File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Linux / UNIX and the fly likes running a .class file from inside a jar Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » Linux / UNIX
Bookmark "running a .class file from inside a jar" Watch "running a .class file from inside a jar" New topic
Author

running a .class file from inside a jar

malki sabag
Greenhorn

Joined: Nov 22, 2011
Posts: 7
Hello everyone!
i am trying to write a korn shell (.ksh file) that will execute a a java class that resides inside a jar.
the java class i am trying to run has a main method that makes some prints.
the .ksh file has
ENV=location of the jar/the path of the java class
${ENV}

it does not work since it cannot get inside the jar,
any suggestions?
best regards
Tim Moores
Rancher

Joined: Sep 21, 2011
Posts: 2408
Something like "java -cp myJar.jar com.package.my.TheCLass" should do it. Not sure what you mean by "getting inside the jar".
malki sabag
Greenhorn

Joined: Nov 22, 2011
Posts: 7
thank you for your reply,
you have managed to take me one step forward
now im getting an exception

Exception in thread "main" java.lang.NoClassDefFoundError
Caused by: java.lang.ClassNotFoundException:

what am I missing??
Tim Moores
Rancher

Joined: Sep 21, 2011
Posts: 2408
Which class is missing? That should be mentioned somewhere in the error message or stack trace.

Also, what are you typing on the command line?
malki sabag
Greenhorn

Joined: Nov 22, 2011
Posts: 7
this is the full stack trace

Exception in thread "main" java.lang.NoClassDefFoundError: com/package/exceptions/MyException
Caused by: java.lang.ClassNotFoundException: com.package.exceptions.MyException
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)
Could not find the main class: com.package.test.MyClass. Program will exit.

the last line indicates the name of the class i want to run
here is the class:
public class MyClass {

public static void main(String[] args)
{
System.out.println("Hello");
}
}
Tim Moores
Rancher

Joined: Sep 21, 2011
Posts: 2408
You don't have a "package com.package.test" statement in your source code, or was that just a copy/paste error?

Also, what are you typing on the command line?


And what are the contents of the jar file? Post the results of a "jar -tf ..." of the jar file.
malki sabag
Greenhorn

Joined: Nov 22, 2011
Posts: 7
problem solved
the issue was that the CLASSPATH was not configured correctly
thank you Tim for your help
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: running a .class file from inside a jar