0

When I run it with IntelliJ Idea - it works completely right. When I run app.jar file from output - everything works good too, but one feature, which is supported by supportLib.jar. I get java.lang.NoClassDefFoundError: sun/plugin/dom/exception/InvalidAccessException when use it. The structure of the output is:

| D:\myprogram\

  |
  ---> app.jar 
  |
  ---> lib\  
        |
        ---> supportLib.jar
        ---> anotherSupportLib.jar

The ClassPath is: lib/supportLib.jar lib/anotherSupportLib.jar

Tim Pote
  • 27,191
  • 6
  • 63
  • 65
Zharro
  • 819
  • 1
  • 11
  • 23

3 Answers3

2

sun.plugin.dom.exception.InvalidAccessException resides in $JRE_HOME/lib/plugin.jar, so you need to add $JRE_HOME/lib/plugin.jar to your classpath. I suppose that IntelliJ adds this automatically, but it is not automatically loaded by the Java runtime (unlike rt.jar).


Based on the feedback from the comments, the application should be started like this:

java -classpath "c:/Program Files/Java/jre7/lib/plugin.jar;app.jar;lib/supportLib1.jar;lib/supportLib2.jar;lib/supportLib3.jar" namespace.forms.MainForm
Andreas Fester
  • 36,091
  • 7
  • 95
  • 123
  • META-INF\MANIFEST.MF in output jar doesn't have `$JRE_HOME/lib/plugin.jar`. I added it this way: `$JRE_HOME/lib/plugin.jar lib/supportLib.jar lib/anotherSupportLib.jar`, it did not help. Did I added this part correctly? – Zharro Oct 23 '12 at 13:19
  • You can not use variables in the Manifest file - the classpath in the Manifest is a relative path. Can you simply try to run your application with "java -classpath your_JRE_directory/lib/plugin.jar ...", to make sure that this is actually the issue? – Andreas Fester Oct 23 '12 at 13:25
  • I run my application with `java -classpath c:/Program Files/Java/jre7/lib/plugin.jar .;app.jar;lib/supportLib1.jar;lib/supportLib2.jar;lib/supportLib3.jar namespace.forms.MainForm` and give an error: Could not find or load main class Files.Java.jre7.lib.plugin.jar. Without `$JRE_HOME/lib/plugin.jar` app runs, but necessary functionality does not work. Am I doing smth wrong? – Zharro Oct 23 '12 at 22:28
  • You have spaces in your path - you need to quote them. Also, there is a bogus dot in your classpath - you should not need that. Please see my updated answer. – Andreas Fester Oct 24 '12 at 06:14
  • Earned!! But what to do in order to run the executable JAR itself? It still has a manifest file inside with format: `Manifest-Version: 1.0 Class-Path: lib/supportLib1.jar lib/supportLib2.jar lib/supportLib3.jar Main-Class: namespace.forms.MainForm` – Zharro Oct 24 '12 at 07:04
  • See [How to build an executable jar with external jar](http://stackoverflow.com/questions/502960/eclipse-how-to-build-an-executable-jar-with-external-jar). Technically, you have two options: either copy the plugin.jar file into your lib subdirectoy and add `lib/plugin.jar` to your manifest's `Class-Path`, or repackage plugin.jar so that its classes are included in your app.jar file. The latter could also be a good idea for your support libs, if you really want to have a complete self-containing runnable jar file. – Andreas Fester Oct 24 '12 at 07:35
2

IDEA usually adds absolute path:

 -classpath D:\myprogram\lib\supportLib.jar;D:\myprogram\lib\anotherSupportLib.jar

Try to run your jar with this synthax.

Jack
  • 10,943
  • 13
  • 50
  • 65
  • I've tried with `java -classpath c:/Program Files/Java/jre7/lib/plugin.jar .;app.jar;lib/supportLib1.jar;lib/supportLib2.jar;lib/supportLib3.jar namespace.forms.MainForm`. But the problematic option still doesn't work... – Zharro Oct 23 '12 at 22:31
0

On windows machine this needs to be with semicolon lib/supportLib.jar;lib/anotherSupportLib.jar.

Aleksandr M
  • 24,264
  • 12
  • 69
  • 143
  • The application has stopped running – Zharro Oct 23 '12 at 13:22
  • Excuse me! The application runs with `java -classpath c:/Program Files/Java/jre7/lib/plugin.jar .;app.jar;lib/supportLib1.jar;lib/supportLib2.jar;lib/supportLib3.jar namespace.forms.MainForm`. But the problematic option still doesn't work... – Zharro Oct 23 '12 at 22:30