wood burning stoves*
The moose likes Beginning Java and the fly likes Problem Creating Executable JAR Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Problem Creating Executable JAR" Watch "Problem Creating Executable JAR" New topic
Author

Problem Creating Executable JAR

Don Gardner
Ranch Hand

Joined: Aug 30, 2001
Posts: 33
I have been trying to figure out how to package the program I've been working on into an excutable JAR file. I thought my problem was in the process of creating the JAR, but after reading a previous discussion on creating an executable JAR file, I discovered the problem is in my program.
The program is a Java media player for playing AVIs and such, and it uses the Java Media Framework to supply the classes the actually play the movies.
If I compile my code (included at the end of the post), and JAR it, it runs fine from the command line, but I cannot double click on the JAR file to get it to execute. If I do, I get the following error:
"Could not fine the main class. Program will exit!"
Any suggestions you might have that will help me figure out this problem would be greatly appreciated.
Thanks,
Don
Here is the code for the media player:
Dirk Schreckmann
Sheriff

Joined: Dec 10, 2001
Posts: 7023
I installed the JMF (the Windows performance edition) and then double-clicked on the jar file that you emailed me that didn't previously work and previously generated the same error message that you are reporting. It worked. No errors.
Perhaps you have a system configuration problem such that some setting (perhaps the classpath) is working properly at the command line, but not in the regular windows environment.
Do you specify your classpath as an enviroment variable or in an autoexec.bat file?
I'm just fishing here.


[How To Ask Good Questions] [JavaRanch FAQ Wiki] [JavaRanch Radio]
Don Gardner
Ranch Hand

Joined: Aug 30, 2001
Posts: 33
Originally posted by Dirk Schreckmann:
Perhaps you have a system configuration problem such that some setting (perhaps the classpath) is working properly at the command line, but not in the regular windows environment.

I, originally, had the class path defined in the autoexec.bat, but I have now placed in as an environment variable. Doing this did not change the performance. It still works from the command line, and still won't work by double clicking.
I realize you are just guessing at this point, but if you have any ideas as to where else I could look for solutions, I would appreciate it. I'm kinda stumped at the moment.
On a related note, I'm wondering how to avoid requiring the user to install the JMF to get the program to work. Do I need to include all of the classes I import in my manifest to avoid this problem?
Thanks,
Don
Dirk Schreckmann
Sheriff

Joined: Dec 10, 2001
Posts: 7023
Recall that I was able to recreate your error experience by not having the JMF installed. After installation, the application worked properly. I still suspect that it is a system setting, such that the JMF classes are not by default available to Java applications running directly under Windows.
The most obvious (to me) and relevant system setting is the CLASSPATH setting. On my system, it is an environment variable with this value:
.;H:\j2sdk1.4.0_01\bin;H:\PROGRA~1\JMF21~1.1\lib\sound.jar;H:\PROGRA~1\JMF21~1.1\lib\jmf.jar
But I suppose that your classpath is already set correctly.
Let's confirm that more than one jarred JMF application won't work on your system by double-clicking on it, but will work at the command line. I've used the code you posted to create a similar jar file (only the main class name and jar file name are different) available for download here. With this jar file, is your previous experience repeatable? It does work on my system - both at the command line and by doubl-clicking on it.
Otherwise, the original jar file in question Don has agreed to make available so that others might experiment with it a bit and report back their experience. Download it here. Note that installation of the JMF would also be required to test these jar files. It's a small download and an easy installation. It's available from Sun at http://java.sun.com/products/java-media/jmf/2.1.1/download.html
Dirk Schreckmann
Sheriff

Joined: Dec 10, 2001
Posts: 7023
I'm wondering how to avoid requiring the user to install the JMF to get the program to work
I'm not sure what Sun's policy is concerning packaging JMF API classes with an application that you might create.
The basic idea would be that you'd have to include any class files used by your application (either directly or that are used by classes that you use) with your application. Of course, packages and directories would still have to be appropriately structured.
The easiest way might be to leave the individual classes alone and make use of the appropriate jar files, that comprise the JMF and are located in the JMF/lib directory, through The Extension Mechanism. Again, I don't know if Sun allows this.
...if you have any ideas as to where else I could look for solutions...
You may want to look at the JMF specific forum maitained by Sun at http://forum.java.sun.com/forum.jsp?forum=28 - I'm not sure if I said that out loud or not.
Don Gardner
Ranch Hand

