Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Calling Java .jar Program from Perl using System()

Tags:

java

perl

system

The title pretty much says it all, I am trying to get a java program (.jar file) to run from a Perl program. I read another post on Stackoverflow saying this syntax is correct:

system("java filename.jar");

However this is giving me the following error. I'm not sure if the problem is that it shows the filename as "filename/jar" instead of "filename.jar"

Exception in thread "main" java.lang.NoClassDefFoundError: filename/jar
Caused by: java.lang.ClassNotFoundException: filename.jar
        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:307)
        at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
like image 749
user387049 Avatar asked Apr 07 '26 05:04

user387049


2 Answers

You need to call it as java -jar filename.jar.

If you leave out the -jar, then java thinks you're trying to run a class named filename.jar, which it tries to load from the filename/jar file. Since you don't have that file, java throws the error that you see.

like image 109
CanSpice Avatar answered Apr 09 '26 10:04

CanSpice


You have to use the -jar option to launch a jar.

java [ options ] -jar file.jar [ argument ... ]


Resources :

  • sun.com - java
like image 39
Colin Hebert Avatar answered Apr 09 '26 12:04

Colin Hebert



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!