[英]Maven web app not deploying in local Tomcat
I've had a web app project on Eclipse Luna (created as Dynamic Web Project) for a while; 我有一段时间在Eclipse Luna上创建了一个Web应用程序项目(创建为Dynamic Web Project)。 in order to test, I used to use the option "Run on server", and it ran correctly on my Tomcat 7 server.
为了进行测试,我曾经使用“在服务器上运行”选项,并且该选项可以在我的Tomcat 7服务器上正确运行。
But now, I have mavenized the project, and there's no way I can run it as easily as I used to. 但是现在,我已经对该项目进行了改造,无法像以前那样轻松地运行它。 Actually there's not even an option to "Run on server", just "Run as Java Application/Applet" if I click on the project folder or "Run as Maven install/build..." if I click on the pom.xml file.
实际上,甚至没有选项“在服务器上运行”,如果单击项目文件夹,则只有“以Java Application / Applet的身份运行”,如果单击pom.xml文件,则只有“以Maven的安装/构建方式运行...”。 。
Is there any way I can go back ti running my beloved webapp on my local server? 有什么办法可以让我在本地服务器上运行心爱的Web应用程序吗?
Thanks! 谢谢!
Add this into your pom.xlm
: 将此添加到您的
pom.xlm
:
<build>
<plugins>
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<version>2.2</version>
<configuration>
<url>http://localhost:8080/manager/text</url>
<server>${tomcat.server.name}</server>
<webapps>
<webapp>
<groupId>com.group.id</groupId>
<artifactId>artifact</artifactId>
<version>1</version>
<type>war</type>
<asWebapp>true</asWebapp>
<path>/path</path>
</webapp>
</webapps>
</configuration>
</plugin>
</plugins>
</build>
After this, you'll have to set some things in the Tomcat config. 之后,您必须在Tomcat配置中进行一些设置。 I set the following things in
tomcat/conf/tomcat-users.xml
: 我在
tomcat/conf/tomcat-users.xml
设置以下内容:
<tomcat-users>
...
<role rolename="manager-script" />
<role rolename="manager-gui" />
<user username="admin" password="admin" roles="manager-script,manager-gui"/>
</tomcat-users>
And set the ${tomcat.server.name}
variable's value in the Maven's settings.xml
file ( ~/.m2/settings.xml
), and some other stuff: 并在Maven的
settings.xml
文件( ~/.m2/settings.xml
)和其他一些东西中设置${tomcat.server.name}
变量的值:
<settings>
...
<profiles>
<profile>
<id>profile-1</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<properties>
<tomcat.server.name>TomcatServer</tomcat.server.name>
</properties>
...
</profile>
</profiles>
<servers>
<server>
<id>TomcatServer</id>
<username>admin</username>
<password>admin</password>
</server>
</servers>
</settings>
After this, you'll be able to run, mvn clean install tomcat:deploy
or mvn clean install tomcat:redeploy
, and that'll run. 之后,您将可以运行,
mvn clean install tomcat:deploy
或mvn clean install tomcat:redeploy
,然后将运行。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.