aspose file tools*
The moose likes IDEs, Version Control and other tools and the fly likes Make a runnable jar of my project in Eclipse Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Engineering » IDEs, Version Control and other tools
Bookmark "Make a runnable jar of my project in Eclipse" Watch "Make a runnable jar of my project in Eclipse" New topic
Author

Make a runnable jar of my project in Eclipse

Dan Foster
Greenhorn

Joined: May 02, 2013
Posts: 21
I have a Java swing project which i need to test on other computers. I have some classes and a sqlite db which stores login information. I have some lib jars as well. The application takes information from the user and stores it in the sqlite db and then pushes data to the web. I want to package my project so that whoever uses my project has to just double click on an executable or jar. Here is my folder structure -



I tried to Export to a Runnable Jar file in Eclipse but this does not give desired results. After the runnable jar is created and i run it for the first time it creates the sqlite db beside it and is not able to read the fcl file.

How can i package my data properly?
surlac surlacovich
Ranch Hand

Joined: Mar 12, 2013
Posts: 296

Dan Foster wrote:After the runnable jar is created and i run it for the first time it creates the sqlite db beside it and is not able to read the fcl file.

Have you tried to put the fcl-file in classpath? Because now it looks like it isn't there.
Also, it can be an option to use installer, which will do pre-configuration of your app.
Dan Foster
Greenhorn

Joined: May 02, 2013
Posts: 21
It runs fine in Eclipse. I think the fcl file doesn't get included within the jar, so does the sqlite file. That is why it doesnt find the fcl file and creates a sqlite file on its own. How can i include those within the runnable jar file?
If i choose just Jar file then it asks me to include files. But when i choose runnable jar file it just asks launch configuration.

I have target users who use linux and Mac, so if i use installer can they still use it?
Dan Foster
Greenhorn

Joined: May 02, 2013
Posts: 21
I tried putting the fcl file in classpath. But still it doesnt work
surlac surlacovich
Ranch Hand

Joined: Mar 12, 2013
Posts: 296

I don't see output folder in your structure. Does "src" contain *.class files?
Dan Foster
Greenhorn

Joined: May 02, 2013
Posts: 21
src doesnt have the class files. In Eclipse the class files are generated in the "bin" folder. But i don't think that is the problem since when i create the jar from File->Export->Java->Runnable jar file, it creates the jar file. And it launches as well asking login creds. Its just that it cannot read the fcl files. I am using a fuzzy logic package written in Java which i got from - http://jfuzzylogic.sourceforge.net/html/index.html
Dan Foster
Greenhorn

Joined: May 02, 2013
Posts: 21
You can easily recreate the error by following this - http://jfuzzylogic.sourceforge.net/html/videos/jFuzzyProject_example.swf

After creating this simple project also i cannot create a runnable jar of the project. It wont take more than 3 mins to recreate this in Eclipse. I think i have a path problem or so but not able to figure out. Please help me out.
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18116
    
    8

If you want the file.fcl file to be in the jar, then you should put it into your src folder and (if I recall correctly) Eclipse will put a copy into the bin folder when it builds your project. However you haven't actually said whether that's what you want. Do you need file.fcl to be in the jar? Or were you planning on distributing it separately from the jar?

Anyway this seems to be a question about Eclipse so I'll move it to the IDEs forum.
Dan Foster
Greenhorn

Joined: May 02, 2013
Posts: 21
Yes i want the fcl file to be inside the jar.
I placed the fcl file in the src folder and same package as the java file. Now when i make a runnable jar it creates the jar. On double clicking it nothing happens. When i run it from cmd it throws the same error -

Error reading file - 'src/com/MakinJar/file.fcl'
Can't load file - 'src/com/MakinJar/file.fcl'
Maxim Karvonen
Ranch Hand

Joined: Jun 14, 2013
Posts: 94
    
    9
Hi, Dan.

How exactly do you try to access your fcl file? If you want to access it with FileInputStream you should not place that file inside a jar. Put it outside of the jar and access it using a stream. Or you can put it in a jar and use this.getClass().getClassLoader().getResourceAsStream("com/MakinJar/file.fcl"). This will be not a java.io.File, it will be a stream with a given file content.
Dan Foster
Greenhorn

Joined: May 02, 2013
Posts: 21
Ok. I do Export -> Java -> Runnbale Jar file. Then keep the fcl file beside the generated jar. Now it gets the file but throws a lot of errors.

Actually my application connects to the localhost and posts some data. So i use jersey client. When i execute this in Eclipse everything runs fine and the record is populated in the mysql db of localhost. But now it gives a "a message body writer for java type application/json was not found".

Throws error on this line - ClientResponse response = webResource.path("restPath").path("resourcePath").type(MediaType.APPLICATION_JSON).accept(MediaType.APPLICATION_JSON).post(ClientResponse.class, jsonPush);

I don't get this. While developing in Eclipse it throws no errors. And now if i make the same code into a Jar it throws errors.
Dan Foster
Greenhorn

Joined: May 02, 2013
Posts: 21
solved it by adding jersey jar in classpath of the jar
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Make a runnable jar of my project in Eclipse
 
Similar Threads
jar and sqlite....
help needed with creating jar file
How to access and open an existing SQLite database (in Eclipse/Emulator)
ClassLoader.getSystemResourceAsStream() returning null
SQLite and connecting with Java Swing Application