Joined: Aug 30, 2001
Posts: 33
I tend to think that your are right; that there is some sort of configuration problem, but I can't figure out what it might be. Here is what my CLASSPATH looks like (is it case sensitive? Should it be classpath?).
.;.;C:\JMF2.1.1\lib\sound.jar;C:\JMF2.1.1\lib\jmf.jar;%systemroot%\java\classes;.;c:\Program Files\j2sdk1.4.0-rc\bin;
Aside from the directories being correct for my system, it is exactly the same as your classpath. I've set this variable from System Properties >> Advanced in Win2k. Does it matter how the classpath is defined?
I downloaded the file you provided, and it did the same thing as my own file; works just fine from the command line, a no go from a double click.
Dirk Schreckmann
Sheriff

Joined: Dec 10, 2001
Posts: 7023
...CLASSPATH ... is it case sensitive? Should it be classpath?
I don't believe so. Either spelling works fine on my system.
Does it matter how the classpath is defined?
I assume that by how you mean in the autoexec.bat file versus through the control panel as an environment variable, or some other place.
I can't say as that I've ever read of an experience where the problem was that the classpath setting couldn't be specified in the autoexec.bat file and had to be specified as an environment variable through the control panel or vice-versa.
Of course, I was hoping that might have been your problem...
I downloaded the file you provided, and it did the same thing as my own file
Have you tried simply reinstalling the JMF? It doesn't take very long and it's worth a shot.
This evening, I'll stop by the local University's computer lab and quickly test things out on one of their Windows 2000 machines.
[ June 12, 2002: Message edited by: Dirk Schreckmann ]
Don Gardner
Ranch Hand

Joined: Aug 30, 2001
Posts: 33
Ok, I tried uninstalling and reinstalling the JMF twice now. That didn't help, but I did find something interesting on the Sun website, Sun's JMF Diagnostic Page.
It has a little applet that is supposed to check whether or not you have the JMF properly installed. Well, as you might be able to guess, it says that I do not have it properly installed. Unfortunately, the only suggestion it has as to why it's not working is that the classpath is not set properly.
So what now?
Dirk Schreckmann
Sheriff

Joined: Dec 10, 2001
Posts: 7023
Now we quit and go join the M$ camp.
Rene Larsen
Ranch Hand

Joined: Oct 12, 2001
Posts: 1179

Hi
The only to do is to make a 'manifest' file:
MANIFEST.MF

and execute the JAR command:

Now you can double click on the jar-file
/Ren´┐Ż
[ June 12, 2002: Message edited by: Rene Larsen ]

Regards, Rene Larsen
Dropbox Invite
Dirk Schreckmann
Sheriff

Joined: Dec 10, 2001
Posts: 7023
I do notice that your classpath setting includes the full name of the Program Files directory. I do know that a space in the classpath can cause problems unless the classpath setting is surrounded by double quotation marks.
Why don't you try changing your classpath setting to reflect the same style that my classpath setting uses (being certain that no spaces are involved). So, use Progra~1 instead of Program Files. Note that my setting was created by the JMF installation program.
Any luck?
Rene Larsen
Ranch Hand

Joined: Oct 12, 2001
Posts: 1179

Hi
I was able to get to work by unjar the jmf.jar into the same dir witch I have your code, and then I made a new jar-file (JarTest.jar) with the jmf class-files and your code inside.
The users do not need to download and install the jmf API and the user do not need to setup any CLASSPATH
/Rene
Don Gardner
Ranch Hand

Joined: Aug 30, 2001
Posts: 33
Thank you Rene for your response. I suspected that I would have to copy the JMF class files I was using into the JAR file before I distributed it. I was just hoping that there was a way (possibly through manipulationg the manifest) to have the Java compiler or the JAR utility to do this automatically.
Your sugestion, however, does not answer my other question as to why, dispite an apparently correct installation of the JMF, I can't the the program to run by double clicking.
After I uninstalled and reinstalled JMF, my classpath was of the format you mentioned, Dirk. It now looks like:
.;C:\PROGRA~1\JMF21~1.1\lib\sound.jar;C:\PROGRA~1\JMF21~1.1\lib\jmf.jar;.;c:\PROGRA~1\j2sdk1.4.0-rc\bin;
Thanks for all of the help.
Don Gardner
Ranch Hand

