📄 start.java
字号:
public static void main(String[] args) throws IOException { String firstArg = args.length > 0 ? args[0] : ""; Start start = new Start(); if (firstArg.equals("-help") || firstArg.equals("-?")) { System.out.println(""); System.out.println("Usage: java -jar ofbiz.jar [command] [arguments]"); System.out.println("-help, -? ----> This screen"); System.out.println("-install -----> Run install (create tables/load data)"); System.out.println("-setup -------> Run external application server setup"); System.out.println("-start -------> Start the server"); System.out.println("-status ------> Status of the server"); System.out.println("-shutdown ----> Shutdown the server"); System.out.println("-test --------> Run the JUnit test script"); System.out.println("[no config] --> Use default config"); System.out.println("[no command] -> Start the server w/ default config"); } else { // hack for the status and shutdown commands if (firstArg.equals("-status")) { start.init(args, false); System.out.println("Current Status : " + start.status()); } else if (firstArg.equals("-shutdown")) { start.init(args, false); System.out.println("Shutting down server : " + start.shutdown()); } else { // general start start.init(args, true); start.start(); } } } private static String getConfigFileName(String command) { // default command is "start" if (command == null || command.trim().length() == 0) { command = "start"; } // strip off the leading dash if (command.startsWith("-")) { command = command.substring(1); } // shutdown & status hack if (command.equalsIgnoreCase("shutdown")) { command = "start"; } else if (command.equalsIgnoreCase("status")) { command = "start"; } return "org/ofbiz/base/start/" + command + ".properties"; } public static class Config { public String containerConfig; public String testConfig; public InetAddress adminAddress; public int adminPort; public String adminKey; public String ofbizHome; public String baseJar; public String toolsJar; public String commJar; public String baseLib; public String baseDtd; public String baseConfig; public String logDir; public List loaders; public String awtHeadless; public String splashLogo; public boolean shutdownAfterLoad = false; public boolean useShutdownHook = true; public boolean requireToolsJar = false; public boolean requireCommJar = false; private Properties getPropertiesFile(String config) throws IOException { InputStream propsStream = null; Properties props = new Properties(); try { // first try classpath propsStream = getClass().getClassLoader().getResourceAsStream(config); if (propsStream != null) { props.load(propsStream); } else { throw new IOException(); } } catch (IOException e) { // next try file location File propsFile = new File(config); if (propsFile != null) { FileInputStream fis = null; try { fis = new FileInputStream(propsFile); if (fis != null) { props.load(fis); } else { throw new FileNotFoundException(); } } catch (FileNotFoundException e2) { // do nothing; we will see empty props below } finally { if (fis != null) { fis.close(); } } } } finally { if (propsStream != null) { propsStream.close(); } } // check for empty properties if (props.isEmpty()) { throw new IOException("Cannot load configuration properties : " + config); } return props; } public void readConfig(String config) throws IOException { // check the java_version String javaVersion = System.getProperty("java.version"); String javaVendor = System.getProperty("java.vendor"); double version = Double.parseDouble(javaVersion.substring(0, javaVersion.indexOf(".") + 2)); if (REQUIRED_JDK > version) { System.err.println(""); System.err.println("Java Version - " + javaVendor + " " + javaVersion + " - is not supported by OFBiz."); System.err.println("Please install Java2 SDK " + REQUIRED_JDK + "+"); System.err.println(""); System.exit(-1); } Properties props = this.getPropertiesFile(config); // set the ofbiz.home if (ofbizHome == null) { ofbizHome = props.getProperty("ofbiz.home", "."); // get a full path if (ofbizHome.equals(".")) { ofbizHome = System.getProperty("user.dir"); ofbizHome = ofbizHome.replace('\\', '/'); System.out.println("Set OFBIZ_HOME to - " + ofbizHome); } } System.setProperty("ofbiz.home", ofbizHome); // base config directory baseConfig = System.getProperty("ofbiz.base.config"); if (baseConfig == null) { baseConfig = ofbizHome + "/" + props.getProperty("ofbiz.base.config", "base/config"); } // base schema directory baseDtd = System.getProperty("ofbiz.base.schema"); if (baseDtd == null) { baseDtd = ofbizHome + "/" + props.getProperty("ofbiz.base.schema", "base/dtd"); } // base lib directory baseLib = System.getProperty("ofbiz.base.lib"); if (baseLib == null) { baseLib = ofbizHome + "/" + props.getProperty("ofbiz.base.lib", "base/lib"); } // base jar file baseJar = System.getProperty("ofbiz.base.jar"); if (baseJar == null) { baseJar = ofbizHome + "/" + props.getProperty("ofbiz.base.jar", "base/build/lib/ofbiz-base.jar"); } // tools jar String reqTJ = System.getProperty("java.tools.jar.required"); if (reqTJ == null) { reqTJ = props.getProperty("java.tools.jar.required", "false"); } requireToolsJar = "true".equalsIgnoreCase(reqTJ); toolsJar = this.findSystemJar(props, javaVendor, javaVersion, "tools.jar", requireToolsJar); // comm jar String reqCJ = System.getProperty("java.comm.jar.required"); if (reqTJ == null) { reqTJ = props.getProperty("java.comm.jar.required", "false"); } requireCommJar = "true".equalsIgnoreCase(reqCJ); commJar = this.findSystemJar(props, javaVendor, javaVersion, "comm.jar", requireCommJar); // log directory logDir = System.getProperty("ofbiz.log.dir"); if (logDir == null) { logDir = ofbizHome + "/" + props.getProperty("ofbiz.log.dir", "logs"); } // container configuration containerConfig = System.getProperty("ofbiz.container.config"); if (containerConfig == null) { containerConfig = ofbizHome + "/" + props.getProperty("ofbiz.container.config", "base/config/ofbiz-containers.xml"); } // get the admin server info String serverHost = System.getProperty("ofbiz.admin.host"); if (serverHost == null) { serverHost = props.getProperty("ofbiz.admin.host", "127.0.0.1"); } String adminPortStr = System.getProperty("ofbiz.admin.port"); if (adminPortStr == null) { adminPortStr = props.getProperty("ofbiz.admin.port", "0"); } // set the admin key adminKey = System.getProperty("ofbiz.admin.key"); if (adminKey == null) { adminKey = props.getProperty("ofbiz.admin.key", "NA"); } // create the host InetAddress adminAddress = InetAddress.getByName(serverHost); // parse the port number try { adminPort = Integer.parseInt(adminPortStr); } catch (Exception e) { adminPort = 0; } // set the Derby system home String derbyPath = System.getProperty("derby.system.home"); if (derbyPath == null) { derbyPath = props.getProperty("derby.system.home", "data/derby"); } System.setProperty("derby.system.home", derbyPath); // set the property to tell Log4J to use debug.properties String log4jConfig = System.getProperty("log4j.configuration"); if (log4jConfig == null) { log4jConfig = props.getProperty("log4j.configuration"); } // build a default log4j configuration based on ofbizHome if (log4jConfig == null) { log4jConfig = ofbizHome + "/base/config/debug.properties"; } // set the log4j configuration property so we don't pick up one inside jars by mistake System.setProperty("log4j.configuration", log4jConfig); // check for shutdown hook if (System.getProperty("ofbiz.enable.hook") != null && System.getProperty("ofbiz.enable.hook").length() > 0) { useShutdownHook = "true".equalsIgnoreCase(System.getProperty("ofbiz.enable.hook")); } else if (props.getProperty("ofbiz.enable.hook") != null && props.getProperty("ofbiz.enable.hook").length() > 0) { useShutdownHook = "true".equalsIgnoreCase(props.getProperty("ofbiz.enable.hook")); } // check for auto-shutdown if (System.getProperty("ofbiz.auto.shutdown") != null && System.getProperty("ofbiz.auto.shutdown").length() > 0) { shutdownAfterLoad = "true".equalsIgnoreCase(System.getProperty("ofbiz.auto.shutdown")); } else if (props.getProperty("ofbiz.auto.shutdown") != null && props.getProperty("ofbiz.auto.shutdown").length() > 0) { shutdownAfterLoad = "true".equalsIgnoreCase(props.getProperty("ofbiz.auto.shutdown")); } // set AWT headless mode awtHeadless = System.getProperty("java.awt.headless"); if (awtHeadless == null) { awtHeadless = props.getProperty("java.awt.headless"); } if (awtHeadless != null) { System.setProperty("java.awt.headless", awtHeadless); } // get the splash logo splashLogo = props.getProperty("ofbiz.start.splash.logo", null); // set the property to tell Jetty to use 2.4 SessionListeners System.setProperty("org.mortbay.jetty.servlet.AbstractSessionManager.24SessionDestroyed", "true"); // loader classes loaders = new ArrayList(); int currentPosition = 1; while (true) { String loaderClass = props.getProperty("ofbiz.start.loader" + currentPosition); if (loaderClass == null || loaderClass.length() == 0) { break; } else { loaders.add(loaderClass); currentPosition++; } } } private String findSystemJar(Properties props, String javaVendor, String javaVersion, String jarName, boolean required) { String fileSep = System.getProperty("file.separator"); String javaHome = System.getProperty("java.home"); String errorMsg = "Unable to locate " + jarName + " - "; //String foundMsg = "Found " + jarName + " - "; String jarLoc = "lib" + fileSep + jarName; File tj = null; if ("tools.jar".equals(jarName) && javaVendor.startsWith("Apple")) { // tools.jar is always available in Apple's JDK implementation return null; } // check to see if it is in the OFBIZ_HOME directory tj = new File(ofbizHome + fileSep + jarName); if (tj.exists()) { return null; } // check to see if it is in the base/lib directory tj = new File(baseLib + fileSep + jarName); if (tj.exists()) { return null; } // try to locate tools.jar from the properties file String jarProps = props.getProperty("java." + jarName, null); if (jarProps != null) { tj = new File(jarProps); if (!tj.exists()) { if (required) { System.err.println(errorMsg + tj.getAbsolutePath()); } } else { //System.out.println(foundMsg + tj.getAbsolutePath()); return jarProps; } } // next check the JAVA_HOME lib dir tj = new File(javaHome + fileSep + jarLoc); if (!tj.exists()) { if (required) { System.err.println(errorMsg + tj.getAbsolutePath()); } } else { //System.out.println(foundMsg + tj.getAbsolutePath()); return tj.getAbsolutePath(); } // next if we are a JRE dir check the parent dir String jreExt = fileSep + "jre"; if (javaHome.toLowerCase().endsWith(jreExt)) { javaHome = javaHome.substring(0, javaHome.lastIndexOf(fileSep)); tj = new File(javaHome + fileSep + jarLoc); if (!tj.exists()) { if (required) { System.err.println(errorMsg + tj.getAbsolutePath()); } } else { //System.out.println(foundMsg + tj.getAbsolutePath()); return tj.getAbsolutePath(); } } // special windows checking if (javaHome.toLowerCase().charAt(1) == ':') { String driveLetter = javaHome.substring(0, 2); String windowsPath = driveLetter + fileSep + "j2sdk" + javaVersion; tj = new File(windowsPath + fileSep + jarLoc); if (!tj.exists()) { if (required) { System.err.println(errorMsg + tj.getAbsolutePath()); } } else { //System.out.println(foundMsg + tj.getAbsolutePath()); return tj.getAbsolutePath(); } } if (required) { System.err.println(""); System.err.println("Required library " + jarName + " could not be located."); System.err.println("Make sure you using Java2 SDK " + REQUIRED_JDK + "+ and NOT the JRE."); System.err.println("You may need to copy " + jarName + " into a loadable lib directory"); System.err.println("(i.e. OFBIZ_HOME or OFBIZ_HOME/base/lib)"); System.err.println(""); System.exit(-1); } return null; } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -