wood burning stoves 2.0*
The moose likes Java in General and the fly likes ClassLoading? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "ClassLoading?" Watch "ClassLoading?" New topic


V Bose
Ranch Hand

Joined: Jul 10, 2003
Posts: 113
What would be the easiest way to run a java class located inside jar file from within a another running java program?
Ben Souther

Joined: Dec 11, 2004
Posts: 13410

Add the jar file to your classpath.
Import the class.
Then instanciate the class and call it's methods.

For example, if I had a jar file (foo.jar) with a foo.bar package.
In this package is a class named Thingy with a method called sayHello().

On Unix:
export CLASSPATH=$CLASSPATH:/jars/foo.jar

or on Windows:
set CLASSPATH=%CLASSPATH%;C:\jars\foo.jar

Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
subject: ClassLoading?
Similar Threads
zipping as self extracting exe
WA #2 ..... word association
c++ or Java--your suggestions please