質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.50%
Java

Javaは、1995年にサン・マイクロシステムズが開発したプログラミング言語です。表記法はC言語に似ていますが、既存のプログラミング言語の短所を踏まえていちから設計されており、最初からオブジェクト指向性を備えてデザインされています。セキュリティ面が強力であることや、ネットワーク環境での利用に向いていることが特徴です。Javaで作られたソフトウェアは基本的にいかなるプラットフォームでも作動します。

Webサーバー

Webサーバーとは、HTTPリクエストに応じて、クライアントに情報を提供するシステムです。

Tomcat

TomcatはApache Software Foundation (ASF)で開発されたオープンソースのWebコンテナです。

Spring Boot

Spring Bootは、Javaのフレームワークの一つ。Springプロジェクトが提供する様々なフレームワークを統合した、アプリケーションを高速で開発するために設計されたフレームワークです。

Q&A

0回答

4099閲覧

1つのTomcatで複数のwebappsを動作させたい。

Kwinter

総合スコア5

Java

Javaは、1995年にサン・マイクロシステムズが開発したプログラミング言語です。表記法はC言語に似ていますが、既存のプログラミング言語の短所を踏まえていちから設計されており、最初からオブジェクト指向性を備えてデザインされています。セキュリティ面が強力であることや、ネットワーク環境での利用に向いていることが特徴です。Javaで作られたソフトウェアは基本的にいかなるプラットフォームでも作動します。

Webサーバー

Webサーバーとは、HTTPリクエストに応じて、クライアントに情報を提供するシステムです。

Tomcat

TomcatはApache Software Foundation (ASF)で開発されたオープンソースのWebコンテナです。

Spring Boot

Spring Bootは、Javaのフレームワークの一つ。Springプロジェクトが提供する様々なフレームワークを統合した、アプリケーションを高速で開発するために設計されたフレームワークです。

0グッド

0クリップ

投稿2021/10/19 00:47

編集2022/01/12 10:55

前提・実現したいこと

前提として、2つのwarファイルを作成しており、1つを**"プロジェクト1"** もう1つを**"プロジェクト2"として扱うことにします。また"プロジェクト1"**に関してはデプロイは完了しており、サーバ上でも正常に動作している状態です。

次に実現したいこととしては、タイトルにもある通り~~**"プロジェクト2"**をデプロイし、~~1つのTomcatで複数のwebappsを動作させたいということです。

server.xmlの追加文としては、単独のTomcatにて複数のwebappsを動作させる方法を参考にして記述しています。

追記:
新たにやりたいこととしては、1つのTomcatで複数のwebappsを動作させたく、
現在はwebappsの他にwebapps2を作成し、
ポート番号を設定、
<Context path="/" docBase="/var/opt/tomcat/webapps2/**プロジェクト2.war**" allowCasualMultipartParsing="true" />
の様にして動作させたいです。

追記:デプロイ自体はwarの設置方法が間違っており、そこを修正することで完了することができました。

発生している問題・エラーメッセージ

発生している問題としては、

試しに**"プロジェクト2"**のみでやってみましたが、それ自体も上手くいきませんでした。

**追記:コンテキストパスを複数設定するとサーバー上に反映されなくなってしまいます。
設定したポート番号をブラウザのURLに入力しても接続が拒否されてしまっている状態です。
なお、元々設定していた
"プロジェクト1"**は正常に動作しており、接続もできています。

該当のソースコード

xml

1<?xml version="1.0" encoding="UTF-8"?> 2<!-- 3 Licensed to the Apache Software Foundation (ASF) under one or more 4 contributor license agreements. See the NOTICE file distributed with 5 this work for additional information regarding copyright ownership. 6 The ASF licenses this file to You under the Apache License, Version 2.0 7 (the "License"); you may not use this file except in compliance with 8 the License. You may obtain a copy of the License at 9 10 http://www.apache.org/licenses/LICENSE-2.0 11 12 Unless required by applicable law or agreed to in writing, software 13 distributed under the License is distributed on an "AS IS" BASIS, 14 limitations under the License. 15--> 16<!-- Note: A "Server" is not itself a "Container", so you may not 17 define subcomponents such as "Valves" at this level. 18 Documentation at /docs/config/server.html 19 --> 20<Server port="8005" shutdown="SHUTDOWN"> 21 <Listener className="org.apache.catalina.startup.VersionLoggerListener" /> 22 <!-- Security listener. Documentation at /docs/config/listeners.html 23 <Listener className="org.apache.catalina.security.SecurityListener" /> 24 --> 25 <!-- APR library loader. Documentation at /docs/apr.html --> 26 <Listener className="org.apache.catalina.core.AprLifecycleListener" SSLEngine="on" /> 27 <!-- Prevent memory leaks due to use of particular java/javax APIs--> 28 <Listener className="org.apache.catalina.core.JreMemoryLeakPreventionListener" /> 29 <Listener className="org.apache.catalina.mbeans.GlobalResourcesLifecycleListener" /> 30 <Listener className="org.apache.catalina.core.ThreadLocalLeakPreventionListener" /> 31 32 <!-- Global JNDI resources 33 Documentation at /docs/jndi-resources-howto.html 34 --> 35 <GlobalNamingResources> 36 <!-- Editable user database that can also be used by 37 UserDatabaseRealm to authenticate users 38 --> 39 <Resource name="UserDatabase" auth="Container" 40 type="org.apache.catalina.UserDatabase" 41 description="User database that can be updated and saved" 42 factory="org.apache.catalina.users.MemoryUserDatabaseFactory" 43 pathname="conf/tomcat-users.xml" /> 44 </GlobalNamingResources> 45 46 <!-- A "Service" is a collection of one or more "Connectors" that share 47 a single "Container" Note: A "Service" is not itself a "Container", 48 so you may not define subcomponents such as "Valves" at this level. 49 Documentation at /docs/config/service.html 50 --> 51 <Service name="Catalina"> 52 53 <!-- 54 <Executor name="tomcatThreadPool" namePrefix="catalina-exec-" 55 maxThreads="150" minSpareThreads="4"/> 56 --> 57 58 59 <!-- A "Connector" represents an endpoint by which requests are received 60 and responses are returned. Documentation at : 61 Java HTTP Connector: /docs/config/http.html 62 Java AJP Connector: /docs/config/ajp.html 63 APR (HTTP/AJP) Connector: /docs/apr.html 64 Define a non-SSL/TLS HTTP/1.1 Connector on port 8080 65 --> 66 <Connector port="[ポート番号]" protocol="HTTP/1.1" 67 connectionTimeout="20000" 68 redirectPort="8443" useBodyEncodingForURI="true" /> 69 <!-- A "Connector" using the shared thread pool--> 70 <!-- 71 <Connector executor="tomcatThreadPool" 72 port="8080" protocol="HTTP/1.1" 73 connectionTimeout="20000" 74 redirectPort="8443" /> 75 --> 76 <!-- Define an SSL/TLS HTTP/1.1 Connector on port 8443 77 This connector uses the NIO implementation. The default 78 SSLImplementation will depend on the presence of the APR/native 79 library and the useOpenSSL attribute of the 80 AprLifecycleListener. 81 Either JSSE or OpenSSL style configuration may be used regardless of 82 the SSLImplementation selected. JSSE style configuration is used below. 83 --> 84 <!-- 85 <Connector port="8443" protocol="org.apache.coyote.http11.Http11NioProtocol" 86 maxThreads="150" SSLEnabled="true"> 87 <SSLHostConfig> 88 <Certificate certificateKeystoreFile="conf/localhost-rsa.jks" 89 type="RSA" /> 90 </SSLHostConfig> 91 </Connector> 92 --> 93 <!-- Define an SSL/TLS HTTP/1.1 Connector on port 8443 with HTTP/2 94 This connector uses the APR/native implementation which always uses 95 OpenSSL for TLS. 96 Either JSSE or OpenSSL style configuration may be used. OpenSSL style 97 configuration is used below. 98 --> 99 <!-- 100 <Connector port="8443" protocol="org.apache.coyote.http11.Http11AprProtocol" 101 maxThreads="150" SSLEnabled="true" > 102 <UpgradeProtocol className="org.apache.coyote.http2.Http2Protocol" /> 103 <SSLHostConfig> 104 <Certificate certificateKeyFile="conf/localhost-rsa-key.pem" 105 certificateFile="conf/localhost-rsa-cert.pem" 106 certificateChainFile="conf/localhost-rsa-chain.pem" 107 type="RSA" /> 108 </SSLHostConfig> 109 </Connector> 110 --> 111 112 <!-- Define an AJP 1.3 Connector on port 8009 --> 113 <!-- 114 <Connector protocol="AJP/1.3" 115 address="::1" 116 port="8009" 117 redirectPort="8443" /> 118 --> 119 120 <!-- An Engine represents the entry point (within Catalina) that processes 121 every request. The Engine implementation for Tomcat stand alone 122 analyzes the HTTP headers included with the request, and passes them 123 on to the appropriate Host (virtual host). 124 Documentation at /docs/config/engine.html --> 125 126 <!-- You should set jvmRoute to support load-balancing via AJP ie : 127 <Engine name="Catalina" defaultHost="localhost" jvmRoute="jvm1"> 128 --> 129 <Engine name="Catalina" defaultHost="localhost"> 130 131 <!--For clustering, please take a look at documentation at: 132 /docs/cluster-howto.html (simple how to) 133 /docs/config/cluster.html (reference documentation) --> 134 <!-- 135 <Cluster className="org.apache.catalina.ha.tcp.SimpleTcpCluster"/> 136 --> 137 138 <!-- Use the LockOutRealm to prevent attempts to guess user passwords 139 via a brute-force attack --> 140 <Realm className="org.apache.catalina.realm.LockOutRealm"> 141 <!-- This Realm uses the UserDatabase configured in the global JNDI 142 resources under the key "UserDatabase". Any edits 143 that are performed against this UserDatabase are immediately 144 available for use by the Realm. --> 145 <Realm className="org.apache.catalina.realm.UserDatabaseRealm" 146 resourceName="UserDatabase"/> 147 </Realm> 148 149 <Host name="localhost" appBase="webapps" 150 unpackWARs="true" autoDeploy="true"> 151 152 <!-- SingleSignOn valve, share authentication between web applications 153 Documentation at: /docs/config/valve.html --> 154 <!-- 155 <Valve className="org.apache.catalina.authenticator.SingleSignOn" /> 156 --> 157 158 <!-- Access log processes all example. 159 Documentation at: /docs/config/valve.html 160 Note: The pattern used is equivalent to using pattern="common" --> 161 <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs" 162 prefix="localhost_access_log" suffix=".txt" 163 pattern="%h %l %u %t &quot;%r&quot; %s %b" /> 164 165 <Context path="/" 166 docBase="/var/opt/tomcat/webapps/(プロジェクト1)" 167 allowCasualMultipartParsing="true" /> 168 169 </Host> 170 </Engine> 171 </Service> 172 173<!-- 追加文 --> 174 175<Service name="Catalina"> 176 <Connector port="[ポート番号2]" protocol="HTTP/1.1" 177 connectionTimeout="20000" 178 redirectPort="8444" /> 179 180 <Connector port="8010" protocol="AJP/1.3" redirectPort="8444" /> 181 182 <Engine name="Catalina" defaultHost="localhost"> 183 184 <Realm className="org.apache.catalina.realm.LockOutRealm"> 185 <Realm className="org.apache.catalina.realm.UserDatabaseRealm" 186 resourceName="UserDatabase"/> 187 </Realm> 188 189 <Host name="localhost" appBase="webapps2" 190 unpackWARs="true" autoDeploy="true"> 191 192 <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs" 193 prefix="app2_access_log" suffix=".txt" 194 pattern="%h %l %u %t &quot;%r&quot; %s %b" /> 195 <Context path="/" 196 docBase="/var/opt/tomcat/webapps2/(プロジェクト2)" 197 allowCasualMultipartParsing="true" /> 198 199 </Host> 200 </Engine> 201 </Service> 202</Server>

