Search code examples
javajarjava-6

Strange behaviour in Java app (runs when lauched by Eclipse but gives error with java -jar)


I have a Java app that, when runned with the same JARs (I've refreshed them all), runs OK on Eclipse but, when running with the command line args:

java -jar name.jar

with all of the dependencies on $JRE/lib/ext/

gives an error on a Class.createInstance() line.

Every dependant .jar are generated using Eclipse (right click above package > Export > JAR).

EDIT:

I have 2 projects in eclipse. The first it's the one I run (let's call it main jar) and the other have some utils used in this project (tet's call it utils).

The error is ClassNotFound. It happens on utils jar, when looking for a a class that's on main jar.

    try {

       Class.forName(proxyFieldType.getName());

    } catch (ClassNotFoundException e) {

        ...
    }

When there's no libs on JRE/lib/ext runs ok with Eclipse, but when I put utils.jar, generated from the code on my utils project (generated with right click over package > Export > JAR), on JRE/lib/ext, gives that error.


Solution

  • supply all the dependency jars using -classpath argument.

    java -classpath "path of lib/ext" -jar name.jar