Java: changing system properties through the runtime

I have a jar file that I am running. This is a Selenium RC server. I want to be able to change the JVM values ​​of httpProxy.host/port/etc. On the one hand, I can change the source and add this function. It would take some time. Is there another way to do this? Like my own JAR (which set these JVM properties), is selenium-rc called inside the same JVM instance (so it can change the values ​​of the JVM variable)?

+3
source share
2 answers

You can define system properties on the command line using

-DpropertyName=propertyValue

So you can write

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

See Java - java launcher application ,

EDIT:

, . 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);
   }
}
+5

Source: https://habr.com/ru/post/1755226/


All Articles