Joined: Aug 30, 2001
Posts: 33
Ok, I've tried the suggestion of copying the JMF classes that I use, and including them in the JAR file. It's a no go. Is it possible there are classes that these classes call which are not included? Would I need to include all of the JMF classes? If not, how do I figure out which classes I would need?
Thanks,
Don
Rene Larsen
Ranch Hand

Joined: Oct 12, 2001
Posts: 1179

Hi
I just copied the hole jmf.jar info the 'new' jar-file
After creating of the jar-file you do not need any CLASSPATH reference to jmf.jar and sound.jar!
If you have tried to test your jmf implementation on Sun's JMF Diagnostic Page it will not work because the Applet is made with an old API.
/Rene
Dirk Schreckmann
Sheriff

Joined: Dec 10, 2001
Posts: 7023
If you have tried to test your jmf implementation on Sun's JMF Diagnostic Page it will not work because the Applet is made with an old API.
I'm not exactly sure what you mean. The referenced applet is intended to test whether you have the JMF installed and setup properly. It's not intended to test some implementation of the JMF that you might create.
Also, the applet displays the appropriate/relevant information for me indicating that the JMF is properly setup on my system.
Don Gardner
Ranch Hand

Joined: Aug 30, 2001
Posts: 33
Rene, I don't doubt that copying the entire jmf.jar contents into my program would get it to work properly, but that sounds like a heavy handed way to get it to work. That would include many classes that are not being used by the program, and would increase the file size unnecessarily.
Rene Larsen
Ranch Hand

Joined: Oct 12, 2001
Posts: 1179

If you have tried to test your jmf implementation ...
I didn't mean implementation - sorry - It should have been installation.
If you download the code from the 'test' page and run the Applet on your local PC - and using JMF 2.1.1 - it will not find the JMF classes, but if you change the import reference com.sun.media.util.JMFSecurity in 'QueryJMF11.java' and 'QueryJMF10.java' to com.sun.media.JMFSecurity it will work (if all is Ok )
/Rene
Dirk Schreckmann
Sheriff

Joined: Dec 10, 2001
Posts: 7023
Don,
If I wanted to do what you are proposing, I'd take a look at the source code for the classes that I use, and try to figure out just how difficult it may be. The JMF source code is avaiable for downloading at http://wwws.sun.com/software/communitysource/jmf/
The idea would be to figure out what other classes are used by the classes that you directly use. It's probably a lot of them and this may not be a practical thing to do - but it may be worth some initial investigation.
Regarding the problem of just running these jar files on your system. Perhaps somehow, your system's jar file association was improperly altered. It may be worth taking a look at the jar file type setting. On my system, the default action is open and the application used to perform this action is specified as "...\j2re1.4.0_01\bin\javaw.exe" -jar "%1" (more or less).
Good Luck.
Don Gardner
Ranch Hand

Joined: Aug 30, 2001
Posts: 33
Perhaps somehow, your system's jar file association was improperly altered.

I don't think this is the problem. I created a JAR using the class you posted here, and that worked just fine when I double-clicked it.
Dirk Schreckmann
Sheriff

Joined: Dec 10, 2001
Posts: 7023
Right. I had that in mind when considering my previous suggestion. I doubt it's the problem. If I were you, I'd just be sure to cover all the bases. My next step would probably be to uninstall and then install the Java SDK and the JMF.
Don Gardner
Ranch Hand

Joined: Aug 30, 2001
Posts: 33
Finally! I guess if you uninstall and reinstall enough times, it will eventually work. I had to uninstall the SDK and JMF, and reinstall both, but now it works. Of course, doing this messed up the path on my IDE (Doh! LoL, *sigh*). I guess if it's not one thing it's another.
Thanks for all of the great help.
On the install independent JAR:
I haven't had the time to sort through the source code to find all of the dependences yet, but I hope that will work. I'll let ya'll what happens.
Thanks again,
Don
Dirk Schreckmann
Sheriff

Joined: Dec 10, 2001
Posts: 7023
[sigh]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Problem Creating Executable JAR
 
Similar Threads
JMF ?classpath? problem
faced one error in JMF(JAVA MEDIA FRAMEWORK)
Thread coding SOS
Urgent: JMF Player for real time voice input
HELP