Allow running not within a WAR By setting -DExecutable-War-Package=blah on the JVM arguments we can support launching code from the ExecutableWarMain without unpacking it from the WAR file to local disk. This is handy if you are trying to run the code through an IDE debugger. Signed-off-by: Shawn O. Pearce <sop@google.com>
diff --git a/pom.xml b/pom.xml index b368e1a..a1c05f3 100644 --- a/pom.xml +++ b/pom.xml
@@ -21,7 +21,7 @@ <groupId>gerrit</groupId> <artifactId>executablewar</artifactId> <packaging>jar</packaging> - <version>1.1</version> + <version>1.2</version> <name>executablewar</name> <description>Support for running code directly from WAR files</description> <url>http://android.git.kernel.org/?p=tools/executablewar.git</url>
diff --git a/src/main/java/ExecutableWarMain.java b/src/main/java/ExecutableWarMain.java index 4d2e8fb..c93be7e 100644 --- a/src/main/java/ExecutableWarMain.java +++ b/src/main/java/ExecutableWarMain.java
@@ -127,14 +127,7 @@ final String[] argv = new String[origArgv.length - 1]; System.arraycopy(origArgv, 1, argv, 0, argv.length); - final Attributes att = myManifest(); - String pkg = att.getValue(EXECUTABLE_WAR_PACKAGE); - if (pkg == null) { - pkg = ""; - } else { - pkg = pkg + "."; - } - + String pkg = cmdPackage(); Class<?> clazz; try { try { @@ -180,6 +173,21 @@ } } + private static String cmdPackage() throws IOException, MalformedURLException { + String pkg = System.getProperty(EXECUTABLE_WAR_PACKAGE); + if (pkg != null && !pkg.equals("")) { + return pkg + "."; + } + + pkg = myManifest().getValue(EXECUTABLE_WAR_PACKAGE); + if (pkg == null) { + pkg = ""; + } else { + pkg = pkg + "."; + } + return pkg; + } + private static Attributes myManifest() throws IOException, MalformedURLException { final InputStream mfin = @@ -237,7 +245,7 @@ throw new LinkageError("Cannot unpack libs from " + myURL); } if (paths.isEmpty()) { - throw new LinkageError("No files under WEB-INF/lib/"); + return ExecutableWarMain.class.getClassLoader(); } return new URLClassLoader(paths.toArray(new URL[paths.size()])); }