This week's book giveaway is in the OO, Patterns, UML and Refactoring forum.
We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line!
See this thread for details.
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’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link: http://aspose.com
 
subject: ClassLoading?
 
It's not a secret anymore!