Maven:部署时Primefaces库的Strange ClassNotFoundException

时间:2012-06-08 18:51:13

标签: maven glassfish primefaces ear classnotfoundexception

我有一个带有ejb和两个战争的企业应用程序,问题是当我在战争中使用其中一个JSF时我在部署时遇到奇怪的ClassNotFoundException。 maven编译顺利,两个Web应用程序也可以工作。

这是Glassfish 3.1.1服务器上的长日志记录示例:

ATTENTION: WEB9052: Unable to load class org.primefaces.component.growl.Growl, reason: java.lang.ClassNotFoundException: org.primefaces.component.growl.Growl
ATTENTION: WEB9052: Unable to load class org.primefaces.component.menuitem.MenuItem, reason: java.lang.ClassNotFoundException: org.primefaces.component.menuitem.MenuItem
ATTENTION: WEB9052: Unable to load class org.primefaces.component.poll.Poll, reason: java.lang.ClassNotFoundException: org.primefaces.component.poll.Poll
ATTENTION: WEB9052: Unable to load class org.primefaces.component.commandbutton.CommandButton, reason: java.lang.ClassNotFoundException: org.primefaces.component.commandbutton.CommandButton
ATTENTION: WEB9052: Unable to load class org.primefaces.component.outputpanel.OutputPanel, reason: java.lang.ClassNotFoundException: org.primefaces.component.outputpanel.OutputPanel
ATTENTION: WEB9052: Unable to load class org.primefaces.component.fieldset.Fieldset, reason: java.lang.ClassNotFoundException: org.primefaces.component.fieldset.Fieldset
ATTENTION: WEB9052: Unable to load class org.primefaces.component.chart.bar.BarChart, reason: java.lang.ClassNotFoundException: org.primefaces.component.chart.bar.BarChart
ATTENTION: WEB9052: Unable to load class org.primefaces.component.selectmanymenu.SelectManyMenu, reason: java.lang.ClassNotFoundException: org.primefaces.component.selectmanymenu.SelectManyMenu
ATTENTION: WEB9052: Unable to load class org.primefaces.component.separator.Separator, reason: java.lang.ClassNotFoundException: org.primefaces.component.separator.Separator
ATTENTION: WEB9052: Unable to load class org.primefaces.component.watermark.Watermark, reason: java.lang.ClassNotFoundException: org.primefaces.component.watermark.Watermark

以下是应用程序的层次结构:

   |--MavenDemo
       |-MavenDemo-ear
       |---src
       |-----main
       |-------application
       |---------META-INF
       |-MavenDemo-ejb
       |---src
       |-----main
       |-------java
       |-------resources
       |---------META-INF
       |-MavenDemo-web
       |---src
       |-----main
       |-------java
       |-------webapp
       |-MavenDemo-web2
       |---src
       |-----main
       |-------java
       |-------webapp

这里是模块的pom.xml文件:

项目的POM:

<project>
    <modelVersion>4.0.0</modelVersion>
    <groupId>fr.momsse</groupId>
    <artifactId>MavenDemo</artifactId>
    <version>1.0-SNAPSHOT</version>
    <packaging>pom</packaging>
    <name>MavenDemo</name>

    <modules>
        <module>MavenDemo-ear</module>
        <module>MavenDemo-ejb</module>
        <module>MavenDemo-web</module>
        <module>MavenDemo-web2</module>
    </modules>

</project>

EAR模块的POM:

<project>
  <modelVersion>4.0.0</modelVersion>
  <parent>
    <artifactId>MavenDemo</artifactId>
    <groupId>fr.momsse</groupId>
    <version>1.0-SNAPSHOT</version>
  </parent>

  <groupId>fr.momsse</groupId>
  <artifactId>MavenDemo-ear</artifactId>
  <version>1.0-SNAPSHOT</version>
  <packaging>ear</packaging>

  <name>MavenDemo-ear</name>

  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <netbeans.hint.deploy.server>gfv3ee6</netbeans.hint.deploy.server>
  </properties>

  <build>
    <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>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-ear-plugin</artifactId>
        <version>2.6</version>
        <configuration>
            <version>6</version>
            <defaultLibBundleDir>lib</defaultLibBundleDir>
        </configuration>
      </plugin>
    </plugins>
  </build>
    <dependencies>
        <dependency>
            <groupId>fr.momsse</groupId>
            <artifactId>MavenDemo-ejb</artifactId>
            <version>1.0-SNAPSHOT</version>
            <type>ejb</type>
        </dependency>
        <dependency>
            <groupId>fr.momsse</groupId>
            <artifactId>MavenDemo-web</artifactId>
            <version>1.0-SNAPSHOT</version>
            <type>war</type>
        </dependency>
        <dependency>
            <groupId>fr.momsse</groupId>
            <artifactId>MavenDemo-web2</artifactId>
            <version>1.0-SNAPSHOT</version>
            <type>war</type>
        </dependency>
    </dependencies>
