Wednesday, June 29, 2011

Configuring Derby over Eclipse

Download Derby plugins:
http://db.apache.org/derby/derby_downloads.html
When you click on any release lets say 10.8.1.2 Release
Look  little down just before the "Release Notes for Apache Derby 10.8.1.2"
two zip files
derby_core_plugin_10.8.1.zip [PGP] [MD5]
derby_ui_doc_plugin_1.1.3.zip [PGP] [MD5]



Both plugins must be installed for full functionality. Unzip them in the c:\eclipse or in the eclipse folder where ever it is installed.
Here are more details in this link 
http://db.apache.org/derby/integrate/plugin_howto.html#Installing+the+plug-ins

Next Step is adding the Apache Derby Nature to your project. If you do not have create one Java Project.
Right-click it and select Apache Derby >> Add Apache Derby nature.


Adding the Derby nature to your Eclipse project does the following:

  1. Adds the derby.jar, derbynet.jar, derbytools.jar, derbyclient.jar jar files to the Java Build Path of the project. 
  2. Enables the Derby features for the project. Several other menu items now appear under the Apache Derby menu item. The ij and sysinfo tools are now accessible from this menu, and the Apache Derby Network Server can now be started and stopped using this menu. 
  3. Allows Apache Derby properties such as the port number the Network Server listens on, and the value for derby.system.home to be set for the project.



Very Important


Assuming you are using a jdk for as your JRE. Look in preferences (Installed JRE) If it is JRE add another runtime that points to JDK (e.g. C:\Program Files\Java\jdk1.6.0_24). Make this as your default runtime. ( delete the other JRE runtime).


Now go to the 'java.policy' in C:\Program Files\Java\jdk1.6.0_24\jre\lib\security' folder.
We need to make changes in 'java.policy' because we want to allow derby.jar file to access some of the folders.

There are so many examples given here you should look at that if you are concerned to opening up holes on your computer. For eclipse plugin I spent one day, I was not able to make it work.
Finally I got one simple solution, add one line
permission java.security.AllPermission;
at the top and bottom of  java.policy, here is mine...


// Standard extensions get all permissions by default

grant codeBase "file:${{java.ext.dirs}}/*" {
permission java.security.AllPermission;
};

// default permissions granted to all domains

grant { 
// Allows any thread to stop itself using the java.lang.Thread.stop()
// method that takes no argument.
// Note that this permission is granted by default only to remain
// backwards compatible.
// It is strongly recommended that you either remove this permission
// from this policy file or further restrict it to code sources
// that you specify, because Thread.stop() is potentially unsafe.
// See the API specification of java.lang.Thread.stop() for more
        // information.
        
        permission java.security.AllPermission;
permission java.lang.RuntimePermission "stopThread";

// allows anyone to listen on un-privileged ports
permission java.net.SocketPermission "localhost:1024-", "listen";

// "standard" properies that can be read by anyone
  permission java.util.PropertyPermission "derby.log", "read,write"; //Pankaj
permission java.util.PropertyPermission "java.version", "read";
permission java.util.PropertyPermission "java.vendor", "read";
permission java.util.PropertyPermission "java.vendor.url", "read";
permission java.util.PropertyPermission "java.class.version", "read";
permission java.util.PropertyPermission "os.name", "read";
permission java.util.PropertyPermission "os.version", "read";
permission java.util.PropertyPermission "os.arch", "read";
permission java.util.PropertyPermission "file.separator", "read";
permission java.util.PropertyPermission "path.separator", "read";
permission java.util.PropertyPermission "line.separator", "read";

permission java.util.PropertyPermission "java.specification.version", "read";
permission java.util.PropertyPermission "java.specification.vendor", "read";
permission java.util.PropertyPermission "java.specification.name", "read";

permission java.util.PropertyPermission "java.vm.specification.version", "read";
permission java.util.PropertyPermission "java.vm.specification.vendor", "read";
permission java.util.PropertyPermission "java.vm.specification.name", "read";
permission java.util.PropertyPermission "java.vm.version", "read";
permission java.util.PropertyPermission "java.vm.vendor", "read";
permission java.util.PropertyPermission "java.vm.name", "read";
permission java.security.AllPermission;

};

/* Grants permission to run Derby and access all      */
/* databases under the Derby system home              */
/* when it is specified by the system property             */
/* derby.system.home                                        */
 
/* Note derby.system.home must be an absolute pathname */
 
grant codeBase "file://C:/springsource//sts-2.6.0.SR1/plugins//org.apache.derby.core_10.8.1/derby.jar" {
 
 permission java.lang.RuntimePermission "createClassLoader";
   permission java.util.PropertyPermission "derby.*", "read";
   permission java.util.PropertyPermission "${user.dir}", "read";
   permission java.util.PropertyPermission "derby.storage.jvmInstanceId";
 permission java.io.FilePermission "${derby.system.home}${/}-", "read,write";
 permission java.io.FilePermission "${user.dir}${/}derby.log", "read,write";
 permission java.io.FilePermission "${derby.system.home}${/}derby.properties", "read" ;
   permission java.io.FilePermission "<>",
          "read,write,delete";
            permission java.net.SocketPermission "*", "accept"; 
            permission java.security.AllPermission;

};


------------------------------
Next step is to start the server

Right-click on your project and select Apache Derby >> Start Derby Network Server


-------------------

Now go to the Database Development Perspective and create a new database by following these steps
Step By Step guide


Derby Documentation

Wednesday, June 22, 2011

Setup Maven and maven plugin on eclipse

Best way to give Maven access to Spring is via Spring’s bundle repositories. I find that the easiest way to do this is to include therepository entries in my settings.xml file, but you can also put them in the POM file for your project or even add them to Nexus as proxy repositories if you are in such an environment. The entries should look like this:


    com.springsource.repository.bundles.release
    SpringSource Enterprise Bundle Repository - SpringSource Bundle Releases
    http://repository.springsource.com/maven/bundles/release



    com.springsource.repository.bundles.external
    SpringSource Enterprise Bundle Repository - External Bundle Releases
    http://repository.springsource.com/maven/bundles/external


With these entries in place Maven should now be able to import Spring 3.0 binaries and certain other useful bundles.

---------------------------------------------------------

For Hibernate add following dependency.

<dependency>
    <groupId>org.hibernategroupId>
    <artifactId>hibernate-c3p0artifactId>
    <version>3.6.0.CR2version>
dependency>

---------------------------------------------------------
For Rest Framework Jersey  add following 
Dependency
   com.sun.jersey
   jersey-client
   1.8
 

Repository (if you do not have this)
  
   maven2-repository.java.net
   Java.net Repository for Maven
   http://download.java.net/maven/2/
   default
  
---------------------------------------------------------


Followers