Browse Source

pass in db server as parameter

Nick Kasvosve 10 years ago
parent
commit
84f2a81ebc

+ 24 - 1
frameworks/Java/beyondj/beyondj-launcher/src/main/java/com/techempower/beyondj/BeyondJApplication.java

@@ -18,6 +18,9 @@ import java.net.JarURLConnection;
 import java.net.URL;
 import java.security.CodeSource;
 import java.security.ProtectionDomain;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
 
 /**
  * @author nickk
@@ -29,6 +32,19 @@ public class BeyondJApplication {
 
         System.out.println("Start Launching Beyondj");
 
+        if (args != null && args.length > 0) {
+            for (String arg : args) {
+                Map<String, String> map = convert(arg);
+                Iterator<String> iterator = map.keySet().iterator();
+                while (iterator.hasNext()) {
+                    String key = iterator.next();
+                    String value = map.get(key);
+                    System.setProperty(key, value);
+                    System.out.println("Set System Property " + key + " to " + value);
+                }
+            }
+        }
+
         ApplicationContext context = new ClassPathXmlApplicationContext("/config/spring/core-spring-and-camel-config.xml");
         extractResources(context);
 
@@ -50,6 +66,13 @@ public class BeyondJApplication {
         system.awaitTermination();
     }
 
+    private static Map<String, String> convert(String str) {
+        String[] tokens = str.split(" |=");
+        Map<String, String> map = new HashMap<>();
+        for (int i = 0; i < tokens.length - 1; ) map.put(tokens[i++], tokens[i++]);
+        return map;
+    }
+
     private static void extractResources(ApplicationContext context) throws Exception {
 
         Config config = (Config) context.getBean(ApplicationConfiguration.CONFIG);
@@ -77,7 +100,7 @@ public class BeyondJApplication {
                 LaunchUtil.extractJar(locFile.getAbsolutePath(), installationDir.getAbsolutePath());
             }
         } else {
-           // throw new IllegalStateException("Not able to install platform. File format must be JAR");
+            // throw new IllegalStateException("Not able to install platform. File format must be JAR");
         }
 
         String webAppsPath = path + File.separator + ApplicationConfiguration.LAUNCHERS + File.separator