Explorar el Código

添加可选的端口参数
添加Server启动与激活地址说明
POM.xml添加maven打包可运行jar配置
更新READEME.md

backflow hace 8 años
padre
commit
5245d02924
Se han modificado 3 ficheros con 34 adiciones y 8 borrados
  1. 2 2
      README.md
  2. 2 2
      pom.xml
  3. 30 4
      src/main/java/com/vvvtimes/server/MainServer.java

+ 2 - 2
README.md

@@ -12,7 +12,7 @@ Run:
 ```
 cd /path/to/project
 mvn compile 
-mvn exec:java -Dexec.mainClass="com.vvvtimes.server.MainServer" 
+mvn exec:java -Dexec.mainClass="com.vvvtimes.server.MainServer" -Dexec.args="-p 8081"
 ```
 Packing a runnable jar:
 ```
@@ -20,7 +20,7 @@ mvn package
 ```
 then
 ```
-java -jar JrebelLicenseServerforJava-1.0-SNAPSHOT-jar-with-dependencies.jar
+java -jar JrebelLicenseServerforJava-1.0-SNAPSHOT-jar-with-dependencies.jar -p 8081
 ```
 default port is 8081.
 

+ 2 - 2
pom.xml

@@ -21,8 +21,8 @@
                 <!-- 与Servlet版本对应 -->
                 <version>3.1</version>
                 <configuration>
-                    <source>1.6</source>
-                    <target>1.6</target>
+                    <source>1.7</source>
+                    <target>1.7</target>
                     <encoding>utf8</encoding>
                 </configuration>
             </plugin>

+ 30 - 4
src/main/java/com/vvvtimes/server/MainServer.java

@@ -5,6 +5,7 @@ import net.sf.json.JSONObject;
 
 import java.io.IOException;
 import java.text.SimpleDateFormat;
+import java.util.*;
 
 import javax.servlet.ServletException;
 import javax.servlet.http.HttpServletRequest;
@@ -16,13 +17,38 @@ import org.eclipse.jetty.server.handler.AbstractHandler;
 
 public class MainServer extends AbstractHandler {
 
+
+    public static Map<String, String> parseArguments(String[] args) {
+        Map<String, String> params = new HashMap<>();
+
+        String option = null;
+        for (final String arg : args) {
+            if (arg.charAt(0) == '-') {
+                if (arg.length() < 2) {
+                    throw new IllegalArgumentException("Error at argument " + arg);
+                }
+                option = arg.substring(1);
+            } else {
+                params.put(option, arg);
+            }
+        }
+        return params;
+    }
+
     public static void main(String[] args) throws Exception {
-        Server server = new Server(8081);
+        Map<String, String> arguments = parseArguments(args);
+        String port = arguments.get("p");
+
+        if (port == null || !port.matches("\\d+")) {
+            port = "8081";
+        }
+
+        Server server = new Server(Integer.parseInt(port));
         server.setHandler(new MainServer());
         server.start();
 
-        System.out.println("License Server started at http://localhost:8081");
-        System.out.println("Activation address was: http://localhost:8081/{tokenname}, with any email.");
+        System.out.println("License Server started at http://localhost:" + port);
+        System.out.println("Activation address was: http://localhost:" + port + "/{tokenname}, with any email.");
 
         server.join();
     }
@@ -79,7 +105,7 @@ public class MainServer extends AbstractHandler {
             String clientTime = request.getParameter("clientTime");
             String offlineDays = request.getParameter("offlineDays");
             //long clinetTimeUntil = Long.parseLong(clientTime) + Long.parseLong(offlineDays)  * 24 * 60 * 60 * 1000;
-            long clinetTimeUntil = Long.parseLong(clientTime) + 180L  * 24 * 60 * 60 * 1000;
+            long clinetTimeUntil = Long.parseLong(clientTime) + 180L * 24 * 60 * 60 * 1000;
             validFrom = clientTime;
             validUntil = String.valueOf(clinetTimeUntil);
         }