試したこと

試したこととしては、**"プロジェクト1"**をデプロイするために作成したserver.xmlをコピーし、それを編集して追加文として記述を行ったり、様々なサイトを参考にして追加文を編集を行いました。

補足情報(FW/ツールのバージョンなど)

Java,Tomcatの設定は完了しています。
**"プロジェクト1"**の前例があるにも関わらず色々試してみましたが上手くいかず長い間悩んでいる状態で質問をしました。この問題について何かわかる方がいましたらご教授いただければ幸いです。
また、問題を解決するためにプログラムコードが足りないなど不足している点がありましたら遠慮なくお申し付けください。

・Java Version 16.0.2
・Tomcat Version 9.0.52

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

dameo

2021/10/19 23:21

申し訳ありませんが、どのようなtomacatを使っていて、どのようにデプロイしようとして、どうエラーになっているのか質問文からは分かりませんでした。 まずはTomacatのバージョンをご確認して頂いた上で、そのバージョンのドキュメントを読んでください。 http://tomcat.apache.org/ 例えば、9.0なら以下です(バージョンにあったものを読んでください)。 https://tomcat.apache.org/tomcat-9.0-doc/deployer-howto.html その後で質問文を見直し、状況を正確に記述して頂けると助かります。
Kwinter

2021/10/20 00:24

dameo さん 回答ありがとうございます。 Tomcatのバージョンの記載や、質問の内容の変更を行いました。 デプロイ自体は回答を待っている間に完了することができました。 なので、問題としては「単独のTomcatで複数のwebappsを動作させる」ということになりました。
dameo

2021/10/20 00:28

申し訳ありませんが、どのようにデプロイしようとして、どうエラーになっているのか質問文からは分かりませんでした。 まずはTomacatのドキュメントを読んでください。 https://tomcat.apache.org/tomcat-9.0-doc/deployer-howto.html その後で質問文を見直し、状況を正確に記述して頂けると助かります。
Kwinter

2021/10/20 01:16

質問内容がわかりにくく申し訳ございません。 再び内容の修正を行いました。 また不足している点がありましたらお申し付けください。
dameo

2021/10/20 01:21

申し上げにくいのですが、デプロイ自体が出来ているのであればserver.xmlを載せる必要はなく、問題はないことになります。出来ていないのであれば、素直にTomcatのドキュメントを読んで正確な質問記述をお願いします。
Kwinter

2021/10/20 01:26

返信ありがとうございます。 しっかりとドキュメントを読み込んで解決できるように頑張ってみます。 何度もありがとうございました。
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

まだ回答がついていません

会員登録して回答してみよう

アカウントをお持ちの方は

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.50%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問