开发者

Set classpath with a java program?

I want to set this C:\Program Files\OpenO开发者_StackOverflow中文版ffice.org 3\program as a classpath with java program. How can I do that?


Its not much use modifying the classpath after JVM startup, as that system property has already been read by the runtime during intialization and your changes will have no effect.

I recommend using scripts to modify your classpath before initializing java


add -classpath C:\Program Files\OpenOffice.org 3\program to your java command


Go to My Computer > right click > Properties > Advance Tab > Environment variable > System variable > New.

Add

   Name : CLASSPATH  
   Value : C:\Program Files\OpenOffice.org 3\program


Assuming you have a fixed class path in your application and you want to load classes from C:\Program Files\OpenOffice.org 3\program (which might be a path configured by the user of your application at runtime), you can use

ClassLoader classLoader = new URLClassLoader(new URL[] {
    new File("C:\\Program Files\\OpenOffice.org 3\\program").toURI().toURL()
});
classLoader.loadClass("com.mycompany.FooBar");

to load the class com.mycompany.FooBar.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