• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

running a .class file from inside a jar

 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Saloon Keeper
Posts: 7585
176
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Saloon Keeper
Posts: 7585
176
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Saloon Keeper
Posts: 7585
176
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
problem solved
the issue was that the CLASSPATH was not configured correctly
thank you Tim for your help
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic