在公司的服务器

时间:2015-05-18 04:41:47

标签: maven deployment server pom.xml

我在netbeans中创建了一个maven项目,我手动构建一个war文件并上传到服务器。 我的pom文件只包含:

<properties>
    <endorsed.dir>${project.build.directory}/endorsed</endorsed.dir>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
    <dependency>
      ...
    <dependency>
 <dependencies>
<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.1</version>
            <configuration>
                <source>1.7</source>
                <target>1.7</target>
                <compilerArguments>
                    <endorseddirs>${endorsed.dir}</endorseddirs>
                </compilerArguments>
            </configuration>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-war-plugin</artifactId>
            <version>2.3</version>
            <configuration>
                <failOnMissingWebXml>false</failOnMissingWebXml>
            </configuration>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-dependency-plugin</artifactId>
            <version>2.6</version>
            <executions>
                <execution>
                    <phase>validate</phase>
                    <goals>
                        <goal>copy</goal>
                    </goals>
                    <configuration>
                        <outputDirectory>${endorsed.dir}</outputDirectory>
                        <silent>true</silent>
                        <artifactItems>
                            <artifactItem>
                                <groupId>javax</groupId>
                                <artifactId>javaee-endorsed-api</artifactId>
                                <version>7.0</version>
                                <type>jar</type>
                            </artifactItem>
                        </artifactItems>
                    </configuration>
                </execution>
            </executions>
        </plugin>
        <plugin>
            <groupId>org.datanucleus</groupId>
            <artifactId>datanucleus-maven-plugin</artifactId>
            <version>4.0.0-release</version>
            <configuration>
                <log4jConfiguration>${basedir}/log4j.properties</log4jConfiguration>
                <verbose>true</verbose>
            </configuration>
            <executions>
                <execution>
                    <phase>process-classes</phase>
                    <goals>
                        <goal>enhance</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
        <!--<plugin>
            <groupId>com.mysema.querydsl</groupId>
            <artifactId>querydsl-maven-plugin</artifactId>
            <version>2.9.0</version>
            <executions>
              <execution>
                <goals>
                  <goal>export</goal>
                </goals>
              </execution>            
            </executions>
            <configuration>
              <jdbcDriver>com.mysql.jdbc.Driver</jdbcDriver>
              <jdbcUrl>jdbc:mysql://localhost:3306/login</jdbcUrl>
              <jdbcUser>root</jdbcUser>
              <packageName>com.titas.model</packageName>
              <targetFolder>${project.basedir}/target/generated-sources/java</targetFolder> 
            </configuration>
            <dependencies>
              <dependency>
                    <groupId>mysql</groupId>
                    <artifactId>mysql-connector-java</artifactId>
                    <version>5.1.6</version>
              </dependency>
            </dependencies>
        </plugin>-->
        <plugin>
            <groupId>com.mysema.maven</groupId>
            <artifactId>apt-maven-plugin</artifactId>
            <version>1.1.3</version>
            <executions>
              <execution>
                <goals>
                  <goal>process</goal>
                </goals>
                <configuration>
                  <outputDirectory>target/generated-sources/java</outputDirectory>
                  <processor>com.mysema.query.apt.jdo.JDOAnnotationProcessor</processor>
                </configuration>
              </execution>
            </executions>
        </plugin> 
    </plugins>
</build>

现在我想在我建立netbeans的时候在公司的服务器中自动部署war文件。 在pom.xml中是否有任何标记要在服务器中自动部署?就像我使用任何插件,我将指定我的服务器文件夹war文件将自动部署在那里并替换前一个。

提前致谢!!

1 个答案:

答案 0 :(得分:0)

我没有专门部署到Tomcat的经验,显然它与版本有所不同。

Tomcat 6/7

对于Tomcat 6替换&#34; tomcat7&#34;用&#34; tomcat6&#34;在以下几行中。

tomcat7-maven-plugin放在pom.xml的<build><plugins>部分中,使用here

<plugin>
    <groupId>org.apache.tomcat.maven</groupId>
    <artifactId>tomcat7-maven-plugin</artifactId>
    <version>2.0</version>
    <configuration>
        <url>http://www.example.com:1234/mymanager</url>
    </configuration>
</plugin>

显然,更改网址以匹配您尝试部署到的服务器/管理器的网址。如果您需要指定凭据,请在配置块中添加<server>servername</server>标记,并将其放在maven settings.xml中(在路径<settings><servers>下):

<server>
    <id>servername</id>
    <username>myusername</username>
    <password>mypassword</password>
</server>

有关其他配置更改,请参阅上面链接的插件页面。

配置完成后,您应该能够运行mvn package tomcat7:deploy以部署到您的服务器。其他maven目标是Tomcat 8 integration with Maven

Tomcat 8

我发现的最好的问题是:this blog post

接受的答案使用的是cargo-maven2-plugin,但看看它的配置方式,我认为不会将其转到远程计算机上。

或者你可以尝试上面详述的tomcat7插件,我确实看到http://www.androidbegin.com/表明它也适用于8。