0

I have the app, which i launch with "Java Web Start". This app is used for launching other java apps. The issue is that with the command "java -cp class_path class_name" java app cannot be launched, an exception "Could not find or load main class class_name" appears.

However, Class.forName(class_name) doesn't throw exception: "ClassNotFoundException" and i can run static method from another jar(but it's in current JVM).

Without using "Java Web Start" everything is alright.

When I launch the common app, I use the command: java -cp *; com.vitaxa.voidbox.MainApp. In this way I form the classpath, collecting everything from the current directory.

Then I can launch other apps, using the command: java -cp current_classpath class_name. So everything works well, but without using Java WebStart.

There is the difference. For getting the classPath I use the next method:

private static String getClasspath() {
        final StringBuilder sb = new StringBuilder();
        ClassLoader classLoader = TaskRunner.class.getClassLoader();
        if (classLoader == null) {
            classLoader = ClassLoader.getSystemClassLoader();
        }
        final URL[] urls = ((URLClassLoader) classLoader).getURLs();
        for (URL url : urls) {
            sb.append(url.getFile()).append(";");

        }
        return sb.toString();
    }

In case of running with an ordinary app, the classpath is: /D:/WorkDir/Applications/FirstApp.jar;/D:/WorkDir/Applications/SecondApp.jar;/D:/WorkDir/Applications/ThirdApp.jar;

and running with using Java WebStart the classpath is: /Applications/FirstApp.jar;/Applications/SecondApp.jar;/Applications/ThirdApp.jar.

P.S. I tried using System.getProperty("java.class.path"), it hadn't helped.

vitaxa
  • 1
  • 1
  • 1

1 Answers1

0

The problem is that the class you are attempting to load either does not have the public static void main(String[] args) method or is not a JavaFX Application in which case you should probably modify your code. Another scenario is you have not loaded the classpath correctly. Make sure that the class you are trying to load is included in the path i.e. java -cp .;list_of_jars_including_the_jar_file_containing_your_class class_name_including_the_package information. This will hopefully solve your issue. An example:

$ java -cp .;my_main.jar;another.jar;yet_another.jar com.example.MyClass

adekorir
  • 21
  • 5