我有一个运行的jar文件.它是Selenium RC服务器.我希望能够更改JVM httpProxy.host/port/etc系统值.一方面,我可以修改源并添加此功能.需要一些时间.还有另一种可能的方法吗?就像拥有我自己的JAR(它会设置这些JVM属性)一样,在同一个JVM实例中调用selenium-rc(这样它就可以修改它的JVM变量的值)?
您可以使用命令行在系统属性上定义
-DpropertyName=propertyValue
Run Code Online (Sandbox Code Playgroud)
所以你可以写
java -jar selenium-rc.jar -Dhttp.proxyHost=YourProxyHost -Dhttp.proxyPort=YourProxyPort
Run Code Online (Sandbox Code Playgroud)
编辑:
您可以编写一个作为应用程序启动器的包装器.很容易模拟main使用反射调用类中的方法.然后,您还可以System.setProperty在启动最终应用程序之前设置系统属性.例如,
public class AppWrapper
{
/* args[0] - class to launch */
public static void main(String[] args) throws Exception
{ // error checking omitted for brevity
Class app = Class.forName(args[0]);
Method main = app.getDeclaredMethod("main", new Class[] { (new String[1]).getClass()});
String[] appArgs = new String[args.length-1];
System.arraycopy(args, 1, appArgs, 0, appArgs.length);
System.setProperty("http.proxyHost", "someHost");
main.invoke(null, appArgs);
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
7140 次 |
| 最近记录: |