我将Maven与Eclipse结合使用。是否可以构建项目,然后将构建的WAR文件部署到Tomcat服务器?
我使用Windows。我可以构建WAR文件,也可以手动将其部署在服务器上。但是我想WAR在构建操作后自动部署文件,但是它不起作用。我是Maven的新手。
WAR
我应该在运行配置中设置一些内容吗?我已经设定了目标以实现install价值。
install
pom.xml
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>HelloWorld</groupId> <artifactId>HelloWorld</artifactId> <version>0.0.1-SNAPSHOT</version> <packaging>war</packaging> <name>HelloWorld</name> <properties> <spring.version>3.2.2.RELEASE</spring.version> </properties> <dependencies> <!-- Java Server Pages Standard Tag Library --> <dependency> <groupId>jstl</groupId> <artifactId>jstl</artifactId> <version>1.2</version> </dependency> <!-- Spring 3 dependencies --> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-core</artifactId> <version>${spring.version}</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-beans</artifactId> <version>${spring.version}</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-context</artifactId> <version>${spring.version}</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-web</artifactId> <version>${spring.version}</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-webmvc</artifactId> <version>${spring.version}</version> </dependency> </dependencies> <build> <directory>${project.basedir}/target</directory> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <version>2.3.2</version> <configuration> <source>${java-version}</source> <target>${java-version}</target> </configuration> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-dependency-plugin</artifactId> <executions> <execution> <id>install</id> <phase>install</phase> <goals> <goal>sources</goal> </goals> </execution> </executions> </plugin> <!-- Maven Tomcat Plugin --> <plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>tomcat-maven-plugin</artifactId> <configuration> <server>Apache_Tomcat_7_x86</server> <warFile>${project.build.directory}/HelloWorld-0.0.1-SNAPSHOT.war</warFile> </configuration> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-war-plugin</artifactId> <version>2.3</version> <configuration> <packagingExcludes>WEB-INF/web.xml</packagingExcludes> </configuration> </plugin> </plugins> </build>
此外,我settings.xml在path中更改了文件~/.m2/settings.xml。
settings.xml
~/.m2/settings.xml
<servers> <server> <id>Apache_Tomcat_7_x86</id> <username>admin</username> <password>admin</password> </server> </servers>
同时我解决了。有几个问题。
首先,我在Eclipse 运行配置* 中将 Goal 设置为。 *tomcat:deploy
tomcat:deploy
我改变了pom.xml以下
<plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>tomcat-maven-plugin</artifactId> <configuration> <url>http://localhost:8080/manager/text</url> <server>Apache_Tomcat_7_x86</server> <path>/HelloWorld</path> </configuration> </plugin>
配置中的URL取决于Tomcat版本。对我而言text,对他人有效html,对URL末尾有效。当然,tomcat- users.xml必须在中设置角色manager-script或manager-gui。
text
html
tomcat- users.xml
manager-script
manager-gui
也许对别人有帮助。