简体   繁体   English

在Java ClassPath中设置网络位置

[英]Setting a Network location in Java ClassPath

I am trying to run a Java Program on Windows machines. 我正在尝试在Windows计算机上运行Java程序。 Libraries for program are placed on a network location - \\\\libs\\myprog . 程序库位于网络位置- \\\\libs\\myprog I can't create a network drive on my windows machine . 我无法在Windows机器上创建网络驱动器

Now question is, how to set Java Classpath for above lib? 现在的问题是,如何为上述lib设置Java Classpath?

I tried following: 我尝试了以下操作:

java -cp \\libs\myprog Main

java -cp //libs/myprog Main

But nothing worked. 但是没有任何效果。

If you are desparate and you really need this (beware: it is lousy from design and performance point of view), you can use a URLClassLoader for retrieving those libraries at runtime. 如果您绝望并且确实需要这样做(请注意:从设计和性能的角度来看这太糟糕了),则可以使用URLClassLoader在运行时检索那些库。 Just configure the URLs you want to load the libs from eg at application start at argument to the main class or as System property and hand them over to a URLClassLoader which then can retrieve the classes (probably a lot slower and more risky then local file system access, but it will work). 只需配置您要从中加载库的URL,例如在应用程序中从主类的参数开始或作为System属性,然后将它们移交给URLClassLoader,然后该URLClassLoader可以检索类(与本地文件系统相比,速度可能慢得多,风险也更大)访问,但它将起作用)。 Have a look at the Javadoc: URLClassLoader javadoc 看看Javadoc: URLClassLoader javadoc

In theory, you can complete your work by "java -javaagent:**.jar=option -jar your.jar". 从理论上讲,您可以通过“ java -javaagent:**。jar = option -jar your.jar”完成工作。

Just as far as i know, you can load Class using URLClassLoader etc from the remote server in agent Class. 据我所知,您可以使用URLClassLoader等从代理类中的远程服务器加载类。

But, it maybe work, because i just coded agent application. 但是,这可能有用,因为我只是编写代理应用程序的代码。

There is no need to do anything special (I checked it with Java 7). 不需要做任何特殊的事情(我用Java 7进行了检查)。

My program was not working because there was some typo. 我的程序无法正常运行,因为有一些错字。 So, if I have to add a jars from a network path 所以,如果我必须从网络路径添加一个罐子

\\\\remote\\libs to my program's classpath, then all I need is to fire following command: \\\\remote\\libs到程序的类路径中,那么我需要执行的是以下命令:

java -cp local.jar;\\remote\libs\*;. MAIN

That is all!! 就这些!!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM