Question

So I made a super-simple file, and shot it up onto my server at:

http://myServer:8080/testApp/

In there is testApp.jar and a folder that acts as bin. I've tried a few things to fix this but I keep getting: Exception in thread "main" java.lang.ClassNotFoundException: com.testApp.Main

The full path to Main.Class is http://myserver:8080/testApp/com/myCom/Main.Class

My code to find this is

    URLClassLoader loader = new URLClassLoader(new URL[]{new File("http://myserver04:8080/testApp/").toURI().toURL()});

    Class<?> mainClass = loader.loadClass("com.myCom.Main");
    Method mainMethod = mainClass.getMethod("main", String[].class);
    mainMethod.invoke(null, new String[]{});
}

My end-goal is simply to run the main method of this file and the file being launched will have a simple "Hello World" swing window.

Thanks

Was it helpful?

Solution

From just glancing at the javadocs of URLClassLoader:

Any URL that ends with a '/' is assumed to refer to a directory. Otherwise, the URL is assumed to refer to a JAR file which will be downloaded and opened as needed.

The URL you're specifying ends with a slash, so the class loader expects to see .class files in that directory. Try specifying the full path to the JAR in the URL

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top