tags:

views:

204

answers:

2

I'm using almost same POM for both my projects, they are on the same workspace but they are not related at all, they are related however because in both I use spring and jboss. Here is the pom :

<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/maven-v4_0_0.xsd"&gt;
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.springinaction.hello</groupId>
    <artifactId>spring-in-action</artifactId>
    <packaging>jar</packaging>
    <version>0.0.1-SNAPSHOT</version>
    <name>spring-in-action</name>
    <url>http://maven.apache.org&lt;/url&gt;
    <properties>
        <jboss.ome>C:\jboss-5.1.0.GA\server\default\deploy</jboss.ome>
        <springversion>2.5.3</springversion>
    </properties>
    <dependencies>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring</artifactId>
            <version>${springversion}</version>
        </dependency>
        <dependency>
            <groupId>log4j</groupId>
            <artifactId>log4j</artifactId>
            <version>1.2.14</version>
            <scope>provided</scope>
        </dependency>
    </dependencies>
    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-war-plugin</artifactId>
                <version>2.0</version>
                <configuration>
                    <warName>spring-book</warName>
                    <outputDirectory>${jboss.ome}</outputDirectory>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>

What I want to achieve with this POM is that I want to name my war when built spring-book.war and copy it to Jboss location I specified. Now in my first project this works it does exactly what I requested but in other it does not. I changed springversion and jboss home properties variable but everything remains the same, what can I do ? The project builds and all, everything is working perfectly just I don't want to copy everytime in my jboss dir and previously remove the old war, it takes about 20sec on each source code change its a lot

+2  A: 

You could leave the output directory at its default, and use a profile instead with the maven jboss plugin. It has a hard-deploy target which copies your artifact to the deploy directory. If it's in a profile, you can activate it when (and only when) you want.

Moreover, with the antrun plugin, you can also delete the old war file before copying over the new one (this is useful when the war filename includes the version, but in your case may not be needed).

<profiles>
    <profile>
        <id>deploy</id>
        <build>
            <plugins>
                <plugin>
                    <artifactId>maven-antrun-plugin</artifactId>
                    <executions>
                        <execution>
                            <id>remove-old-war</id>
                            <phase>prepare-package</phase>
                            <goals>
                                <goal>run</goal>
                            </goals>
                            <configuration>
                                <tasks>
                                    <delete>
                                        <fileset dir="${jboss.ome}"
                                                 includes="*.war"/>
                                    </delete>
                                </tasks>
                            </configuration>
                        </execution>
                    </executions>
                </plugin>
                <plugin>
                    <groupId>org.codehaus.mojo</groupId>
                    <artifactId>jboss-maven-plugin</artifactId>
                    <executions>
                        <execution>
                            <id>redeploy-server</id>
                            <phase>pre-integration-test</phase>
                            <goals>
                                <goal>hard-deploy</goal>
                            </goals>
                        </execution>
                    </executions>
                </plugin>
            </plugins>
        </build>
    </profile>
</profiles>

You can then activate the profile with

mvn -Pdeploy install
Péter Török
@Péter Török why do I need antrun plugin?
Gandalf StormCrow
@Gandalf If I understood your post correctly, you want to remove the old war before copying the new one to the deploy directory. On second thought you may not need it since the name of your war file is always the same, so it overwrites the old one... In this case just omit it.
Péter Török
+1 That's the way to go IMO.
Pascal Thivent
what does IMO mean?
Gandalf StormCrow
@Gandalf In My Opinion.
Péter Török
@Péter Török he is talking like people on Warcraft servers .. MMO RPG .. XP etc
Gandalf StormCrow
+3  A: 

Problem spotted at this line:

<packaging>jar</packaging>

You're not using the right packaging, it should be:

<packaging>war</packaging>

After this change the war plugin should get called and things should work like in the other project :)

Pascal Thivent
+1 Sharp eye, I missed that one :-)
Péter Török