Main commands in OSGi boot
[lgpl/argeo-commons.git] / org.argeo.osgi.boot / src / org / argeo / osgi / boot / Main.java
diff --git a/org.argeo.osgi.boot/src/org/argeo/osgi/boot/Main.java b/org.argeo.osgi.boot/src/org/argeo/osgi/boot/Main.java
new file mode 100644 (file)
index 0000000..fdabd99
--- /dev/null
@@ -0,0 +1,32 @@
+package org.argeo.osgi.boot;
+
+import java.lang.management.ManagementFactory;
+
+public class Main {
+
+       public static void main(String[] args) {
+               String mainClass = System.getProperty(OsgiBoot.PROP_ARGEO_OSGI_BOOT_APPCLASS);
+               if (mainClass == null) {
+                       throw new IllegalArgumentException(
+                                       "System property " + OsgiBoot.PROP_ARGEO_OSGI_BOOT_APPCLASS + " must be specified");
+               }
+
+               OsgiBuilder osgi = new OsgiBuilder();
+               String distributionUrl = System.getProperty(OsgiBoot.PROP_ARGEO_OSGI_DISTRIBUTION_URL);
+               if (distributionUrl != null)
+                       osgi.install(distributionUrl);
+               // osgi.conf("argeo.node.useradmin.uris", "os:///");
+               // osgi.conf("osgi.clean", "true");
+               // osgi.conf("osgi.console", "true");
+               osgi.launch();
+               osgi.main(mainClass, args);
+
+               long jvmUptime = ManagementFactory.getRuntimeMXBean().getUptime();
+               String jvmUptimeStr = (jvmUptime / 1000) + "." + (jvmUptime % 1000) + "s";
+               System.out.println("Command " + mainClass + " executed in " + jvmUptimeStr);
+
+               osgi.shutdown();
+
+       }
+
+}