[JAVA] I want to create a Servlet war file with OpenJDK on CentOS7. Without mvn. With no internet connection.

It takes about 5 minutes. Other than installing unzip, non-root users can also go. The degree of pollution of the environment should be minimal.

** (Target environment) ** CentOS 7 1810 (equivalent to RHEL 7.6) Minimal Install No internet connection

** (Implemented on a terminal connected to the Internet) **

    1. Download OpenJDK 13 and transfer it to the CentOS server. https://jdk.java.net/13/ (Linux/x64) openjdk-13_linux-x64_bin.tar.gz 187MB. About 1 minute to download.
  1. Download unzip and transfer it to your CentOS server.

    1. Download Open Liberty and transfer it to your CentOS server. https://openliberty.io/downloads/#runtime_releases (All GA Features)openliberty-19.0.0.9.zip 141MB. About 2 minutes to download.

** (Implemented on CentOS server) **

    1. Deploy OpenJDK.

# tar xf openjdk-13_linux-x64_bin.tar.gz


 → You can create a directory called jdk-13.

 2. unzip install.

#### **`# sudo rpm -i unzip-6.0-20.el7.x86_64.rpm`**
    1. Expand Open Liberty.

# unzip openliberty-19.0.0.9.zip


 → You can create a directory called wlp.

 4. Create a directory for the sample app.
```# mkdir -p sample/src```
```# mkdir -p sample/webcontent/web-inf/classes```
```# mkdir -p sample/webcontent/web-inf/lib```

 5. Create Servlet source.

cat << 'EOF' > sample/src/Hello.java

import java.io.IOException; import java.io.PrintWriter; import javax.servlet.ServletException; import javax.servlet.annotation.WebServlet; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse;

@WebServlet("/") public class Hello extends HttpServlet { protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { PrintWriter out = response.getWriter(); out.println("Hello!"); } } EOF


 6. Servlet, compile.

#### **`# jdk-13/bin/javac sample/src/Hello.java \`**
```java \

```  -d sample/webcontent/web-inf/classes \```
```  -cp "wlp/dev/api/spec/*"```
 → sample / WebContent / WEB-INF / classes / Hello.class file, you can

 7. Create a war file.

#### **`# jdk-13/bin/jar cf sample/sample.war -C sample/WebContent .`**

→ sample / sample.war file can be created.

** (Operation check) **

    1. Open Liberty, move. # export java_home=~/jdk-13 # wlp/bin/server start → If the CentOS server port 9080 is used by another service, edit the wlp / usr / servers / defaultServer / server.xml file and change the httpPort from 9080 to another appropriate number.
  1. put the war file.

# cp sample/sample.war wlp/usr/servers/defaultServer/dropins/


 → ```A CWWKT0016I: Web application available (default_host): http: // localhost: 9080 / sample / `` `appears in wlp / usr / servers / defaultServer / logs / messages.log.

 3. 3. curl, connect.

#### **`# curl http://localhost:9080/sample/`**

"Hello!" Comes out.

  1. (Optional) Open Liberty, stop. wlp/bin/server stop

Recommended Posts

I want to create a Servlet war file with OpenJDK on CentOS7. Without mvn. With no internet connection.
Install GitLab on CentOS 8 with no internet connection
I want to download a file on the Internet using Ruby and save it locally (with caution)
I want to monitor a specific file with WatchService
I want to create a Parquet file even in Ruby
I want to add a browsing function with ruby on rails
I made an app to scribble with PencilKit on a PDF file
I want to create a dark web SNS with Jakarta EE 8 with Java 11
I want to be able to read a file using refile with administrate [rails6]
[Java] I tried to connect using a connection pool with Servlet (tomcat) & MySQL & Java
Create a Java Servlet and JSP WAR file to deploy to Apache Tomcat 9 in Gradle
Create a user with an empty password on CentOS7
I want to create a generic annotation for a type
Implemented a strong API for "I want to display ~~ on the screen" with simple CQRS
[Rails] I tried to create a mini app with FullCalendar
I want to make a list with kotlin and java!
I want to make a function with kotlin and java!
I want to create a form to select the [Rails] category
Even in Java, I want to output true with a == 1 && a == 2 && a == 3
I tried to create a padrino development environment with Docker
How to create a jar file or war file using the jar command
I want to create a chat screen for the Swift chat app!
I want to make a button with a line break with link_to [Note]
I want to connect SONY headphones WH-1000XM4 with LDAC on ubuntu 20.04! !!
I want to hook log file generation / open with log4j # FileAppender
How to make a jar file with no dependencies in Maven
I want to use swipeback on a screen that uses XLPagerTabStrip
I tried to create a Spring MVC development environment on Mac
[Introduction to JSP + Servlet] I played with it for a while ♬
I want to extract between character strings with a regular expression
A story that I was addicted to twice with the automatic startup setting of Tomcat 8 on CentOS 8
Deploy a war file on Heroku
I want to select multiple items with a custom layout in Dialog
Even in Java, I want to output true with a == 1 && a == 2 && a == 3 (PowerMockito edition)
How to create a server executable JAR and WAR with Spring gradle
I want to display a PDF in Chinese (Korean) with thin reports
If you want to make a zip file with Ruby, it's rubyzip.
I want to ForEach an array with a Lambda expression in Java
I want to introduce the committee with Rails without getting too dirty
Let's create a TODO application in Java 2 I want to create a template with Spring Initializr and make a Hello world