我有一个带有 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>
提前感谢您的宝贵帮助。