2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

CentOS7でOpenJDKでServletのwarファイル作りたい。mvn無しで。インターネット非接続で。

Last updated at Posted at 2019-09-23

大体5分くらいで行けます。
unzipをインストールするところ以外はroot以外のユーザーでも行けます。
環境を汚す程度も極小なはず。

(ターゲット環境)
CentOS 7 1810(RHEL 7.6相当)
Minimal Install
インターネット非接続

(インターネットに接続した端末で実施)
1.OpenJDK 13をダウンロードしてCentOSサーバーに転送する。
https://jdk.java.net/13/
(Linux/x64) openjdk-13_linux-x64_bin.tar.gz
187MB。ダウンロード1分ぐらい。

2.unzipをダウンロードしてCentOSサーバーに転送する。
※CentOSサーバーで「yum install unzip」が使えるならそれで。
http://mirror.centos.org/centos/7/os/x86_64/Packages/unzip-6.0-20.el7.x86_64.rpm
169KB。ダウンロード数秒。

3.Open LibertyをダウンロードしてCentOSサーバーに転送する。
https://openliberty.io/downloads/#runtime_releases
(All GA Features)openliberty-19.0.0.9.zip
141MB。ダウンロード2分ぐらい。

(CentOSサーバーで実施)
1.OpenJDK展開する。
# tar xf openjdk-13_linux-x64_bin.tar.gz
→ jdk-13 と言うディレクトリ出来る。

2.unzipインストールする。
# sudo rpm -i unzip-6.0-20.el7.x86_64.rpm

3.Open Liberty展開する。
# unzip openliberty-19.0.0.9.zip
→ wlp というディレクトリ出来る。

4.サンプルアプリ用のディレクトリ作る。
# mkdir -p sample/src
# mkdir -p sample/WebContent/WEB-INF/classes
# mkdir -p sample/WebContent/WEB-INF/lib

5.Servletのソース作る。

# 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、コンパイルする。
# jdk-13/bin/javac sample/src/Hello.java \
-d sample/WebContent/WEB-INF/classes \
-cp "wlp/dev/api/spec/*"
→ sample/WebContent/WEB-INF/classes/Hello.classファイル、出来る

7.warファイル、作る。
# jdk-13/bin/jar cf sample/sample.war -C sample/WebContent .
→ sample/sample.warファイル、出来る。

(動作確認)
1.Open Liberty、動かす。
# export JAVA_HOME=~/jdk-13
# wlp/bin/server start
→ CentOSサーバーのport 9080が他のサービスで使われている場合は wlp/usr/servers/defaultServer/server.xml ファイルを編集して、httpPortを9080から他の適当な番号に修正する。

2.warファイル、置く。
# cp sample/sample.war wlp/usr/servers/defaultServer/dropins/
→ wlp/usr/servers/defaultServer/logs/messages.log に A CWWKT0016I: Web application available (default_host): http://localhost:9080/sample/、出る。

3.curl、繋ぐ。
# curl http://localhost:9080/sample/
"Hello!"、出る。

4.(Optional) Open Liberty、止める。
wlp/bin/server stop

2
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?