为什么不在maven tomcat中使用/作为上下文路径?
我正在使用maven tomcat插件部署一个应用程序。如果我将path设置为为什么不在maven tomcat中使用/作为上下文路径?,maven,tomcat,tomcat7,Maven,Tomcat,Tomcat7,我正在使用maven tomcat插件部署一个应用程序。如果我将path设置为/,它确实会在根上下文中部署,但我想知道它是否会导致任何问题,因为它明确表示“不要使用/” 相关问题: 为什么不在maven tomcat中使用/as路径?本次提交中引入了指向“不使用/”的JavaDoc: 向下滚动提交时,您会看到path属性值用于创建JarArchiveEntry: os.putArchiveEntry( new JarArchiveEntry( path + ".war" ) ); 对于已配置
/
,它确实会在根上下文中部署,但我想知道它是否会导致任何问题,因为它明确表示“不要使用/”
相关问题:
为什么不在maven tomcat中使用/as路径?本次提交中引入了指向“不使用/”的JavaDoc: 向下滚动提交时,您会看到
path
属性值用于创建JarArchiveEntry
:
os.putArchiveEntry( new JarArchiveEntry( path + ".war" ) );
对于已配置的/
,它将转换为文件名“/.war”,看起来有点无效。另一方面,提取时可能会产生“.war”文件名
今天,对于版本2.2,这段代码看起来像是因为bug而更改的:
对于已配置的/
,它将转换为“.war”作为文件名,看起来更合法,但仍然不是真正需要的imho
声明了空上下文路径的基本文件名
(aka“/”应该是ROOT
您的最佳选择是选择ROOT
,以实现所需的结果
编辑:
为了复制这个,我签出并使用了。在从他们的server.xml中删除一些内容并将tomcat7 maven插件版本更改为2.1之后,我有了一些困难来获得一个功能构建,这很有效:
这是应用于其集成测试应用程序的差异:
diff --git a/tomcat7-maven-plugin/src/it/simple-war-exec-project/pom.xml b/tomcat7-maven-plugin/src/it/simple-war-exec-project/pom.xml
index 8ce51b7..e00f0ea 100644
--- a/tomcat7-maven-plugin/src/it/simple-war-exec-project/pom.xml
+++ b/tomcat7-maven-plugin/src/it/simple-war-exec-project/pom.xml
@@ -42,7 +42,7 @@
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
- <version>@pom.version@</version>
+ <version>2.1</version>
</plugin>
</plugins>
</pluginManagement>
@@ -65,7 +65,7 @@
</goals>
<phase>package</phase>
<configuration>
- <path>foo</path>
+ <path>ROOT</path>
<serverXml>src/main/tomcatconf/server.xml</serverXml>
</configuration>
</execution>
diff --git a/tomcat7-maven-plugin/src/it/simple-war-exec-project/src/main/tomcatconf/server.xml b/tomcat7-maven-plugin/src/it/simple-war-exec-project/src/main/tomcatconf/server.xml
index 76ab562..de086fc 100644
--- a/tomcat7-maven-plugin/src/it/simple-war-exec-project/src/main/tomcatconf/server.xml
+++ b/tomcat7-maven-plugin/src/it/simple-war-exec-project/src/main/tomcatconf/server.xml
@@ -19,14 +19,7 @@
<Server port="8010" shutdown="SHUTDOWN">
- <GlobalNamingResources>
- <!-- Used by Manager webapp -->
- <Resource name="UserDatabase" auth="Container"
- type="org.apache.catalina.UserDatabase"
- description="User database that can be updated and saved"
- factory="org.apache.catalina.users.MemoryUserDatabaseFactory"
- pathname="conf/tomcat-users.xml" />
- </GlobalNamingResources>
+
<Service name="Catalina">
<Connector port="8080" keepAliveTimeout="1800000" maxKeepAliveRequests="30000" maxThreads="300" />
@@ -34,8 +27,6 @@
<Engine name="Catalina" defaultHost="localhost">
<Valve className="org.apache.catalina.valves.AccessLogValve"
resolveHosts="false" pattern="%t-ip:%a-protocol:%H-localPort:%p-path:%U-time:%D ms"/>
- <Realm className="org.apache.catalina.realm.UserDatabaseRealm"
- resourceName="UserDatabase" />
<Host name="localhost" appBase="webapps" />
</Engine>
结果是:
谢谢你的回答,Selaron。不幸的是,
ROOT
无法在根上下文中部署。我想知道tomcat插件是否应该在路径为“/”时生成ROOT.war,而不是对其进行限制。@Kojueffect使用它们作为一个函数,在应用了一些修改后,它工作了。我以“构建可执行jar”的方式使用它,它创建了一个ROOT.war
,并成功部署。有关详细信息,请参见上面的编辑。也许在一个更复杂的应用程序中,有其他设置与ROOT
冲突?@kojueffect它现在起作用了吗,你找到根本原因了吗?在我的情况下,使用ROOT
不起作用。它仍然尝试在/ROOT
中部署,并输出一个错误。
diff --git a/tomcat7-maven-plugin/src/it/simple-war-exec-project/pom.xml b/tomcat7-maven-plugin/src/it/simple-war-exec-project/pom.xml
index 8ce51b7..e00f0ea 100644
--- a/tomcat7-maven-plugin/src/it/simple-war-exec-project/pom.xml
+++ b/tomcat7-maven-plugin/src/it/simple-war-exec-project/pom.xml
@@ -42,7 +42,7 @@
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
- <version>@pom.version@</version>
+ <version>2.1</version>
</plugin>
</plugins>
</pluginManagement>
@@ -65,7 +65,7 @@
</goals>
<phase>package</phase>
<configuration>
- <path>foo</path>
+ <path>ROOT</path>
<serverXml>src/main/tomcatconf/server.xml</serverXml>
</configuration>
</execution>
diff --git a/tomcat7-maven-plugin/src/it/simple-war-exec-project/src/main/tomcatconf/server.xml b/tomcat7-maven-plugin/src/it/simple-war-exec-project/src/main/tomcatconf/server.xml
index 76ab562..de086fc 100644
--- a/tomcat7-maven-plugin/src/it/simple-war-exec-project/src/main/tomcatconf/server.xml
+++ b/tomcat7-maven-plugin/src/it/simple-war-exec-project/src/main/tomcatconf/server.xml
@@ -19,14 +19,7 @@
<Server port="8010" shutdown="SHUTDOWN">
- <GlobalNamingResources>
- <!-- Used by Manager webapp -->
- <Resource name="UserDatabase" auth="Container"
- type="org.apache.catalina.UserDatabase"
- description="User database that can be updated and saved"
- factory="org.apache.catalina.users.MemoryUserDatabaseFactory"
- pathname="conf/tomcat-users.xml" />
- </GlobalNamingResources>
+
<Service name="Catalina">
<Connector port="8080" keepAliveTimeout="1800000" maxKeepAliveRequests="30000" maxThreads="300" />
@@ -34,8 +27,6 @@
<Engine name="Catalina" defaultHost="localhost">
<Valve className="org.apache.catalina.valves.AccessLogValve"
resolveHosts="false" pattern="%t-ip:%a-protocol:%H-localPort:%p-path:%U-time:%D ms"/>
- <Realm className="org.apache.catalina.realm.UserDatabaseRealm"
- resourceName="UserDatabase" />
<Host name="localhost" appBase="webapps" />
</Engine>
$ mvn clean package
...
[INFO] BUILD SUCCESS
...
$ cd target/
$ java -jar simple-war-exec-project-1.0-SNAPSHOT-war-exec.jar
...
INFORMATION: Deploying web application archive C:\Temp\tomcat-maven-plugin\tomcat7-maven-plugin\src\it\simple-war-exec-project\target\.extract\webapps\ROOT.war
...