aspose file tools*
The moose likes IDEs, Version Control and other tools and the fly likes How to create a jar file of a java project that uses Derby database Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » IDEs, Version Control and other tools
Bookmark "How to create a jar file of a java project that uses Derby database" Watch "How to create a jar file of a java project that uses Derby database" New topic
Author

How to create a jar file of a java project that uses Derby database

Sarah Raf
Ranch Hand

Joined: May 08, 2011
Posts: 35

Hi,
I am trying to create a JAR file for an eclipse project, that uses Java DB. My main class inserts XML file into the Java DB. I need to create a JAR file, so that instead of running the Java application every time I need to insert the XML file, I can simply run the JAR file.
The JAR file that I have created does not insert the XML into the Java DB. Any suggestions are welcome.

Regards,
Sarah
Ajeeth Kumar
Ranch Hand

Joined: Mar 30, 2005
Posts: 56
Any jar file that you create , will not automatically call its main class constructor or main method . You would have to explicitly call the method that would insert the XML in the DB.
Peter Johnson
author
Bartender

Joined: May 14, 2008
Posts: 5776
    
    7

Try this: File | Export | Java | Runnable JAR file, then specify your "main" class and make sure "Extract required libraries into generated JAR" is checked.


JBoss In Action
Ajeeth Kumar
Ranch Hand

Joined: Mar 30, 2005
Posts: 56
Peter Johnson wrote:Try this: File | Export | Java | Runnable JAR file, then specify your "main" class and make sure "Extract required libraries into generated JAR" is checked.


My bad.. i never tried that option
Sarah Raf
Ranch Hand

Joined: May 08, 2011
Posts: 35

Thanks Peter & Ajeeth....
I have already tried that option. My problem is that I am not able to make that Jar file work. I have embedded derby in my Application.

JAR creation failed. See details for additional information.
Resource is out of sync with the file system: '/SampleProject/data/MyDB/db.lck'.
Resource is out of sync with the file system: '/SampleProject/data/MyDB/log/log.ctrl'.
Resource is out of sync with the file system: '/SampleProject/data/MyDB/log/log9.dat'.
Resource is out of sync with the file system: '/SampleProject/data/MyDB/log/logmirror.ctrl'.
Resource is out of sync with the file system: '/SampleProject/derby.log'.


The above mentioned errors occur when I create a JAR in eclipse. How can I avoid this?
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18127
    
    8

I think you press F5 to synchronize a project with the underlying file system. Otherwise you'll find "Refresh" on the project's right-click menu.
Sarah Raf
Ranch Hand

Joined: May 08, 2011
Posts: 35

Thanks Paul..
I tried it.. But still, my JAR file doesn't seem to work. Am I missing out something?
Sarah Raf
Ranch Hand

Joined: May 08, 2011
Posts: 35

I found out why exactly my JAR file isnt working. I have a folder called 'resource' in which I have placed 'label.properties' file. This file is not been packaged with the JAR file. Now how do I proceed?
Ajeeth Kumar
Ranch Hand

Joined: Mar 30, 2005
Posts: 56
Look for options to include all the files under the source folder. ( I believe your properties files is inside the src folder, else you can use ant scripts to create the jar file and make the necessary tweaks to create jar with property file).
Sarah Raf
Ranch Hand

Joined: May 08, 2011
Posts: 35

Ajeeth Kumar wrote:Look for options to include all the files under the source folder. ( I believe your properties files is inside the src folder, else you can use ant scripts to create the jar file and make the necessary tweaks to create jar with property file).


No Ajeeth. My resources folder is separate from the src folder. I did try to do this through command prompt too, but still my JAR isn't working. I have to include JOGL.jar and gluegen-rt.jar too in my project.
Ajeeth Kumar
Ranch Hand

Joined: Mar 30, 2005
Posts: 56
Any folder outside the src folder is not available in the classpath, so it would be missed. You can try to add the folder in the classpath entries by clicking on Run configurations->Classpath-> Advanced options.
Do let me know if this works or not.
Sarah Raf
Ranch Hand

Joined: May 08, 2011
Posts: 35

Ajeeth Kumar wrote:Any folder outside the src folder is not available in the classpath, so it would be missed. You can try to add the folder in the classpath entries by clicking on Run configurations->Classpath-> Advanced options.
Do let me know if this works or not.


Thanks a lot for the help ... I had to include the JOGL and the gluegen-rt DLL files in the JRE library to make my JAR work. So now my UI works absolutely fine, but still I have the problem of including the embedded Java DB in my applications JAR file.. How can I include it???
Ajeeth Kumar
Ranch Hand

Joined: Mar 30, 2005
Posts: 56
Glad that I could be of some help

Now coming to your current issue, If I got it right, you would not be able to port a DB inside a jar file a la some text file. You would have to include the required JARs within your custom jar and then create the DB whenever your application runs in the system.
Sarah Raf
Ranch Hand

Joined: May 08, 2011
Posts: 35

Ajeeth Kumar wrote:Glad that I could be of some help

Now coming to your current issue, If I got it right, you would not be able to port a DB inside a jar file a la some text file. You would have to include the required JARs within your custom jar and then create the DB whenever your application runs in the system.


Thanks again Ajeeth....
I am not able to port my DB As I said I am using embedded Java DB, when I created my application, I'd included the apache libraries in the eclipse plugins, so that I could use the embedded Java DB. But now I have no clue how can I include it in my JAR. I did try doing the same way as mentioned in http://db.apache.org/derby/manuals/develop/develop38.html#Accessing+Databases-in-a-Jar+in+the+Class+Path but still I am not able to include my DB. Could you give me some example....
Ajeeth Kumar
Ranch Hand

Joined: Mar 30, 2005
Posts: 56
Sorry Sarah, I have never tried to port a DB along with a JAR.
Sarah Raf
Ranch Hand

Joined: May 08, 2011
Posts: 35

Ajeeth Kumar wrote:Sorry Sarah, I have never tried to port a DB along with a JAR.

Thanks for the help Ajeeth. By the way my JAR file creates the database, so I don't have to port it along with the application. Once again Thanks a lot for all the suggestions and the timely help

Regards,
Sarah
Peter Johnson
author
Bartender

Joined: May 14, 2008
Posts: 5776
    
    7

Sarah Raf,
Since your questions was really about a different topic, I moved it to a new post new topic.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to create a jar file of a java project that uses Derby database
 
Similar Threads
java, xml schema and relation db
executing jar file
a generic doubt
JDBC Err while running jar file
Java Program/XML