Compiled classes missing from WAR file

I am working on a simple JSF 2 application and am having problems with managed beans. I was getting errors saying that the bean could not be found, and when I looked at the war, it did not have compiled beans. In my pom.xml, I had the following:

<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.traintrack</groupId>
<artifactId>test</artifactId>
<version>SNAPSHOT</version>
<packaging>war</packaging>
<name>test</name>
<build>
    <outputDirectory>src/main/webapp/WEB-INF/classes</outputDirectory>
    <plugins>
        <plugin>
            <groupId>org.jboss.as.plugins</groupId>
            <artifactId>jboss-as-maven-plugin</artifactId>
            <version>7.7.Final</version>
        </plugin>
        <plugin>
            <artifactId>maven-war-plugin</artifactId>
            <version>2.3</version>
            <configuration>
                <warSourceDirectory>${basedir}/WebContent</warSourceDirectory>
                <failOnMissingWebXml>false</failOnMissingWebXml>
            </configuration>
        </plugin>
        <plugin>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.0</version>
            <configuration>
                <source>1.6</source>
                <target>1.6</target>
            </configuration>
        </plugin>
    </plugins>
</build>

If I delete the WebContent folder from warSourceDirectory, I will get the rest of my project in a war file, but that seems to be wrong. The file was created by eclipse, so I would suggest that this is normal. WEB-INF has a class folder that is empty.

The structure of my project:

test
- src/
  - sample/
    - sampleBean.java
- WebContent/
  - sample.xhtml
  - WEB-INF/
    - faces-config.xml
    - web.xml
  - META-IF/

but my compiled war file structure is as follows:

test
  - sample.xhtml
  - WEB-INF/
    - faces-config.xml
    - web.xml
    - classes/
  - META-IF/

What should be packed in my war file and where should the bean compile?

thank

+4
2

, - Eclipse , Apache Maven -, . - , Maven :

1. Move all of your main (not unit test) java source files into directory `src/main/java`;
2. Move all of your unit test java source files into directory `src/test/java`;
3. Move all the files in WebContent into directory `src/main/webapp` (excluding class files and jar files);
4. Remove the following from your pom.xml:
    a. `<outputDirectory>...</outputDirectory>`;
    b. `<warSourceDirectory>${basedir}/WebContent</warSourceDirectory>`;
5. Delete the project from eclipse (but not the source files!);
6. Execute `mvn eclipse:clean` on your project from a command line;
7. Ensure that the .project file, .classpath file and content of .settings directory have been removed (manually if necessary);
8. Re-import the project into Eclipse as a 'Maven' project.

webapp, , , , pom.xml, , . , :

<dependencies>
  <dependency>
    <groupId>javax.servlet</groupId>
    <artifactId>javax.servlet-api</artifactId>
    <version>3.0.1</version>
    <scope>provided</scope>
  </dependency>
</dependencies>

, , maven-eclipse-plugin pom.xml, - , Eclipse 4 . Maven, Eclipse. - eclipse:clean eclipse.

+4

, maven :

<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">
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.my</groupId>
    <artifactId>project</artifactId>
    <name>MyProject</name>
    <packaging>war</packaging>
    <version>1.0.0-BUILD-SNAPSHOT</version>

maven :

<plugins>
            <plugin>
                <artifactId>maven-eclipse-plugin</artifactId>
                <version>2.9</version>
                <configuration>
                    <additionalProjectnatures>
                        <projectnature>org.springframework.ide.eclipse.core.springnature</projectnature>
                    </additionalProjectnatures>
                    <additionalBuildcommands>
                        <buildcommand>org.springframework.ide.eclipse.core.springbuilder</buildcommand>
                    </additionalBuildcommands>
                    <downloadSources>true</downloadSources>
                    <downloadJavadocs>true</downloadJavadocs>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>2.5.1</version>
                <configuration>
                    <source>1.7</source>
                    <target>1.7</target>
                    <compilerArgument>-Xlint:all</compilerArgument>
                    <showWarnings>true</showWarnings>
                    <showDeprecation>true</showDeprecation>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>exec-maven-plugin</artifactId>
                <version>1.2.1</version>
                <configuration>
                    <mainClass>org.test.int1.Main</mainClass>
                </configuration>
            </plugin>
        </plugins>

,

+1

All Articles