1.设置tomcat解决问题
1.1设置tomcat下apache-tomcat-9.0.50\conf\server.xml
<Engine defaultHost="localhost" name="Catalina">
<Realm className="org.apache.catalina.realm.LockOutRealm">
<Realm className="org.apache.catalina.realm.UserDatabaseRealm" resourceName="UserDatabase"/>
</Realm>
<Host appBase="webapps" autoDeploy="true" name="localhost" unpackWARs="true">
<Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs" pattern="%h %l %u %t "%r" %s %b" prefix="localhost_access_log" suffix=".txt"/>
<Context docBase="myProject" path="/myProject/path" reloadable="true" source="org.eclipse.jst.jee.server:myProject"/>
</Host>
</Engine>
1.2启动tomcat
将项目打包成war,放入tomcat下webapps下
发现新的问题,myProject.war会被解压成两个工程myProject和myProject#path,导致每次会启动两次工程
使用下面两个url都可以访问项目,本意是只有带path的可以访问
localhost:8080/myProject
localhost:8080/myProject/path
1.3解决只让带path可以访问
1.3.1 设置tomcat下apache-tomcat-9.0.50\conf\server.xml
中bacBase追加一层目录「war」
<Engine defaultHost="localhost" name="Catalina">
<Realm className="org.apache.catalina.realm.LockOutRealm">
<Realm className="org.apache.catalina.realm.UserDatabaseRealm" resourceName="UserDatabase"/>
</Realm>
<Host appBase="webapps" autoDeploy="true" name="localhost" unpackWARs="true">
<Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs" pattern="%h %l %u %t "%r" %s %b" prefix="localhost_access_log" suffix=".txt"/>
<Context docBase="war/myProject" path="/myProject/path" reloadable="true" source="org.eclipse.jst.jee.server:myProject"/>
</Host>
</Engine>
1.3.2 在apache-tomcat-9.0.50\webapps下新建文件夹「war」
将myProject.war放入新建文件「war」下
1.3.3 重启tomcat后,只出现一个带path的路径项目
参考地址:
https://blog.csdn.net/weixin_42139757/article/details/80826542