您好, 欢迎来到 !    登录 | 注册 | | 设为首页 | 收藏本站

Java:通过运行时修改系统属性

Java:通过运行时修改系统属性

您可以使用以下命令在命令行上定义系统属性

-DpropertyName=propertyValue

所以你可以写

java -jar selenium-rc.jar -Dhttp.proxyHost=YourProxyHost -Dhttp.proxyPort=YourProxyPort

请参阅Java- Java应用程序启动器

编辑:

您可以编写一个包装,它是一个应用程序启动器。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);
   }
}
java 2022/1/1 18:14:50 有702人围观

撰写回答


你尚未登录,登录后可以

和开发者交流问题的细节

关注并接收问题和回答的更新提醒

参与内容的编辑和改进,让解决方法与时俱进

请先登录

推荐问题


联系我
置顶