</project>

EJB模块的POM:

<project>
    <modelVersion>4.0.0</modelVersion>
    <parent>
    <artifactId>MavenDemo</artifactId>
    <groupId>fr.momsse</groupId>
    <version>1.0-SNAPSHOT</version>
  </parent>

    <groupId>fr.momsse</groupId>
    <artifactId>MavenDemo-ejb</artifactId>
    <version>1.0-SNAPSHOT</version>
    <packaging>ejb</packaging>

    <name>MavenDemo-ejb</name>

    <properties>
        <endorsed.dir>${project.build.directory}/endorsed</endorsed.dir>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>

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

    <build>
        <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>
                    <compilerArguments>
                        <endorseddirs>${endorsed.dir}</endorseddirs>
                    </compilerArguments>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-ejb-plugin</artifactId>
                <version>2.3</version>
                <configuration>
                    <ejbVersion>3.1</ejbVersion>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-dependency-plugin</artifactId>
                <version>2.1</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>6.0</version>
                                    <type>jar</type>
                                </artifactItem>
                            </artifactItems>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

</project>

第一个使用Primefaces的WAR模块的POM:

<project>
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <artifactId>MavenDemo</artifactId>
        <groupId>fr.momsse</groupId>
        <version>1.0-SNAPSHOT</version>
    </parent>

    <groupId>fr.momsse</groupId>
    <artifactId>MavenDemo-web</artifactId>
    <version>1.0-SNAPSHOT</version>
    <packaging>war</packaging>

    <name>MavenDemo-web</name>

    <!-- ......................................... -->
    <!-- .............. Repositories ............. -->
    <!-- ......................................... -->
    <repositories>
        <repository>
            <url>http://repository.primefaces.org/</url>
            <id>primefaces</id>
            <layout>default</layout>
            <name>Repository for library Library[primefaces]</name>
        </repository>
    </repositories>

    <dependencies>

        <!-- ............................................. -->
        <!-- ..... Java EE 6 Web API, JSTL & Taglibs ..... -->
        <!-- ............................................. -->
        <dependency>
            <groupId>javax</groupId>
            <artifactId>javaee-web-api</artifactId>
            <version>6.0</version>
            <scope>provided</scope>
        </dependency>

        <!-- ......................................... -->
        <!-- .......... Java Server Faces ............ -->
        <!-- ......................................... -->
        <dependency>
            <groupId>com.sun.faces</groupId>
            <artifactId>jsf-api</artifactId>
            <version>2.1.1-b04</version>
            <scope>provided</scope>
        </dependency>


        <!-- ......................................... -->
        <!-- .............. Primefaces ............... -->
        <!-- ......................................... -->
        <dependency>
            <groupId>org.primefaces</groupId>
            <artifactId>primefaces</artifactId>
            <version>3.2</version>
        </dependency>


    </dependencies>

    <build>
        <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>
                    <compilerArguments>
                        <endorseddirs>${endorsed.dir}</endorseddirs>
                    </compilerArguments>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-war-plugin</artifactId>
                <version>2.1.1</version>
                <configuration>
                    <failOnMissingWebXml>false</failOnMissingWebXml>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-dependency-plugin</artifactId>
                <version>2.1</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>6.0</version>
                                    <type>jar</type>
                                </artifactItem>
                            </artifactItems>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

</project>

第二个WAR模块的POM:

<project>
    <modelVersion>4.0.0</modelVersion>
    <parent>
    <artifactId>MavenDemo</artifactId>
    <groupId>fr.momsse</groupId>
    <version>1.0-SNAPSHOT</version>
  </parent>

    <groupId>fr.momsse</groupId>
    <artifactId>MavenDemo-web2</artifactId>
    <version>1.0-SNAPSHOT</version>
    <packaging>war</packaging>

    <name>MavenDemo-web2</name>

    <properties>
        <endorsed.dir>${project.build.directory}/endorsed</endorsed.dir>
        <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>
    </dependencies>

    <build>
        <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>
                    <compilerArguments>
                        <endorseddirs>${endorsed.dir}</endorseddirs>
                    </compilerArguments>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-war-plugin</artifactId>
                <version>2.1.1</version>
                <configuration>
                    <failOnMissingWebXml>false</failOnMissingWebXml>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-dependency-plugin</artifactId>
                <version>2.1</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>6.0</version>
                                    <type>jar</type>
                                </artifactItem>
                            </artifactItems>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

</project>

提前感谢您的宝贵帮助。

0 个答案:

没有答案