Results 1 to 20 of 26
- 02-23-2011, 02:27 AM #1
Senior Member
- Join Date
- Feb 2011
- Posts
- 107
- Rep Power
- 0
Creating executable jar file in Eclipse
Hi,
I have just 3 files:
TestJar.java - this has my main()
TestJarForm - this has my form/AWT/Swing components - basically just a button that says press me, when pressed it plays bark.wav from the sounds file (next file)
Sounds.java
So I clicked on file->export->Java->Runnable Jar File->
picked TestJar
then gave the jarfile name as Test4
and specified the directory where it should be created.
I opened the jar file and I see a crapload of other files that are not related to these three. Basically, it jarred ALL the files in the project folder - how do I limit it to jar just these 3?
Can I just delete these extra files from the jar?
And finally double clicking the jar file... nothing happens :(
The jar file seems to be associated with Nokia's OVI and that instead launches :(
(I am on Windows 7)
If need be I can copy and paste the contents of the 3 files here...
Thanks!
R
-
What are you using to create your Jar? Eclipse? NetBeans? Other?
- 02-23-2011, 05:20 AM #3
Senior Member
- Join Date
- Feb 2011
- Posts
- 107
- Rep Power
- 0
In the subject I wrote:
Creating executable jar file in Eclipse
D:D
But I guess I should have mentioned it in the body as well.
Anyway, I think I have partly figured out why I was getting that problem, in Eclipse it seems to jar the entire project folder.
So I created another project folder called "test" and moved the 3 files into that folder and was able to jar it like that... but still cant make an "executable jar file" :(
A little off topic:
I basically want to send a friend of mine the test project I was working on so that he (who does not have any java/programming experience) can double click my jar file and launch the program and test it out.
- 02-23-2011, 05:44 AM #4
Why don't you go the traditional way. Create the jar file manually from command line, set the manifest file entries properly and run the jar.
Refer following links in case if you are interested.
How To Create Jar And Manifest Files Basics
Hope that helps,
GoldestJava Is A Funny Language... Really!.gif)
Click on * and add to member reputation, if you find their advices/solutions effective.
- 02-23-2011, 05:53 AM #5
Senior Member
- Join Date
- Feb 2011
- Posts
- 107
- Rep Power
- 0
Thanks for those links, I am totally new to this so they do help.
I have also read online that you can create a zip file and then drag and drop the files accordingly, once done (and after adding the manifest file) you simple rename it to .jar
have your tried this option and do you recommend it?
Most importantly, if I distribute this jar file will my end users be able to just double click and launch it?
Thanks!
- 02-23-2011, 06:16 AM #6
Moderator
- Join Date
- Feb 2009
- Location
- New Zealand
- Posts
- 4,537
- Rep Power
- 11
First on Eclipse. When you selected file->export->Java->Runnable Jar File->... the resulting dialog gave you a choice (on the left hand side) to select what resources you wanted to include.
I wouldn't recommend using some random zip tool (including whatever Microsoft build into their file browser) when what you are making is a jar file. The links explain what the jar executable does and how to use it: and building your own jar file will give you more insight into what Eclipse does for you. (the options you have, which - as you've seen - may not be clear from its dialogs)
For your friend to be able to doubleclick-n-run (that wasn't off topic btw) a couple of conditions have to be met. First you must have jarred up all the resources your application needs. And not just what you think it needs. You can test this by copying the jar file somewhere else on your computer, renaming it and seeing for yourself what happens.
Secondly your friend's computer must have some sort of desktop manager that interprets jar files as something that should be run when double clicked. Windows (out of the box and provided the Java runtime is installed!) does, others may not.
- 02-23-2011, 06:40 AM #7
Yes, they will be able to do that. Read the conditions mentioned by pbrockway2 above.
This link will probably clear all you doubts : How To Make An Executable Jar File.
Google is probably the best thing, that has happened to us. Please utilize it properly. :D
Hope that helps,
GoldestJava Is A Funny Language... Really!.gif)
Click on * and add to member reputation, if you find their advices/solutions effective.
- 02-23-2011, 07:09 AM #8
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,373
- Blog Entries
- 7
- Rep Power
- 17
If you right click on a project and select Export>Jar File, Eclipse assumes that you want to export all the files in that project; the wizard shows that project top level folder as selected in the left pane. Files unrelated, but belonging to that project are shown in the right pane. You can (de) select any directory in the project. You can also specify the name and directory of your jar file in the current panel (below the two others).
In the next panels (click 'next') you can specify what exactly to export and you can also specify which file to use for the manifest entry in the jar file.
Finally click 'Finish' and voila.
kind regards,
JosWhen people rob a bank they get a penalty; when banks rob people they get a bonus.
- 02-23-2011, 02:36 PM #9
Senior Member
- Join Date
- Feb 2011
- Posts
- 107
- Rep Power
- 0
I am not totally sure what you are talking about as I seem to be getting a different screen.. so pictures should help:



