Win a copy of Modern JavaScript for the Impatient this week in the Server-Side JavaScript and NodeJS forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

running a .class file from inside a jar

 
Greenhorn
Posts: 8
  • 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
 
Saloon Keeper
Posts: 6584
160
Android Mac OS X Firefox Browser VI Editor Tomcat Server Safari
  • 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
  • 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
Saloon Keeper
Posts: 6584
160
Android Mac OS X Firefox Browser VI Editor Tomcat Server Safari
  • 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
  • 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
Saloon Keeper
Posts: 6584
160
Android Mac OS X Firefox Browser VI Editor Tomcat Server Safari
  • 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
  • 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
 
rubbery bacon. crispy tiny ad:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
    Bookmark Topic Watch Topic
  • New Topic