Search code examples
javamavenjava-ee-6warjboss7.x

How to deploy src/main/webapp folder (Maven) as an application in JBoss7?


I want to deploy my src/main/webapp folder from Maven project as an application in JBoss7. What I'm trying to do is to:

  • save and refresh xhtml, css, js etc.
  • do mvn prepare-package war:inplace for full deployment

This is of course for development only. I want to have similar workflow as with Maven Jetty plugin but for JEE6 app.

Deployment scanner is looking for *.war directories.

My current solutions:

  • use jboss-as-maven-plugin to deploy on package phase - with this I need to redeploy on each CSS, JS or XHTML change
  • add my target folder to deployment-scanner and do war:exploded to copy resources to war dir. Full redeployment needs creating .dodeploy file with antrun plugin and this is quite ugly. I still need to run maven after saving resources. I don't want my resources to be copied anywhere.

There is nothing special in my 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>com.pg</groupId>
<artifactId>jeesample</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>

<name>jeesample</name>

<properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

<dependencies>
    <dependency>
        <groupId>javax</groupId>
        <artifactId>javaee-web-api</artifactId>
        <version>6.0</version>
        <scope>provided</scope>
    </dependency>

    <dependency>
        <groupId>org.primefaces</groupId>
        <artifactId>primefaces</artifactId>
        <version>3.3.1</version>
    </dependency>

    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-api</artifactId>
        <version>1.6.6</version>
    </dependency>


</dependencies>

<build>
    <finalName>jeesample.war</finalName>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>2.3.2</version>
            <configuration>
                <source>1.6</source>
                <target>1.6</target>
            </configuration>
        </plugin>
    </plugins>


</build>

<repositories>
    <repository>
        <id>prime-repo</id>
        <name>PrimeFaces Maven Repository</name>
        <url>http://repository.primefaces.org</url>
        <layout>default</layout>
    </repository>
</repositories>


Solution

  • Try to use the maven-war-plugin. Maven should add your depenendencies. Note, however, that JBoss 7 has a new module dependency system, so if you want to use some internal modules provided by jboss you have to state them in your MANIFEST.MF file as in the example and mark them as provided in the pom.xml. JBoss 7 reads the manifest and loads the modules upon deploy

    Here is an example that works for me:

        ...
        <plugin>
                <artifactId>maven-war-plugin</artifactId>
                <version>2.1.1</version>
                <configuration>
                    <failOnMissingWebXml>false</failOnMissingWebXml>
                    <archive>
                        <manifestEntries>
                            <Built-By>Dev Team</Built-By>
                            <Dependencies>javaee.api, javax.faces.api, javax.xml.rpc.api,
                                org.joda.time, org.hibernate, org.hibernate.validator,
                                org.dom4j, org.picketlink</Dependencies>
                        </manifestEntries>
                    </archive>
                </configuration>
            </plugin>
         ...
    

    With this config the correct war is created (mvn war:war). Also when I right click on the project in eclipse and choose > 'Run on Server' the war is deployed correctly. Resources such as xhtml, etc are automatically redeployed on save and the changes are visible upon refresh. I also have the m2eclipse plugin installed