File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

running a .class file from inside a jar

 
malki sabag
Greenhorn
Posts: 8
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Bartender
Pie
Posts: 2488
4
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 8
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Bartender
Pie
Posts: 2488
4
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 8
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Bartender
Pie
Posts: 2488
4
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 8
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
problem solved
the issue was that the CLASSPATH was not configured correctly
thank you Tim for your help
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic