I am trying to figure out whether it is possible to run a java class that is located on a mapped network drive. An example would be:
C:\temp\groovy>java p:\Test
Exception in thread "main" java.lang.NoClassDefFoundError: p:\Test
Caused by: java.lang.ClassNotFoundException: p:\Test
at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
Could not find the main class: p:\Test. Program will exit.
Before trying this, I wanted to see whether I could run a java class file that is on UNC share (java \\somehost\share\Test
). This did not work either - same error about class def not being found.
Am I doing something wrong or is this really not supported ?
Thanks
When you give a path as part of the class name, Java expects it to be in a package corresponding to the folder hierarchy it's in.
Example:
> java z:/Test
java.lang.NoClassDefFoundError: z:/Test
Caused by: java.lang.ClassNotFoundException: z:.Test
Here it is looking for "z:.Test" as the fully qualified class name.
Assuming your Test class is not declared as being in any package, you need to specify the directory on the classpath:
java -cp Z:\path Test