0

Windows console command:

c:\..path..>java -jar TestApp.jar

results in: Error could not find or load main class com.test.Main

I'm using IntelliJ 14 and my artifact layout looks like this:

TestApp.jar/
--client.jar <----- com.test.Main is located here

--jogl/
----gluegen.jar
----jogl-all.jar

--META-INF/
----manifest.mf

Manifest file info:

Main-Class: com.test.Main
Class-Path: client.jar;jogl/gluegen-rt.jar;jogl/jogl-all.jar;

but when I run code in IntelliJ, it is succesfull.

user2977027
  • 105
  • 1
  • 10

1 Answers1

3

I am afraid you can't, because default Classloader cannot load from a jar-within-a-jar. I suppose IntelliJ will expand those jars and thus working.

See here : Reference jars inside a jar

But there is a solution. I use to create autorun-jars with dependencies using maven-assembly-plugin. If I expand this jar I found that all jar dependencies are expanded inside the jar. This way, Classloader can load all classes.

If you don't use maven, IntelliJ must have an option to export project as autorun-jar or something similar.

Edit

If maven or exporting your project as autorun-jar is not ok for you, maybe One-JAR would serve your porpouse, but I have no experience with this project.

Community
  • 1
  • 1
malaguna
  • 4,183
  • 1
  • 17
  • 33
  • That could be an answer, but at this point it rather overcomplicated project for me. If Classloader capabilities ends here, I better restructurate my layout. – user2977027 Oct 08 '15 at 13:01
  • There are lots of information about how to make a fat JAR with JogAmp (JOGL, JOAL, JOCL) libraries here: http://jogamp.org/wiki/index.php/JogAmp_JAR_File_Handling I mention maven-shade-plugin too. You can make a fat JAR with a very few lines of XML code with Ant. I assume that IntelliJ supports Ant. – gouessej Oct 09 '15 at 14:03