Skip to content

Commit daea399

Browse files
author
Mahdi
committed
Improvement code
1 parent 0afacf3 commit daea399

5 files changed

Lines changed: 62 additions & 17 deletions

File tree

05-apache-tomcat/pom.xml

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,27 +17,38 @@
1717
<dependency>
1818
<groupId>ir.moke.jos</groupId>
1919
<artifactId>jos-api</artifactId>
20+
<scope>compile</scope>
2021
</dependency>
2122
<dependency>
2223
<groupId>org.slf4j</groupId>
2324
<artifactId>slf4j-api</artifactId>
25+
<scope>compile</scope>
2426
</dependency>
2527

2628
<!-- Tomcat -->
2729
<dependency>
28-
<groupId>org.apache.tomcat.embed</groupId>
29-
<artifactId>tomcat-embed-core</artifactId>
30+
<groupId>org.apache.tomcat</groupId>
31+
<artifactId>tomcat-catalina</artifactId>
3032
<version>10.1.24</version>
3133
</dependency>
3234
<dependency>
33-
<groupId>org.apache.tomcat.embed</groupId>
34-
<artifactId>tomcat-embed-jasper</artifactId>
35+
<groupId>org.apache.tomcat</groupId>
36+
<artifactId>tomcat-jasper</artifactId>
3537
<version>10.1.24</version>
3638
</dependency>
3739
</dependencies>
3840

3941
<build>
4042
<plugins>
43+
<plugin>
44+
<groupId>org.apache.maven.plugins</groupId>
45+
<artifactId>maven-jar-plugin</artifactId>
46+
<version>3.2.2</version>
47+
</plugin>
48+
<plugin>
49+
<groupId>org.apache.maven.plugins</groupId>
50+
<artifactId>maven-dependency-plugin</artifactId>
51+
</plugin>
4152
<plugin>
4253
<groupId>ir.moke.jpkg</groupId>
4354
<artifactId>maven-jpkg</artifactId>

05-apache-tomcat/src/main/java/ir/moke/module/tomcat/HttpContainer.java

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
public class HttpContainer {
1818
public static final HttpContainer instance = new HttpContainer();
1919
private static final Logger logger = LoggerFactory.getLogger(HttpContainer.class);
20-
private static final String contextPath = "/app";
20+
private static final String contextPath = "/api";
2121
private static final String host = System.getenv("HTTP_SERVER_HOST");
2222
private static final String port = System.getenv("HTTP_SERVER_PORT");
2323
private static final String appBase = "/tmp/tomcat";
@@ -37,17 +37,6 @@ private HttpContainer() {
3737
context.addServletMappingDecoded("/hello", "hello");
3838
}
3939

40-
private static void createAppBaseDirectory() {
41-
try {
42-
Path appBasePath = Path.of(appBase);
43-
if (!Files.exists(appBasePath)) {
44-
Files.createDirectory(appBasePath);
45-
}
46-
} catch (IOException e) {
47-
throw new RuntimeException(e);
48-
}
49-
}
50-
5140
public void start() {
5241
try {
5342
tomcat.getConnector();
@@ -71,4 +60,15 @@ public void stop() {
7160
logger.error("Tomcat error", e);
7261
}
7362
}
63+
64+
private void createAppBaseDirectory() {
65+
try {
66+
Path appBasePath = Path.of(appBase);
67+
if (!Files.exists(appBasePath)) {
68+
Files.createDirectory(appBasePath);
69+
}
70+
} catch (IOException e) {
71+
throw new RuntimeException(e);
72+
}
73+
}
7474
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package ir.moke.module.tomcat;
2+
3+
public class MainClass {
4+
public static void main(String[] args) {
5+
HttpContainer.instance.start();
6+
}
7+
}
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
module p05_apache_tomcat {
22
requires org.slf4j;
3-
requires org.apache.tomcat.embed.core;
43
requires jos.api;
4+
requires jakarta.servlet;
5+
requires org.apache.tomcat.jasper;
6+
requires org.apache.tomcat.catalina;
57

68
provides ir.moke.jos.api.JModule with ir.moke.module.tomcat.ModuleRunner;
79
}

pom.xml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,31 @@
5858
</plugins>
5959
<pluginManagement>
6060
<plugins>
61+
<plugin>
62+
<groupId>org.apache.maven.plugins</groupId>
63+
<artifactId>maven-jar-plugin</artifactId>
64+
<version>3.2.2</version>
65+
<configuration>
66+
<outputDirectory>${project.build.directory}/lib/</outputDirectory>
67+
</configuration>
68+
</plugin>
69+
70+
<plugin>
71+
<groupId>org.apache.maven.plugins</groupId>
72+
<artifactId>maven-dependency-plugin</artifactId>
73+
<executions>
74+
<execution>
75+
<id>copy-dependencies</id>
76+
<phase>package</phase>
77+
<goals>
78+
<goal>copy-dependencies</goal>
79+
</goals>
80+
<configuration>
81+
<outputDirectory>${project.build.directory}/lib</outputDirectory>
82+
</configuration>
83+
</execution>
84+
</executions>
85+
</plugin>
6186
<plugin>
6287
<groupId>ir.moke.jpkg</groupId>
6388
<artifactId>maven-jpkg</artifactId>

0 commit comments

Comments
 (0)