1

Here is my code:

import java.net.URL;
import java.net.URLClassLoader;
public class App {
    public static void main(String[] args) {
        System.out.println("java.class.path="+System.getProperty("java.class.path"));
        ClassLoader cl = ClassLoader.getSystemClassLoader();

        URL[] urls = ((URLClassLoader)cl).getURLs();

        for(URL url: urls){
            System.out.println(url.getFile());
        }
    }
}

When I run this in Eclipse with the LWJGL and Slick2d libraries, I get, as expected:

java.class.path=/home/the-genius/workspace/classpath/bin:/home/the-geniu/workspace      
/libs/slick/lib/slick.jar:/home/the-genius/workspace/libs/lwjgl/lwjgl-2.9.2/jar  
/lwjgl.jar:/home/the-genius/workspace/libs/lwjgl/lwjgl-2.9.2/jar/lwjgl_util.jar:
/home/the-genius/workspace/libs/lwjgl/lwjgl-2.9.2/jar/jinput.jar
/home/the-genius/workspace/classpath/bin/
/home/the-genius/workspace/libs/slick/lib/slick.jar
/home/the-genius/workspace/libs/lwjgl/lwjgl-2.9.2/jar/lwjgl.jar
/home/the-genius/workspace/libs/lwjgl/lwjgl-2.9.2/jar/lwjgl_util.jar
/home/the-genius/workspace/libs/lwjgl/lwjgl-2.9.2/jar/jinput.jar

However, when I export it as a runnable jar and execute via

java -cp /home/the-genius/workspace/classpath/bin:/home/the-geniu/workspace      
/libs/slick/lib/slick.jar:/home/the-genius/workspace/libs/lwjgl/lwjgl-2.9.2/jar  
/lwjgl.jar:/home/the-genius/workspace/libs/lwjgl/lwjgl-2.9.2/jar/lwjgl_util.jar: -jar app.jar

I get

java.class.path=classpath.jar
/home/the-genius/classpath.jar

Is there any reason for this to be happening? How do I fix it?

I'm running on Ubuntu, if that makes a difference. I've also tried it using both OpenJDK-7 and Sun Java-7.

1 Answer 1

4

If you use -cp and -jar option at the same, the former is ignored. To fix it, you can either run it without -jar(add your jar file to the classpath and call the main class: java -cp app.jar App) or add the classpath to the jar manifest file.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.