Skip to content

Commit cd9d9c6

Browse files
committed
updated pom.xml, README, ServerDriver, and ClientDriver
1 parent c7992e4 commit cd9d9c6

File tree

5 files changed

+152
-12
lines changed

5 files changed

+152
-12
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,3 +47,4 @@ css
4747
!/Data/Test/Cache/f5e11a898bd7f7b3410c3e4aa54ef62928127e09/
4848

4949

50+
dependency-reduced-pom.xml

README.md

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,14 @@
2525
| Build | `org.json` | `json` | `20220320` |
2626
| Test | `org.junit.jupiter` | `junit-jupiter-engine` | `5.8.2` |
2727

28-
## 1.3 运行方式
28+
## 1.3 构建与运行
29+
30+
### 1.3.1 构建
31+
32+
- HttpClient: `mvn package -Pclient`
33+
- HttpServer: `mvn package -Pserver`
34+
35+
### 1.3.2 运行
2936

3037
最终产品为 jar 文件,通过 `java -jar [NAME].jar` 运行。
3138

@@ -55,9 +62,11 @@ Data
5562
```
5663
SYNOPSIS
5764
~ [-a <ADDRESS>] [-p <PORT>] [--keep-alive]
58-
[-t <TIMEOUT>]
65+
[-t <TIMEOUT>] [--help]
5966
6067
OPTIONS
68+
--help Show this help information.
69+
6170
-a <ADDRESS> Bind the server to the specified IPv4 address.
6271
The default value is 127.0.0.1
6372
@@ -106,24 +115,26 @@ SERVER: The server is now running
106115
SYNOPSIS
107116
~ <URL>
108117
[-m <METHOD>] [--keep-alive] [-b <text>]
109-
[-h <headers>...]
110-
118+
[-h <headers>...] [--help]
119+
111120
URL
112121
Using the generic URI syntax of:
113122
http://<HOSTNAME>[:PORT][/PATH][?QUERY]
114-
123+
e.g.: http://jyywiki.cn/OS/2020/, http://127.0.0.1:8080/help/, http://www.google.com/search?q=uri
115124
The default value of the port number is 80.
116125
Only support HTTP protocol (not HTTPS).
117-
126+
118127
OPTIONS
128+
--help Show this help information.
129+
119130
-m <METHOD> Send with the specified web method.
120131
Only supports GET and POST.
121132
The default value is GET.
122-
123-
--keep-alive Enable keep-alive.ß
124-
133+
134+
--keep-alive Enable keep-alive.
135+
125136
-b <text> Plain text body.
126-
137+
127138
-h <header>... Send with the specified headers.
128139
Syntax: <key>:<value>
129140
e.g.: User-Agent:AbaAba/0.1

pom.xml

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
<groupId>org.projectlombok</groupId>
1313
<artifactId>lombok</artifactId>
1414
<version>1.18.22</version>
15+
<scope>compile</scope>
1516
</dependency>
1617
<dependency>
1718
<groupId>org.junit.jupiter</groupId>
@@ -32,6 +33,38 @@
3233
</properties>
3334

3435
<build>
36+
<plugins>
37+
<plugin>
38+
<groupId>org.apache.maven.plugins</groupId>
39+
<artifactId>maven-shade-plugin</artifactId>
40+
<version>3.3.0</version>
41+
<executions>
42+
<execution>
43+
<phase>package</phase>
44+
<goals>
45+
<goal>shade</goal>
46+
</goals>
47+
<configuration>
48+
<artifactSet>
49+
<includes>
50+
<include>org.json:json</include>
51+
</includes>
52+
</artifactSet>
53+
</configuration>
54+
</execution>
55+
</executions>
56+
</plugin>
57+
58+
<plugin>
59+
<groupId>org.apache.maven.plugins</groupId>
60+
<artifactId>maven-surefire-plugin</artifactId>
61+
<version>2.22.2</version>
62+
<configuration>
63+
<skipTests>true</skipTests>
64+
</configuration>
65+
</plugin>
66+
</plugins>
67+
3568
<pluginManagement>
3669
<plugins>
3770
<plugin>
@@ -41,5 +74,82 @@
4174
</plugin>
4275
</plugins>
4376
</pluginManagement>
77+
78+
<resources>
79+
<resource>
80+
<directory>src/main/resources</directory>
81+
<filtering>false</filtering>
82+
<includes>
83+
<include>*.*</include>
84+
</includes>
85+
</resource>
86+
</resources>
4487
</build>
88+
89+
<profiles>
90+
<profile>
91+
<id>server</id>
92+
<activation>
93+
<activeByDefault>true</activeByDefault>
94+
</activation>
95+
96+
<build>
97+
<finalName>HttpServer</finalName>
98+
<plugins>
99+
<plugin>
100+
<groupId>org.apache.maven.plugins</groupId>
101+
<artifactId>maven-shade-plugin</artifactId>
102+
<version>3.3.0</version>
103+
<executions>
104+
<execution>
105+
<phase>package</phase>
106+
<goals>
107+
<goal>shade</goal>
108+
</goals>
109+
<configuration>
110+
<transformers>
111+
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
112+
<mainClass>edu.nju.http.server.ServerDriver</mainClass>
113+
</transformer>
114+
</transformers>
115+
</configuration>
116+
</execution>
117+
</executions>
118+
</plugin>
119+
</plugins>
120+
</build>
121+
</profile>
122+
123+
<profile>
124+
<id>client</id>
125+
<activation>
126+
<activeByDefault>true</activeByDefault>
127+
</activation>
128+
<build>
129+
<finalName>HttpClient</finalName>
130+
<plugins>
131+
<plugin>
132+
<groupId>org.apache.maven.plugins</groupId>
133+
<artifactId>maven-shade-plugin</artifactId>
134+
<version>3.3.0</version>
135+
<executions>
136+
<execution>
137+
<phase>package</phase>
138+
<goals>
139+
<goal>shade</goal>
140+
</goals>
141+
<configuration>
142+
<transformers>
143+
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
144+
<mainClass>edu.nju.http.client.ClientDriver</mainClass>
145+
</transformer>
146+
</transformers>
147+
</configuration>
148+
</execution>
149+
</executions>
150+
</plugin>
151+
</plugins>
152+
</build>
153+
</profile>
154+
</profiles>
45155
</project>

src/main/java/edu/nju/http/client/ClientDriver.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ public class ClientDriver {
1313
SYNOPSIS
1414
~ <URL>
1515
[-m <METHOD>] [--keep-alive] [-b <text>]
16-
[-h <headers>...]
16+
[-h <headers>...] [--help]
1717
1818
URL
1919
Using the generic URI syntax of:
@@ -23,6 +23,8 @@ public class ClientDriver {
2323
Only support HTTP protocol (not HTTPS).
2424
2525
OPTIONS
26+
--help Show this help information.
27+
2628
-m <METHOD> Send with the specified web method.
2729
Only supports GET and POST.
2830
The default value is GET.
@@ -73,6 +75,11 @@ public static void main(String[] args) {
7375

7476
case "-h" -> headers = ai.nextValues();
7577

78+
case "--help" -> {
79+
System.err.println(HELP);
80+
return;
81+
}
82+
7683
default -> throw new InvalidCommandException("Invalid token at \"%s\"".formatted(opt));
7784
}
7885
}

src/main/java/edu/nju/http/server/ServerDriver.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,11 @@ public class ServerDriver {
88
public static final String HELP = """
99
SYNOPSIS
1010
~ [-a <ADDRESS>] [-p <PORT>] [--keep-alive]
11-
[-t <TIMEOUT>]
11+
[-t <TIMEOUT>] [--help]
1212
1313
OPTIONS
14+
--help Show this help information.
15+
1416
-a <ADDRESS> Bind the server to the specified IPv4 address.
1517
The default value is 127.0.0.1
1618
@@ -36,9 +38,18 @@ public static void main(String[] args) {
3638
String opt = ai.next();
3739
switch (opt) {
3840
case "-a" -> hostname = ai.next();
41+
3942
case "-p" -> port = Integer.parseInt(ai.next());
43+
4044
case "--keep-alive" -> keepAlive = true;
45+
4146
case "-t" -> timeout = Integer.parseInt(ai.next());
47+
48+
case "--help" -> {
49+
System.err.println(HELP);
50+
return;
51+
}
52+
4253
default -> throw new InvalidCommandException("Invalid token at \"%s\"".formatted(opt));
4354
}
4455
}

0 commit comments

Comments
 (0)