File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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 Make it so: Java DB Connections & Transactions this week in the JDBC 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 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:
subject: ClassLoading?
It's not a secret anymore!