• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Ron McLeod
  • paul wheaton
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
  • Himai Minh
Bartenders:

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

 
Ranch Hand
Posts: 35
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 56
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
author
Posts: 5856
7
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Try this: File | Export | Java | Runnable JAR file, then specify your "main" class and make sure "Extract required libraries into generated JAR" is checked.
 
Ajeeth Kumar
Ranch Hand
Posts: 56
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 35
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
Sheriff
Posts: 28408
101
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 35
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Paul..
I tried it.. But still, my JAR file doesn't seem to work. Am I missing out something?
 
Sarah Raf
Ranch Hand
Posts: 35
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 56
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 35
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 56
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 35
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 56
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 35
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 56
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sorry Sarah, I have never tried to port a DB along with a JAR.
 
Sarah Raf
Ranch Hand
Posts: 35
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 5856
7
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sarah Raf,
Since your questions was really about a different topic, I moved it to a new post new topic.
 
reply
    Bookmark Topic Watch Topic
  • New Topic