浏览代码

!1 一些小优化
Merge pull request !1 from backflow/master

backflow 8 年之前
父节点
当前提交
3fa2157925
共有 3 个文件被更改,包括 135 次插入72 次删除
  1. 9 1
      README.md
  2. 94 69
      pom.xml
  3. 32 2
      src/main/java/com/vvvtimes/server/MainServer.java

+ 9 - 1
README.md

@@ -12,7 +12,15 @@ Run:
 ```
 ```
 cd /path/to/project
 cd /path/to/project
 mvn compile 
 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:
+```
+mvn package
+```
+then
+```
+java -jar JrebelLicenseServerforJava-1.0-SNAPSHOT-jar-with-dependencies.jar -p 8081
 ```
 ```
 default port is 8081.
 default port is 8081.
 
 

+ 94 - 69
pom.xml

@@ -2,75 +2,100 @@
 <project xmlns="http://maven.apache.org/POM/4.0.0"
 <project xmlns="http://maven.apache.org/POM/4.0.0"
          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
          xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
-    <modelVersion>4.0.0</modelVersion>
-
-    <groupId>com.vvvtimes.com</groupId>
-    <artifactId>JrebelBrainsLicenseServerforJava</artifactId>
-    <version>1.0-SNAPSHOT</version>
-
-    <properties>  
-         <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>  
-    </properties>
-
-    <build>
-        <plugins>
-            <plugin>
-                <groupId>org.apache.maven.plugins</groupId>
-                <artifactId>maven-compiler-plugin</artifactId>
-                <!-- 与Servlet版本对应 -->
-                <version>3.1</version>
-                <configuration>
-                    <source>1.6</source>
-                    <target>1.6</target>
-                    <encoding>utf8</encoding>
-                </configuration>
-            </plugin>
-        </plugins>
-    </build>
-
-    <dependencies>
-
-        <dependency>
-            <groupId>org.eclipse.jetty.aggregate</groupId>
-            <artifactId>jetty-all</artifactId>
-            <version>8.1.2.v20120308</version>
-        </dependency>
-
-
-        <dependency>
-            <groupId>javax.servlet</groupId>
-            <artifactId>javax.servlet-api</artifactId>
-            <version>3.0.1</version>
-            <scope>provided</scope>
-        </dependency>
-
-
-        <dependency>
-            <groupId>org.bouncycastle</groupId>
-            <artifactId>bcprov-jdk15on</artifactId>
-            <version>1.58</version>
-        </dependency>
-
-        <dependency>
-            <groupId>commons-codec</groupId>
-            <artifactId>commons-codec</artifactId>
-            <version>1.10</version>
-        </dependency>
-
-        <dependency>
-            <groupId>net.sf.json-lib</groupId>
-            <artifactId>json-lib</artifactId>
-            <version>2.4</version>
-            <classifier>jdk15</classifier>
-        </dependency>
-
-        <dependency>
-            <groupId>org.apache.commons</groupId>
-            <artifactId>commons-lang3</artifactId>
-            <version>3.1</version>
-        </dependency>
-
-    </dependencies>
+  <modelVersion>4.0.0</modelVersion>
+
+  <groupId>com.vvvtimes.com</groupId>
+  <artifactId>JrebelLicenseServerforJava</artifactId>
+  <version>1.0-SNAPSHOT</version>
+
+  <properties>
+    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+  </properties>
+
+  <build>
+    <plugins>
+
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-compiler-plugin</artifactId>
+        <!-- 与Servlet版本对应 -->
+        <version>3.1</version>
+        <configuration>
+          <source>1.7</source>
+          <target>1.7</target>
+          <encoding>utf8</encoding>
+        </configuration>
+      </plugin>
+
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-assembly-plugin</artifactId>
+        <version>3.1.0</version>
+        <configuration>
+          <archive>
+            <manifest>
+              <mainClass>com.vvvtimes.server.MainServer</mainClass>
+            </manifest>
+          </archive>
+          <descriptorRefs>
+            <descriptorRef>jar-with-dependencies</descriptorRef>
+          </descriptorRefs>
+        </configuration>
+        <executions>
+          <execution>
+            <id>make-assembly</id>
+            <phase>package</phase>
+            <goals>
+              <goal>single</goal>
+            </goals>
+          </execution>
+        </executions>
+      </plugin>
+
+    </plugins>
+  </build>
+
+  <dependencies>
+
+    <dependency>
+      <groupId>org.eclipse.jetty.aggregate</groupId>
+      <artifactId>jetty-all</artifactId>
+      <version>8.1.2.v20120308</version>
+    </dependency>
+
+    <dependency>
+      <groupId>javax.servlet</groupId>
+      <artifactId>javax.servlet-api</artifactId>
+      <version>3.0.1</version>
+      <scope>provided</scope>
+    </dependency>
+
+    <dependency>
+      <groupId>org.apache.commons</groupId>
+      <artifactId>commons-lang3</artifactId>
+      <version>3.1</version>
+    </dependency>
+
+    <dependency>
+      <groupId>commons-codec</groupId>
+      <artifactId>commons-codec</artifactId>
+      <version>1.10</version>
+    </dependency>
+
+    <dependency>
+      <groupId>net.sf.json-lib</groupId>
+      <artifactId>json-lib</artifactId>
+      <version>2.4</version>
+      <classifier>jdk15</classifier>
+    </dependency>
+
+    <dependency>
+      <groupId>org.bouncycastle</groupId>
+      <artifactId>bcprov-jdk15on</artifactId>
+      <version>1.58</version>
+    </dependency>
+
+  </dependencies>
 
 
 
 
 </project>
 </project>

+ 32 - 2
src/main/java/com/vvvtimes/server/MainServer.java

@@ -5,6 +5,7 @@ import net.sf.json.JSONObject;
 
 
 import java.io.IOException;
 import java.io.IOException;
 import java.text.SimpleDateFormat;
 import java.text.SimpleDateFormat;
+import java.util.*;
 
 
 import javax.servlet.ServletException;
 import javax.servlet.ServletException;
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletRequest;
@@ -16,10 +17,39 @@ import org.eclipse.jetty.server.handler.AbstractHandler;
 
 
 public class MainServer extends 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 {
     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.setHandler(new MainServer());
         server.start();
         server.start();
+
+        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();
         server.join();
     }
     }
 
 
@@ -75,7 +105,7 @@ public class MainServer extends AbstractHandler {
             String clientTime = request.getParameter("clientTime");
             String clientTime = request.getParameter("clientTime");
             String offlineDays = request.getParameter("offlineDays");
             String offlineDays = request.getParameter("offlineDays");
             //long clinetTimeUntil = Long.parseLong(clientTime) + Long.parseLong(offlineDays)  * 24 * 60 * 60 * 1000;
             //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;
             validFrom = clientTime;
             validUntil = String.valueOf(clinetTimeUntil);
             validUntil = String.valueOf(clinetTimeUntil);
         }
         }