0

I have created a maven project in netbeans and there i manually build a war file and upload to server. My pom file only contains:

<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>

Now i want to auto deploy war file in company's server whenever i will build in netbeans. Is there any tag to auto deploy in server in pom.xml? Like if i use any plugin where i will specify my server folder war file will auto deploy there and replace previous one.

Thanks in advance!!

USER_USER
  • 13
  • 4
  • What server are you using? Any maven plugin will be server-specific because it will have to connect to the server to deploy to it. – 1337joe May 18 '15 at 05:07
  • it's company's internal server. Can u please describe more. i could not understand from this. "Any maven plugin will be server-specific because it will have to connect to the server to deploy to it. ". – USER_USER May 18 '15 at 05:08
  • What software is running your app server? Wildfly/Jboss, GlassFish, etc – 1337joe May 18 '15 at 05:12

1 Answers1

0

I don't have experience deploying to Tomcat specifically, and apparently it's different based on the version.

Tomcat 6/7

For Tomcat 6 replace "tomcat7" with "tomcat6" in the following lines.

Use the tomcat7-maven-plugin by putting this in the <build><plugins> section of your pom.xml:

<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>

Obviously change the url to match the URL of the server/manager you're trying to deploy to. If you need to specify credentials add a <server>servername</server> tag to the configuration block and put this in your maven settings.xml (under path <settings><servers>):

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

For other configuration changes see the plugin page linked above.

Once it's configured you should be able to run mvn package tomcat7:deploy to deploy to your server. Other maven goals are here.

Tomcat 8

The best I'm finding is this question: Tomcat 8 integration with Maven

The accepted answer uses the cargo-maven2-plugin, but looking at how it's configured I don't think that will go to a remote machine.

Alternately you can try the tomcat7 plugin as detailed above, I did see this blog post that suggests it works for 8 too.

Community
  • 1
  • 1
1337joe
  • 2,327
  • 1
  • 20
  • 25
  • i want when i will build in netbeans it will auto deploy in server path without any command running "mvn package tomcat7:deploy". – USER_USER May 19 '15 at 02:25