• Post Reply Bookmark Topic Watch Topic
  • New Topic

running javafx apps using java -jar  RSS feed

 
rick sowfilk
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi there, its another classpath error that makes you pull your hair

i have the following sample code



in a file called main_code.java

i compile like this
javac -d . -g -classpath %java_home%\jre\lib\jfxrt.jar main_code.java

then run
java -cp .;%java_home%\jre\lib\jfxrt.jar test_app.main_code
it runs ok,

however when i pack using jar utility like that
jar cfm test_app.jar manifest.txt test_app\*.class
where manifest.txt is


then try to run
java -jar test_app.jar

i get
Exception in thread "main" java.lang.IllegalArgumentException
at sun.net.www.ParseUtil.decode(Unknown Source)
at sun.misc.URLClassPath$JarLoader.<init>(Unknown Source)
at sun.misc.URLClassPath$3.run(Unknown Source)
at sun.misc.URLClassPath$3.run(Unknown Source)
....
....
 
Andrew Samii
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm pretty sure you can't use variables in your classpath - when compiling, it can figure it out for you, but in your classpath you're going to need to give the absolute or relative location.

http://stackoverflow.com/questions/332522/java-manifest-mf-classpath-issues seems to have some details.

edit:According to the accepted answer there, absolute paths don't seem to work either without appending file:// to it to make it a URL. That seems strange to me, it's possible it was changed in the last 5 years.
 
rick sowfilk
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ok i changed my mainfest file according to you:



but still getting a new error:
Exception in thread "main" java.lang.NoClassDefFoundError: javafx/application/Application
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(Unknown Source)
at java.security.SecureClassLoader.defineClass(Unknown Source)
....
....
 
Steve Luke
Bartender
Posts: 4181
22
IntelliJ IDE Java Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Class-Path has to be a URI, which is why the suggestion was to use file://. But that isn't the right solution, you are tying yourself in to one operating system (Windows only) and requiring the exact path to the JDK for it to work. There are three common solutions:

1) package the required libraries with the app and build a lib folder relative to the JAR file. Example:
My App/myjar.jar
My App/lib/jfxrt.jar
And use lib/jfxrt.jar in your Class-Path.

2) Have a setup script which looks up the users JAVA_HOME and looks in the lib\ and lib\ext\ folders to see if the JAR is there, if it isn't then copy a version to %JAVA_HOME%/lib/ext/. If it is already there than I don't think you need to add it to the classpath (as it should already be in).

3) Have a document explaining the pre-requisites and tell the user to install them appropriately.

The first two approaches require an installer to do properly, and #2 is pretty difficult, but would help prevent multiple versions of the JAR from being used (on the other hand, it could mean the user has a version that is incompatible with your application...). The third one is actually the most robust, able to compensate for all kinds of environments and configurations, but sadly, is not the preferred option for people who just want a single download and install.
 
rick sowfilk
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
class path in manifest isn't a problem any more...

still can't rid of
Exception in thread "main" java.lang.NoClassDefFoundError: javafx/application/Application
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(Unknown Source)
at java.security.SecureClassLoader.defineClass(Unknown Source)
....
....

when using java -jar
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!