Browse Source

jetty support

benjobs 7 years ago
parent
commit
a4c99fd2ca

+ 111 - 0
agent.sh

@@ -0,0 +1,111 @@
+#!/bin/bash
+
+#echo color
+WHITE_COLOR="\E[1;37m";
+RED_COLOR="\E[1;31m";
+BLUE_COLOR='\E[1;34m';
+GREEN_COLOR="\E[1;32m";
+YELLOW_COLOR="\E[1;33m";
+RES="\E[0m";
+
+echo_r () {
+    # Color red: Error, Failed
+    [ $# -ne 1 ] && return 1
+    echo -e "[${GREEN_COLOR}opencron${RES}] ${RED_COLOR}$1${RES}"
+}
+
+echo_g () {
+    # Color green: Success
+    [ $# -ne 1 ] && return 1
+    echo -e "[${GREEN_COLOR}opencron${RES}] ${GREEN_COLOR}$1${RES}"
+}
+
+echo_y () {
+    # Color yellow: Warning
+    [ $# -ne 1 ] && return 1
+    echo -e "[${GREEN_COLOR}opencron${RES}] ${YELLOW_COLOR}$1${RES}"
+}
+
+echo_w () {
+    # Color yellow: White
+    [ $# -ne 1 ] && return 1
+    echo -e "[${GREEN_COLOR}opencron${RES}] ${WHITE_COLOR}$1${RES}"
+}
+
+echo -ne "${GREEN_COLOR}"
+cat<<EOT
+
+      --------------------------------------------
+    /                                              \\
+   /   ___  _ __   ___ _ __   ___ _ __ ___  _ __    \\
+  /   / _ \| '_ \ / _ \ '_ \ / __| '__/ _ \| '_ \\    \\
+ /   | (_) | |_) |  __/ | | | (__| | | (_) | | | |    \\
+ \\    \___/| .__/ \___|_| |_|\___|_|  \___/|_| |_|    /
+  \\        |_|                                       /
+   \\                                                /
+    \\       --opencron,Let's crontab easy!         /
+      --------------------------------------------
+
+EOT
+echo -ne "${RES}";
+
+# OS specific support.  $var _must_ be set to either true or false.
+cygwin=false
+darwin=false
+os400=false
+case "`uname`" in
+CYGWIN*) cygwin=true;;
+Darwin*) darwin=true;;
+OS400*) os400=true;;
+esac
+
+# resolve links - $0 may be a softlink
+PRG="$0"
+
+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
+
+# Get standard environment variables
+PRGDIR=`dirname "$PRG"`
+
+WORKDIR=`cd "$PRGDIR" >/dev/null; pwd`;
+
+APP_ARTIFACT=opencron-agent
+
+APP_VERSION="1.1.0-RELEASE";
+
+APP_TAR_NAME=${APP_ARTIFACT}-${APP_VERSION}.tar.gz
+
+MAVEN_TARGET_TAR="${WORKDIR}"/${APP_ARTIFACT}/target/${APP_TAR_NAME}
+
+DIST_PATH=${WORKDIR}/dist/
+
+[ ! -d "${DIST_PATH}" ] && mkdir -p "${DIST_PATH}"
+
+DEPLOY_PATH=${WORKDIR}/dist/opencron-agent
+
+#先检查dist下是否有war包
+if [ ! -f "${DIST_PATH}/${APP_TAR_NAME}" ] ; then
+    #dist下没有tar包则检查agent的target下是否有tar包.
+   if [ ! -f "${MAVEN_TARGET_TAR}" ] ; then
+      echo_w "[opencron] please build project first!"
+      exit 0;
+   else
+      cp ${MAVEN_TARGET_TAR} ${DIST_PATH};
+   fi
+fi
+
+[ -d "${DEPLOY_PATH}" ] && rm -rf ${DEPLOY_PATH}/* || mkdir -p ${DEPLOY_PATH}
+
+tar -xzvf ${DIST_PATH}/${APP_TAR_NAME} -C ${DEPLOY_PATH}/../
+
+#startup
+/bin/bash +x "${DEPLOY_PATH}/bin/startup.sh" "$@"
+

+ 15 - 15
build.sh

@@ -51,7 +51,7 @@ done
 # Get standard environment variables
 PRGDIR=`dirname "$PRG"`
 
-WORKDIR="`readlink -f ${PRGDIR}`"
+WORKDIR=`cd "$PRGDIR" >/dev/null; pwd`;
 
 MAVEN_URL="http://mirror.bit.edu.cn/apache/maven/maven-3/3.5.2/binaries/apache-maven-3.5.2-bin.tar.gz";
 
@@ -59,14 +59,13 @@ MAVEN_NAME="apache-maven-3.5.2-bin"
 
 UNPKG_MAVEN_NAME="apache-maven-3.5.2";
 
-OPENCRON_VERSION="1.2.0-RELEASE";
+OPENCRON_VERSION="1.1.0-RELEASE";
 
-BUILD_HOME=${WORKDIR}/build
+MAVEN_PATH="/tmp";
 
-[ ! -d ${BUILD_HOME} ] && mkdir ${BUILD_HOME}
+[ ! -d "$MAVEN_PATH" ] && mkdir $MAVEN_PATH;
 
-[ ! -d ${BUILD_HOME}/dist ] && mkdir ${BUILD_HOME}/dist/
-rm -rf ${BUILD_HOME}/dist/*
+DIST_HOME="${WORKDIR}/dist"
 
 echo_r () {
     # Color red: Error, Failed
@@ -113,9 +112,9 @@ if [ $? -ne 1 ]; then
 
     echo_y "WARNING:maven is not install!"
 
-    if [ -x "${BUILD_HOME}/${UNPKG_MAVEN_NAME}" ] ; then
+    if [ -x "/tmp/${UNPKG_MAVEN_NAME}" ] ; then
         echo_w "maven is already download,now config setting...";
-        MVN=${BUILD_HOME}/${UNPKG_MAVEN_NAME}/bin/mvn
+        MVN=/tmp/${UNPKG_MAVEN_NAME}/bin/mvn
     else
         echo_w "download maven Starting..."
         echo_w "checking network connectivity ... "
@@ -125,11 +124,11 @@ if [ $? -ne 1 ]; then
         retval=$?
         if [ ${retval} -eq 0 ] ; then
             echo_w "network is connectioned,download maven Starting... "
-            wget -P ${BUILD_HOME} $MAVEN_URL && {
+            wget -P "/tmp" $MAVEN_URL && {
                 echo_g "download maven successful!";
                 echo_w "install maven Starting"
-                tar -xzvf ${BUILD_HOME}/${MAVEN_NAME}.tar.gz -C ${BUILD_HOME}
-                MVN=${BUILD_HOME}/${UNPKG_MAVEN_NAME}/bin/mvn
+                tar -xzvf /tmp/${MAVEN_NAME}.tar.gz -C /tmp
+                MVN=/tmp/${UNPKG_MAVEN_NAME}/bin/mvn
             }
         elif [ ${retval} -ne 0 ]; then
             echo_r "ERROR:network is blocked! download maven failed,please check your network!build error! bye!"
@@ -148,11 +147,12 @@ $MVN clean install -Dmaven.test.skip=true;
 retval=$?
 
 if [ ${retval} -eq 0 ] ; then
-    cp ${WORKDIR}/opencron-agent/target/opencron-agent-${OPENCRON_VERSION}.tar.gz ${BUILD_HOME}/dist/
-    cp ${WORKDIR}/opencron-server/target/opencron-server.war ${BUILD_HOME}/dist/
-    echo -e "[${GREEN_COLOR}opencron${RES}] ${WHITE_COLOR}build opencron @ Version ${BLUE_COLOR}${OPENCRON_VERSION}${RES} successfully! please goto${RES} ${GREEN_COLOR}${BUILD_HOME}/dist${RES}"
+    [ ! -d "${DIST_HOME}" ] && mkdir ${DIST_HOME} || rm -rf  ${DIST_HOME}/* ;
+    cp ${WORKDIR}/opencron-agent/target/opencron-agent-${OPENCRON_VERSION}.tar.gz ${DIST_HOME}
+    cp ${WORKDIR}/opencron-server/target/opencron-server.war ${DIST_HOME}
+    echo -e "[${GREEN_COLOR}opencron${RES}] ${WHITE_COLOR}build opencron @ Version ${BLUE_COLOR}${OPENCRON_VERSION}${RES} successfully! please goto${RES} ${GREEN_COLOR}${DIST_HOME}${RES}"
     exit 0
 else
     echo_r "build opencron failed! please try again "
     exit 1
-fi
+fi

+ 19 - 3
opencron-common/src/main/java/org/opencron/common/utils/ExtClasspathLoader.java

@@ -70,17 +70,33 @@ public final class ExtClasspathLoader {
         }
     }
 
-    public static void loadJarByPath(String path) {
+    public static void loadJar(String jarFilePath) {
+        File jarFile = new File(jarFilePath);
+        if (!jarFile.exists()) {
+            throw new IllegalArgumentException("[opencron] jarFilePath:"+jarFilePath+" is not exists");
+        }
+        if (jarFile.isFile()) {
+            throw new IllegalArgumentException("[opencron] jarFile "+jarFilePath+" is not file");
+        }
+        loadPath(jarFile.getAbsolutePath());
+    }
+
+    public static void scanJar(String path) {
         File jarDir = new File(path);
         if (!jarDir.exists()) {
-            throw new IllegalArgumentException("[opencron] jarPath is not exists");
+            throw new IllegalArgumentException("[opencron] jarPath:"+path+" is not exists");
         }
         if (!jarDir.isDirectory()) {
-            throw new IllegalArgumentException("[opencron] jarPath is not directory");
+            throw new IllegalArgumentException("[opencron] jarPath:"+path+" is not directory");
+        }
+
+        if ( jarDir.listFiles().length == 0 ) {
+            throw new IllegalArgumentException("[opencron] have not jar in path:"+path);
         }
 
         for (File jarFile:jarDir.listFiles()) {
             loadPath(jarFile.getAbsolutePath());
         }
     }
+
 }

+ 1 - 32
opencron-server/pom.xml

@@ -59,37 +59,6 @@
             <artifactId>sitemesh</artifactId>
         </dependency>
 
-        <!--jetty-->
-        <dependency>
-            <groupId>org.eclipse.jetty</groupId>
-            <artifactId>jetty-util</artifactId>
-            <scope>provided</scope>
-        </dependency>
-
-        <dependency>
-            <groupId>org.eclipse.jetty</groupId>
-            <artifactId>jetty-webapp</artifactId>
-            <scope>provided</scope>
-        </dependency>
-
-        <dependency>
-            <groupId>org.eclipse.jetty</groupId>
-            <artifactId>jetty-server</artifactId>
-            <scope>provided</scope>
-        </dependency>
-
-        <dependency>
-            <groupId>org.eclipse.jetty.websocket</groupId>
-            <artifactId>websocket-server</artifactId>
-            <scope>provided</scope>
-        </dependency>
-
-        <dependency>
-            <groupId>org.eclipse.jetty</groupId>
-            <artifactId>jetty-servlet</artifactId>
-            <scope>provided</scope>
-        </dependency>
-
         <!--和tomcat有冲突.-->
         <dependency>
             <groupId>org.eclipse.jetty</groupId>
@@ -238,7 +207,7 @@
                         </dependency>
 
                     </artifactItems>
-                    <outputDirectory>${project.build.directory}/jettylib</outputDirectory>
+                    <outputDirectory>${project.build.directory}/../jetty</outputDirectory>
                 </configuration>
             </plugin>
 

+ 19 - 2
opencron-server/src/main/java/org/opencron/server/bootstrap/JettyLauncher.java

@@ -13,13 +13,15 @@ import org.opencron.common.utils.NetUtils;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+import java.io.File;
+
 public class JettyLauncher {
 
     private  Logger logger = LoggerFactory.getLogger(Startup.class);
 
     private static int startPort = 8080;
 
-    public void start(String warPath,String[] args) {
+    public void start(String artifact, File warFile, boolean launcher, String[] args) {
 
         if (CommonUtils.notEmpty(args)) {
             Integer port = CommonUtils.toInt(args[0]);
@@ -36,7 +38,21 @@ public class JettyLauncher {
 
         WebAppContext appContext = new WebAppContext();
 
-        appContext.setWar(warPath);
+        //war存在
+        if (CommonUtils.notEmpty(warFile)) {
+            appContext.setWar(warFile.getAbsolutePath());
+        }else {
+            //通过脚本启动器启动的服务
+            if (launcher) {
+                appContext.setDescriptor("./WEB-INF/web.xml");
+                appContext.setResourceBase("./");
+            }else {
+                //开发者模式...
+                String baseDir = "./".concat(artifact);
+                appContext.setDescriptor(baseDir + "/src/main/webapp/WEB-INF/web.xml");
+                appContext.setResourceBase(baseDir + "/src/main/webapp");
+            }
+        }
 
         //init param
         appContext.setThrowUnavailableOnStartupException(true);    // 在启动过程中允许抛出异常终止启动并退出 JVM
@@ -85,4 +101,5 @@ public class JettyLauncher {
 
     }
 
+
 }

+ 19 - 18
opencron-server/src/main/java/org/opencron/server/bootstrap/Startup.java

@@ -9,28 +9,29 @@ public class Startup {
 
     public static void main(String[] args) {
 
-        MavenUtils mavenUtils = MavenUtils.get(Startup.class.getClassLoader());
-
-        String artifactName = mavenUtils.getArtifactId();
-
-        String warName = artifactName.concat(".war");
-
-        System.setProperty("catalina.home", "./".concat(artifactName));
-
-        File warFile = new File("./".concat(artifactName).concat("/target/").concat(warName));
-        if (!warFile.exists()) {
-            throw new IllegalArgumentException("[opencron] start server error,please build project with maven first!");
+        String launcher = System.getProperty("server.launcher");
+
+        String artifact = null;
+        String jettyJarPath = null;
+        File warFile = null;
+
+        //dev 开发者模式通过ide启动的main
+        if (launcher == null) {
+            artifact = MavenUtils.get(Thread.currentThread().getContextClassLoader()).getArtifactId();
+            jettyJarPath = "./".concat(artifact).concat("/jetty");
+            warFile = new File( "./".concat(artifact).concat("/target/").concat(artifact).concat(".war") );
+            System.setProperty("catalina.home","./".concat(artifact));
+        }else if (launcher.equals("jetty")){
+            //server.sh脚本启动的...
+            jettyJarPath = "./jetty";
+            System.setProperty("catalina.home","./");
         }
-
-        //add jetty jar...
-        String jettyJarPath = "./"+artifactName+"/target/jettylib";
-
-        ExtClasspathLoader.loadJarByPath(jettyJarPath);
-
+        ExtClasspathLoader.scanJar(jettyJarPath);
         JettyLauncher jettyLauncher = new JettyLauncher();
-        jettyLauncher.start(warFile.getPath(),args);
+        jettyLauncher.start(artifact,warFile,launcher!=null,args);
 
     }
 
+
 }
 

+ 5 - 3
opencron-server/src/main/java/org/opencron/server/controller/DashboardController.java

@@ -218,12 +218,15 @@ public class DashboardController extends BaseController {
                 return;
             }
 
+
             if (user.getHeaderpic() != null) {
                 String name = user.getUserId() + "_140" + user.getPicExtName();
-                String path = httpSession.getServletContext().getRealPath(File.separator) + "upload" + File.separator + name;
+                String path = httpSession.getServletContext().getRealPath("/").replaceFirst("/$","") + "/upload/" + name;
                 IOUtils.writeFile(new File(path), user.getHeaderpic().getBinaryStream());
                 user.setHeaderPath(getWebUrlPath(request) + "/upload/" + name);
+                session.setAttribute(OpencronTools.LOGIN_USER, user);
             }
+
             writeJson(response, String.format(format, "success", "url", "/dashboard.htm?csrf=" + csrf, "csrf", csrf));
         }
     }
@@ -263,8 +266,7 @@ public class DashboardController extends BaseController {
         }
 
         String rootPath = httpSession.getServletContext().getRealPath("/");
-        rootPath +=  rootPath.endsWith("/")?"":"/";
-        String path = rootPath + "upload/";
+        String path = rootPath.replaceFirst("/$","") + "/upload/";
 
         String picName = user.getUserId() + extensionName.toLowerCase();
 

+ 7 - 1
opencron-server/src/main/webapp/WEB-INF/layouts/menu.jsp

@@ -16,7 +16,13 @@
 			<!-- Profile Menu -->
 			<div class="text-center s-widget m-b-25 dropdown" id="profile-menu">
 				<a href="" id="header-img" data-toggle="dropdown" class="animated a-hover">
-					<img class="profile-pic" id="profile-pic" width="140px;" height="140px;"  onerror="javascript:this.src='${contextPath}/static/img/profile-pic.jpg'" src="${contextPath}/upload/${opencron_user.userId}${opencron_user.picExtName}?<%=System.currentTimeMillis()%>">
+					<img class="profile-pic" id="profile-pic" width="140px;" height="140px;"  onerror="javascript:this.src='${contextPath}/static/img/profile-pic.jpg'"
+					<c:if test="${opencron_user.headerPath == null}  ">
+						 src="${contextPath}/upload/${opencron_user.userId}${opencron_user.picExtName}?<%=System.currentTimeMillis()%>">
+					</c:if>
+					<c:if test="${opencron_user.headerPath != null}">
+						src="${opencron_user.headerPath}?<%=System.currentTimeMillis()%>">
+					</c:if>
 					<div class="change-text" id="change-img" href="javascript:void(0);">更换头像</div>
 				</a>
 				<h4 class="m-0">${opencron_user.userName}</h4>

+ 190 - 0
opencron-server/startup.sh

@@ -0,0 +1,190 @@
+#!/bin/bash
+
+#echo color
+WHITE_COLOR="\E[1;37m";
+RED_COLOR="\E[1;31m";
+BLUE_COLOR='\E[1;34m';
+GREEN_COLOR="\E[1;32m";
+YELLOW_COLOR="\E[1;33m";
+RES="\E[0m";
+
+echo_r () {
+    # Color red: Error, Failed
+    [ $# -ne 1 ] && return 1
+    echo -e "[${GREEN_COLOR}opencron${RES}] ${RED_COLOR}$1${RES}"
+}
+
+echo_g () {
+    # Color green: Success
+    [ $# -ne 1 ] && return 1
+    echo -e "[${GREEN_COLOR}opencron${RES}] ${GREEN_COLOR}$1${RES}"
+}
+
+echo_y () {
+    # Color yellow: Warning
+    [ $# -ne 1 ] && return 1
+    echo -e "[${GREEN_COLOR}opencron${RES}] ${YELLOW_COLOR}$1${RES}"
+}
+
+echo_w () {
+    # Color yellow: White
+    [ $# -ne 1 ] && return 1
+    echo -e "[${GREEN_COLOR}opencron${RES}] ${WHITE_COLOR}$1${RES}"
+}
+
+echo -ne "${GREEN_COLOR}"
+cat<<EOT
+
+      --------------------------------------------
+    /                                              \\
+   /   ___  _ __   ___ _ __   ___ _ __ ___  _ __    \\
+  /   / _ \| '_ \ / _ \ '_ \ / __| '__/ _ \| '_ \\    \\
+ /   | (_) | |_) |  __/ | | | (__| | | (_) | | | |    \\
+ \\    \___/| .__/ \___|_| |_|\___|_|  \___/|_| |_|    /
+  \\        |_|                                       /
+   \\                                                /
+    \\       --opencron,Let's crontab easy!         /
+      --------------------------------------------
+
+EOT
+echo -ne "${RES}";
+
+# Make sure prerequisite environment variables are set
+if [ -z "$JAVA_HOME" -a -z "$JRE_HOME" ]; then
+  if $darwin; then
+    # Bugzilla 54390
+    if [ -x '/usr/libexec/java_home' ] ; then
+      export JAVA_HOME=`/usr/libexec/java_home`
+    # Bugzilla 37284 (reviewed).
+    elif [ -d "/System/Library/Frameworks/JavaVM.framework/Versions/CurrentJDK/Home" ]; then
+      export JAVA_HOME="/System/Library/Frameworks/JavaVM.framework/Versions/CurrentJDK/Home"
+    fi
+  else
+    JAVA_PATH=`which java 2>/dev/null`
+    if [ "x$JAVA_PATH" != "x" ]; then
+      JAVA_PATH=`dirname $JAVA_PATH 2>/dev/null`
+      JRE_HOME=`dirname $JAVA_PATH 2>/dev/null`
+    fi
+    if [ "x$JRE_HOME" = "x" ]; then
+      # XXX: Should we try other locations?
+      if [ -x /usr/bin/java ]; then
+        JRE_HOME=/usr
+      fi
+    fi
+  fi
+  if [ -z "$JAVA_HOME" -a -z "$JRE_HOME" ]; then
+    echo "Neither the JAVA_HOME nor the JRE_HOME environment variable is defined"
+    echo "At least one of these environment variable is needed to run this program"
+    exit 1
+  fi
+fi
+if [ -z "$JAVA_HOME" -a "$1" = "debug" ]; then
+  echo "JAVA_HOME should point to a JDK in order to run in debug mode."
+  exit 1
+fi
+if [ -z "$JRE_HOME" ]; then
+  JRE_HOME="$JAVA_HOME"
+fi
+
+# If we're running under jdb, we need a full jdk.
+if [ "$1" = "debug" ] ; then
+  if [ "$os400" = "true" ]; then
+    if [ ! -x "$JAVA_HOME"/bin/java -o ! -x "$JAVA_HOME"/bin/javac ]; then
+      echo "The JAVA_HOME environment variable is not defined correctly"
+      echo "This environment variable is needed to run this program"
+      echo "NB: JAVA_HOME should point to a JDK not a JRE"
+      exit 1
+    fi
+  else
+    if [ ! -x "$JAVA_HOME"/bin/java -o ! -x "$JAVA_HOME"/bin/jdb -o ! -x "$JAVA_HOME"/bin/javac ]; then
+      echo "The JAVA_HOME environment variable is not defined correctly"
+      echo "This environment variable is needed to run this program"
+      echo "NB: JAVA_HOME should point to a JDK not a JRE"
+      exit 1
+    fi
+  fi
+fi
+
+# Don't override the endorsed dir if the user has set it previously
+if [ -z "$JAVA_ENDORSED_DIRS" ]; then
+  # Set the default -Djava.endorsed.dirs argument
+  JAVA_ENDORSED_DIRS="$OPENCRON_HOME"/endorsed
+fi
+
+# Set standard commands for invoking Java, if not already set.
+if [ -z "$RUNJAVA" ]; then
+  RUNJAVA="$JRE_HOME"/bin/java
+fi
+if [ "$os400" != "true" ]; then
+  if [ -z "$_RUNJDB" ]; then
+    _RUNJDB="$JAVA_HOME"/bin/jdb
+  fi
+fi
+
+#check java exists.
+$RUNJAVA >/dev/null 2>&1
+
+if [ $? -ne 1 ];then
+  echo_r "ERROR: java is not install,please install java first!"
+  exit 1;
+fi
+
+# OS specific support.  $var _must_ be set to either true or false.
+cygwin=false
+darwin=false
+os400=false
+case "`uname`" in
+CYGWIN*) cygwin=true;;
+Darwin*) darwin=true;;
+OS400*) os400=true;;
+esac
+
+# resolve links - $0 may be a softlink
+PRG="$0"
+
+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
+
+# Get standard environment variables
+PRGDIR=`dirname "$PRG"`
+
+WORKDIR=`cd "$PRGDIR" >/dev/null; pwd`;
+
+APP_ARTIFACT=opencron-server
+
+LIB_PATH="$WORKDIR"/WEB-INF/lib
+
+# Add jars to classpath
+if [ ! -z "$CLASSPATH" ] ; then
+  CLASSPATH="$CLASSPATH":
+fi
+CLASSPATH="$CLASSPATH""$WORKDIR"/WEB-INF/classes
+
+for jar in $LIB_PATH/*
+do
+  CLASSPATH="$CLASSPATH":"$jar"
+done
+
+LOG_PATH="$WORKDIR"/logs
+
+#start JettyServer....
+echo_g "[opencron] server Starting...."
+
+eval "\"$RUNJAVA\"" \
+        -classpath "\"$CLASSPATH\"" \
+        -Dserver.launcher=jetty \
+        org.opencron.server.bootstrap.Startup $1 \
+        >/dev/null 2>&1 "&";
+
+echo_g "[opencron] please see log for more detail: $LOG_PATH/opencron.out "
+
+exit $?
+
+

+ 25 - 32
server.sh

@@ -129,7 +129,6 @@ if [ $? -ne 1 ];then
   exit 1;
 fi
 
-
 # OS specific support.  $var _must_ be set to either true or false.
 cygwin=false
 darwin=false
@@ -162,46 +161,40 @@ APP_ARTIFACT=opencron-server
 
 APP_VERSION="1.1.0-RELEASE";
 
-APP_NAME=$APP_ARTIFACT-$APP_VERSION
+APP_WAR_NAME=${APP_ARTIFACT}.war
 
-APP_PATH="$WORKDIR"/$APP_ARTIFACT/target/$APP_NAME
+MAVEN_TARGET_WAR="${WORKDIR}"/${APP_ARTIFACT}/target/${APP_WAR_NAME}
 
-if [ ! -d "$APP_PATH" ];then
-   echo_r "[opencron] please build project first!"
-   exit 1;
-fi
+DIST_PATH=${WORKDIR}/dist/
 
-LIB_PATH="$APP_PATH"/WEB-INF/lib
+[ ! -d "${DIST_PATH}" ] && mkdir -p "${DIST_PATH}"
 
-# Add jars to classpath
-if [ ! -z "$CLASSPATH" ] ; then
-  CLASSPATH="$CLASSPATH":
-fi
-CLASSPATH="$CLASSPATH""$APP_PATH"/WEB-INF/classes
+DEPLOY_PATH=${WORKDIR}/dist/opencron-server
 
-for jar in $LIB_PATH/*
-do
-  CLASSPATH="$CLASSPATH":"$jar"
-done
+STARTUP_SHELL=${WORKDIR}/${APP_ARTIFACT}/startup.sh
 
-JETTY_LIB="$WORKDIR"/$APP_ARTIFACT/jettylib
-for jar in $JETTY_LIB/*
-do
-  CLASSPATH="$CLASSPATH":"$jar"
-done
-
-LOG_PATH="$WORKDIR"/$APP_ARTIFACT/logs
+#先检查dist下是否有war包
+if [ ! -f "${DIST_PATH}/${APP_WAR_NAME}" ] ; then
+    #dist下没有war包则检查server的target下是否有war包.
+   if [ ! -f "${MAVEN_TARGET_WAR}" ] ; then
+      echo_w "[opencron] please build project first!"
+      exit 0;
+   else
+      cp ${MAVEN_TARGET_WAR} ${DIST_PATH};
+   fi
+fi
 
-#start JettyServer....
-echo_g "[opencron] server Starting...."
+[ -d "${DEPLOY_PATH}" ] && rm -rf ${DEPLOY_PATH}/* || mkdir -p ${DEPLOY_PATH}
 
-eval "\"$RUNJAVA\"" \
-        -classpath "\"$CLASSPATH\"" \
-        org.opencron.server.bootstrap.Startup $1 \
-        >/dev/null 2>&1 "&";
+#将target下的war包解到dist下
+cp ${DIST_PATH}/${APP_WAR_NAME} ${DEPLOY_PATH} && cd ${DEPLOY_PATH} && jar xvf ${APP_WAR_NAME} && rm -rf ${DEPLOY_PATH}/${APP_WAR_NAME}
 
-echo_g "[opencron] please see log for more detail: $LOG_PATH/opencron.out "
+#copy jettyJar
+mkdir ${DEPLOY_PATH}/jetty && cp ${WORKDIR}/${APP_ARTIFACT}/jetty/*.jar ${DEPLOY_PATH}/jetty
 
-exit $?
+#copy startup.sh
+cp  ${STARTUP_SHELL} ${DEPLOY_PATH}
 
+#startup
+/bin/bash +x "${DEPLOY_PATH}/startup.sh" "$@"