It's not a secret anymore!*
The moose likes Java in General and the fly likes setting the path, classpath from within the java application Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "setting the path, classpath from within the java application" Watch "setting the path, classpath from within the java application" New topic
Author

setting the path, classpath from within the java application

srinivas daroori
Greenhorn

Joined: Feb 23, 2004
Posts: 18
I am looking out to find some way to set the path and classpath from within the java application. I am not able to find one.Is there a way to do that?
( I don't want to set them by running the Runtime.getRuntime().exec() commands).

Thanks!
Joe Ess
Bartender

Joined: Oct 29, 2001
Posts: 8836
    
    7

Well, you can get the classpath by invoking System.getProperty("java.class.path"). I don't know if setting it using System.setProperty() would have any effect.


( I don't want to set them by running the Runtime.getRuntime().exec() commands).


Wouldn't work because you would be setting the classpath in the spawned process, not in your process.


"blabbing like a narcissistic fool with a superiority complex" ~ N.A.
[How To Ask Questions On JavaRanch]
Carlos Costa e Silva
Greenhorn

Joined: Aug 11, 2003
Posts: 3
I don't think you can (change the classpath from inside the vm).

If you really want to manipulate what get's loaded (and from where), look into custom ClassLoader's.
Jim Hicks
Greenhorn

Joined: Jun 23, 2004
Posts: 11
You can't change a classloaders classpath. The only time you can set a classpath is when you create an instance of a classloader. In your application, you can create instances of URLClassloader and supply it with your classpath list.

There is a an Apache utility that does this, called AvalonRepository. You can download it from www.apache.org. The avalon project is not documented very well, and it has a lot of sub projects. The people I know who use avalon, didn't learn how to use avalon from the docs at the avalon site. Rather they tend to learn by doing. Thats how I learned how to use it. I had to work on a project that had a Turbine servlet in it. The Turbine servlet uses avalon.

Avalon is much larger than the repository. This is just one small item, but it is broken out into its own jars and sub project.

To use it, you place your common jar files into a directory that functions as the repository. You then create these property files that end with .meta and place them into the repository. You create an instance of the InitialContext class that requires a path to the repository.
You use the context to request "Artifacts" from the repository. The name of the artifact corresponds to a .meta file. It reads the .meta file, creates the classloader and loads the jars listed in the .meta file.

There are code examples that you should be able to follow. However there is one very important item not documented. When you download the repository jars, do not place all of them into the application's class path. Only put the avalon-repository-main in the application's classpath. The other jars go into the repository. The main jar is a boot jar. It loads the others from the repository.

If anyone is interested in using the avalon repository and has any questions just post them.
[ June 24, 2004: Message edited by: Jim Hicks ]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: setting the path, classpath from within the java application
 
Similar Threads
Batch file
Scheduling a Task With Servlet
Finding libraries on classpaths
Setting up ClassPAth from within my Java Program
Linux, KDE, JBuilder ...