my dog learned polymorphism*
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
JavaRanch » Java Forums » Java » Java in General
Bookmark "ClassLoading?" Watch "ClassLoading?" New topic
Author

ClassLoading?

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
Sheriff

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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: ClassLoading?