Click the above images for full screen.
Pic 1: For some reason I am getting some exclamation / warning icons on some of my files (see in the left panel) as well as red X's (errors?)
Pic 2 and 3 are me making the Jar file...
@goldest,
Ok, will try that as well
@Jos, my export seems a bit different from what you describeLast edited by N00Bie; 02-23-2011 at 02:45 PM.
- 02-23-2011, 02:47 PM #10
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,373
- Blog Entries
- 7
- Rep Power
- 17
Select export to a jar file instead of a runnable jar file and do it yourself: i.e. select the files to be exported and an optional manifest file. More important: read the manual so you know what you're doing; too many people try to click their way through quite a complicated process (Eclipse already makes it a lot easier for you). Also read my previous reply.
kind regards,
JosWhen people rob a bank they get a penalty; when banks rob people they get a bonus.
- 02-23-2011, 06:40 PM #11
Senior Member
- Join Date
- Feb 2011
- Posts
- 107
- Rep Power
- 0
Ok, some progress!
I opened the jar file and I see a lot of class files for one single java file
example
one.java is the original file but I see
one.class
one0.class
one1.class
etc
so I did a manual compile for each program
(javac one.java)
then jarred all those class files, made the manifest to point to the main() class
(so far so good)
then did a java -jar <filename>.jar (in the console)
and the damn thing opened up and ran perfectly!!!
Was soooo ****ing happy to see it running by itself
(first time I have done this, and like they say... you never forget your first :p )
Then I exited the console and double clicked it in windows explorer, and it opens Nokia OVI :confused: :eek: :(
Started googling and found out that Nokia associates .jar files with OVI because they automatically assume that a .jar file is a game or something and NOT that it can be a java developer creating his own jars.
ARRRGH! (Was not going to buy a Nokia again, and this seals the deal - next phone Android)
Ok, done with my little rant... can someone tell me how I associate the .jar files back to java please?
Is it as simple as "open with" and point to Java.exe or javaw.exe or do I have to add some parameters as well?
Thanks!
-
That's an OS dependent thing, and not a Java thing. Are you using Windows? If so, I believe you can change associations via a menu in the windows' file explorer.
- 02-23-2011, 06:54 PM #13
Senior Member
- Join Date
- Feb 2011
- Posts
- 107
- Rep Power
- 0
- 02-23-2011, 07:40 PM #14
Moderator
- Join Date
- Feb 2009
- Location
- New Zealand
- Posts
- 4,537
- Rep Power
- 11
<quote>I need to pass some parameters as well</quote>
I was wondering about this...
COntrol Panel -> Programs -> Default Programs -> Set Associations (or right click and "open with...") lets you set the application executable but that's all as far as I can see.
According to annoyances.org the pre vista ability to edit these things has been removed. They suggest a third party tool that attempts the sisyphean task of making this OS behave properly and let you set file associations. I haven't tried it.
- 02-23-2011, 07:57 PM #15
Senior Member
- Join Date
- Feb 2011
- Posts
- 107
- Rep Power
- 0
This is how I associated the jar file to java.exe
Right click on jar file, in the menu that pops up click on open with, then browse (because java was not shown in the list of program) browse over to your installation of java and double click on java.exe
problem is, when I double click on the .jar it opens a command window and then exits again (too fast to see what the error is), I think its a null pointer exception.
But opening the same thing with java -jar <filename>.jar runs it perfectly :(
-
Try associating it with javaw.exe, not java.exe.
- 02-23-2011, 08:31 PM #17
Senior Member
- Join Date
- Feb 2011
- Posts
- 107
- Rep Power
- 0
- 02-23-2011, 08:59 PM #18
Moderator
- Join Date
- Feb 2009
- Location
- New Zealand
- Posts
- 4,537
- Rep Power
- 11
The manifest file has to end in a new line or carridge return. (ie have a blank line at the end).
- 02-23-2011, 09:10 PM #19
Senior Member
- Join Date
- Feb 2011
- Posts
- 107
- Rep Power
- 0
- 02-23-2011, 09:17 PM #20
Senior Member
- Join Date
- Feb 2011
- Posts
- 107
- Rep Power
- 0
Ok, got it working!
But had to download and use this:
Jarfix
It's a bit frustrating though, I prefer to know _exactly_ what this tool is doing rather than doing a double click and the program doing some "magic" to fix the paths.
I'm guessing its not just a path issue (as I had changed the paths properly) but something in the registry as well...
Anyway, if it helps others, just the link above.
Similar Threads
-
create windows executable using executable jar file
By sarwar1234 in forum New To JavaReplies: 2Last Post: 02-07-2011, 08:29 PM -
Eclipse and creating .jar file
By wantakill in forum EclipseReplies: 11Last Post: 09-04-2010, 11:51 PM -
creating war file in eclipse
By pelegk1 in forum EclipseReplies: 3Last Post: 05-24-2010, 04:28 AM -
Creating an executable jar file in IntelliJ IDEA
By turanan in forum IntelliJ IDEAReplies: 0Last Post: 12-04-2009, 03:06 PM -
Need help for creating executable xml
By patilsubh in forum XMLReplies: 3Last Post: 10-01-2009, 10:54 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks