Title: [2493] trunk/openejb1/modules/core/src/bin: Updated for better locating of OPENEJB_HOME for Windows and *nix.
- Revision
- 2493
- Author
- jcscoobyrs
- Date
- 2006-02-22 23:01:53 -0500 (Wed, 22 Feb 2006)
Log Message
Updated for better locating of OPENEJB_HOME for Windows and *nix. Also updated the org.openejb.cli.Main for better error handling and to fix a minor logic bug.
Modified Paths
Diff
Modified: trunk/openejb1/modules/core/src/bin/openejb (2492 => 2493)
--- trunk/openejb1/modules/core/src/bin/openejb 2006-02-23 03:47:50 UTC (rev 2492)
+++ trunk/openejb1/modules/core/src/bin/openejb 2006-02-23 04:01:53 UTC (rev 2493)
@@ -6,57 +6,32 @@
# This script is the central entry point to
# all of OpenEJB's functions.
#
-# Contributed by:
+# Tested on OS X, Linux and Windows XP (Cygwin)
#
-# - David Blevins <[EMAIL PROTECTED]>
-# - Daniel S. Haischt <[EMAIL PROTECTED]>
+#
+# Created by Jeremy Whitlock
+# <[EMAIL PROTECTED]>
#
#
# ___________________________________________________________
# $Id$
#============================================================
+
cygwin=false
case "`uname`" in
-CYGWIN*) cygwin=true;;
+ CYGWIN*) cygwin=true;;
esac
-if [ -z "$OPENEJB_HOME" -o ! -d "$OPENEJB_HOME" ] ; then
- # find OpenEJB
- if [ -d /opt/openejb ] ; then
- OPENEJB_HOME=/opt/openejb
- fi
+COMMAND=${0:1}
+WD=$PWD
+OPENEJB_HOME=$WD${COMMAND%/bin/openejb}
- if [ -d "${HOME}/opt/openejb" ] ; then
- OPENEJB_HOME="${HOME}/opt/openejb"
- fi
-
- ## resolve links - $0 may be a link to openejb's home
- PRG="$0"
- progname=`basename "$0"`
-
- # need this for relative symlinks
- while [ -h "$PRG" ] ; do
- ls=`ls -ld "$PRG"`
- link=`expr "$ls" : '.*-> \(.*\)$'`
- if expr "$link" : '/.*' > /dev/null; then
- PRG="$link"
- else
- PRG=`dirname "$PRG"`"/$link"
- fi
- done
-
-
- OPENEJB_HOME=`dirname "$PRG"`/..
-
- # make it fully qualified
- OPENEJB_HOME=`cd "$OPENEJB_HOME" && pwd`
-fi
-
if $cygwin; then
OPENEJB_HOME=`cygpath --path --windows "$OPENEJB_HOME"`
fi
echo OPENEJB_HOME=$OPENEJB_HOME
+
java $JAVA_OPTS -jar $OPENEJB_HOME/lib/[EMAIL PROTECTED]@.jar "$@"
Modified: trunk/openejb1/modules/core/src/bin/openejb.bat (2492 => 2493)
--- trunk/openejb1/modules/core/src/bin/openejb.bat 2006-02-23 03:47:50 UTC (rev 2492)
+++ trunk/openejb1/modules/core/src/bin/openejb.bat 2006-02-23 04:01:53 UTC (rev 2493)
@@ -6,11 +6,12 @@
REM This script is the central entry point to
REM all of OpenEJB's functions.
REM
-REM Tested on Windows 2000
+REM Tested on Windows 2000, Windows XP
+REM Windows XP (Cygwin)
REM
REM
-REM Created by David Blevins
-REM <[EMAIL PROTECTED]>
+REM Created by Jeremy Whitlock
+REM <[EMAIL PROTECTED]>
REM _______________________________________________
REM $Id$
REM================================================
@@ -18,7 +19,7 @@
SETLOCAL
SET COMMAND=%0
-SET OPENEJB_HOME=%COMMAND:~0,-15%
+SET OPENEJB_HOME=%COMMAND:~0,-16%
echo OPENEJB_HOME=%OPENEJB_HOME%
Modified: trunk/openejb1/modules/core/src/java/org/openejb/cli/Main.java (2492 => 2493)
--- trunk/openejb1/modules/core/src/java/org/openejb/cli/Main.java 2006-02-23 03:47:50 UTC (rev 2492)
+++ trunk/openejb1/modules/core/src/java/org/openejb/cli/Main.java 2006-02-23 04:01:53 UTC (rev 2493)
@@ -39,34 +39,37 @@
public static void setupClasspath() {
ClassLoader current = Thread.currentThread().getContextClassLoader();
URL classURL = Thread.currentThread().getContextClassLoader().getResource(basePath + "start");
- String propsString = classURL.getFile();
- URL jarURL = null;
- File jarFile = null;
- propsString = propsString.substring(0, propsString.indexOf("!"));
-
- try {
- jarURL = new URL(propsString);
- } catch (MalformedURLException e) {
- e.printStackTrace();
+ if (classURL != null) {
+ String propsString = classURL.getFile();
+ URL jarURL = null;
+ File jarFile = null;
+
+ propsString = propsString.substring(0, propsString.indexOf("!"));
+
+ try {
+ jarURL = new URL(propsString);
+ } catch (MalformedURLException e) {
+ e.printStackTrace();
+ }
+ jarFile = new File(jarURL.getFile());
+
+ if (jarFile.getName().indexOf("openejb-core") > -1) {
+ File lib = jarFile.getParentFile();
+ File home = lib.getParentFile();
+
+ System.setProperty("openejb.home", home.getAbsolutePath());
+ }
+
+ File lib = new File(System.getProperty("openejb.home") + File.separator + "lib");
+ SystemClassPath systemCP = new SystemClassPath();
+
+ try {
+ systemCP.addJarsToPath(lib);
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
}
- jarFile = new File(jarURL.getFile());
-
- if (jarFile.getName().indexOf("openejb-core") > -1) {
- File lib = jarFile.getParentFile();
- File home = lib.getParentFile();
-
- System.setProperty("openejb.home", home.getAbsolutePath());
- }
-
- File lib = new File(System.getProperty("openejb.home") + File.separator + "lib");
- SystemClassPath systemCP = new SystemClassPath();
-
- try {
- systemCP.addJarsToPath(lib);
- } catch (Exception e) {
- e.printStackTrace();
- }
}
public static void main(String[] args) {
@@ -87,85 +90,91 @@
init();
- if (args.length > 0) {
- Properties props = null;
+ if (args.length == 0 || args[0].equals("--help")) {
+ System.out.println("Usage: openejb help [command]");
- if (args[0].equals("--help")) {
- System.out.println("Usage: openejb help [command]");
-
+ printAvailableCommands();
+
+ return;
+ }
+
+ Properties props = null;
+ boolean help = false;
+ int argIndex = 0;
+
+ if (args[0].equals("help")) {
+ if (args.length < 2) {
printAvailableCommands();
- } else {
- String mainClass = null;
- Class clazz = null;
- boolean help = false;
- if (args[0].equals("help")) {
- if (args.length < 2) {
- printAvailableCommands();
- }
-
- try {
- props = finder.doFindCommandProperies(args[1]);
- } catch (IOException e1) {
- System.out.println("Unavailable command: " + args[1]);
-
- printAvailableCommands();
- }
-
- help = true;
- }
-
- if (props != null) {
- mainClass = props.getProperty("main.class");
- }
-
- try {
- clazz = Thread.currentThread().getContextClassLoader().loadClass(mainClass);
- } catch (ClassNotFoundException e) {
- e.printStackTrace();
- }
-
- Method mainMethod = null;
-
- try {
- mainMethod = clazz.getMethod("main", new Class[]{String[].class});
- } catch (SecurityException e) {
- e.printStackTrace();
- } catch (NoSuchMethodException e) {
- e.printStackTrace();
- }
-
- argsList = new ArrayList();
- int startPoint = 1;
-
- if (help) {
- startPoint = 2;
-
- argsList.add("--help");
- }
-
-
- for (int i = startPoint; i < args.length; i++) {
- argsList.add(args[i]);
- }
-
- args = (String[])argsList.toArray(new String[argsList.size()]);
-
- try {
- mainMethod.invoke(clazz, new Object[] { args });
- } catch (IllegalArgumentException e) {
- e.printStackTrace();
- } catch (IllegalAccessException e) {
- e.printStackTrace();
- } catch (InvocationTargetException e) {
- e.printStackTrace();
- }
+ return;
}
- } else {
- System.out.println("Usage: openejb command [command-options-and-arguments]\n");
+ help = true;
+
+ argIndex = 1;
+ }
+
+ String commandName = args[argIndex];
+
+ try {
+ props = finder.doFindCommandProperies(commandName);
+ } catch (IOException e1) {
+ System.out.println("Unavailable command: " + commandName);
+
printAvailableCommands();
+
+ return;
}
+
+ if (props == null) {
+ System.out.println("Unavailable command: " + commandName);
+ printAvailableCommands();
+ return;
+ }
+
+ String mainClass = props.getProperty("main.class");
+ if (mainClass == null) {
+ throw new NullPointerException("Command "+commandName+" did not specify a main.class property");
+ }
+
+ Class clazz = null;
+ try {
+ clazz = Thread.currentThread().getContextClassLoader().loadClass(mainClass);
+ } catch (ClassNotFoundException e) {
+ throw new IllegalStateException("Command "+commandName+" main.class does not exist: "+mainClass);
+ }
+
+ Method mainMethod = null;
+ try {
+ mainMethod = clazz.getMethod("main", new Class[]{String[].class});
+ } catch (Exception e) {
+ throw new IllegalStateException("Main class of command "+commandName+" does not have a static main method: "+mainClass);
+ }
+
+ argsList = new ArrayList();
+ int startPoint = 1;
+
+ if (help) {
+ startPoint = 2;
+
+ argsList.add("--help");
+ }
+
+ for (int i = startPoint; i < args.length; i++) {
+ argsList.add(args[i]);
+ }
+
+ args = (String[])argsList.toArray(new String[argsList.size()]);
+
+ try {
+ mainMethod.invoke(clazz, new Object[] { args });
+ } catch (IllegalArgumentException e) {
+ e.printStackTrace();
+ } catch (IllegalAccessException e) {
+ e.printStackTrace();
+ } catch (InvocationTargetException e) {
+ e.printStackTrace();
+ }
}
private static void printAvailableCommands() {
@@ -207,7 +216,5 @@
System.out.println("For updates and additional information, visit");
System.out.println("http://www.openejb.org\n");
System.out.println("Bug Reports to <[email protected]>");
-
- System.exit(0);
}
}