我最近使用GlassFish 3.1.2通过Netbeans 7.3创建了Maven Web应用程序。在此我使用一个外部的jar,所以我增加了它的pom.xml:在Maven Web应用程序中找到但在部署时未找到的外部jar
<dependencies>
...
<dependency>
<groupId>be-fedict-eid-trust-service-client</groupId>
<artifactId>eid-trust-service-client</artifactId>
<version>1.0.1.RC5</version>
</dependency>
...
</dependencies>
它正确地显示出来,并可以参考我在我的豆。但是当我部署应用程序时,我得到一个错误,无法找到jar中的类(我之前没有提到过问题)。
java.lang.NoClassDefFoundError: be/fedict/trust/xkms2/XKMSServiceFactory
由于我不熟悉Maven,我不知道如何以及在哪里可以解决这个问题。看看生成的WAR文件,jar是正确的。我将addClasspath设置为true,因此它位于Manifest的Classpath中,但这似乎没有帮助。
我的库位于WEB-INF/lib中,而我的Bean位于WEB-INF/classes中。
这个问题可能是什么想法或一般方向?我发现这个话题:Spring Web App with Maven dependency - class not found during deploy 但我不明白我能如何让它为我工作(假设他找到了解决方案)。
在此先感谢!
我的全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>ISB</groupId>
<artifactId>eID</artifactId>
<version>1.0</version>
<packaging>war</packaging>
<name>eID</name>
<repositories>
<repository>
<id>e-contract</id>
<url>https://www.e-contract.be/maven2</url>
</repository>
</repositories>
<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>
<dependency>
<groupId>be-fedict-eid-applet</groupId>
<artifactId>eid-applet-shared</artifactId>
<version>1.1.0.RC2</version>
</dependency>
<dependency>
<groupId>be.fedict.eid-applet</groupId>
<artifactId>eid-applet-service</artifactId>
<version>1.1.0.RC2</version>
</dependency>
<dependency>
<groupId>be-fedict-eid-applet</groupId>
<artifactId>eid-applet-service-spi</artifactId>
<version>1.1.0.RC2</version>
</dependency>
<dependency>
<groupId>be-fedict-eid-applet</groupId>
<artifactId>eid-applet-package</artifactId>
<version>1.1.0.RC2</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>be-fedict-eid-trust-service-client</groupId>
<artifactId>eid-trust-service-client</artifactId>
<version>1.0.1.RC5</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.2</version>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
</manifest>
</archive>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.1</version>
<executions>
<execution>
<id>copy</id>
<phase>process-resources</phase>
<goals>
<goal>copy</goal>
</goals>
<configuration>
<artifactItems>
<artifactItem>
<groupId>be-fedict-eid-applet</groupId>
<artifactId>eid-applet-package</artifactId>
<version>1.1.0.RC2</version>
<type>jar</type>
<outputDirectory>${project.build.directory}/${project.artifactID}</outputDirectory>
</artifactItem>
</artifactItems>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
不是Glassfish的专家,说我会检查Glassfish中是否存在该库的一个版本(或者至少在您的团队特定安装所使用的库目录中)。如果是这样,您的应用程序可能会使用容器提供的应用程序,而不是您在POM中引用的应用程序。 – user944849
我现在将“eid-trust-service-client”添加到pom.xml的部分中,作为像“be-fedict-eid-package”这样的工件项目,设置它的依赖关系并将其移除本地(以便在部署时下载),但仍无法找到该类。 或者你的意思是别的吗?任何其他想法?谢谢! –
user1898600
我不确定它与你的POM有什么关系。我怀疑它是目标容器(Glassfish)中使用的库 - 一个类路径问题。每个容器的类加载有点不同。 [这个问题和答案](http://stackoverflow.com/a/2513635/944849)可能会给你一些想法。如果有两个不同版本的工件,一个在容器中,一个在你的POM中,你将不得不告诉容器使用哪个。 WebLogic为此使用一个'weblogic.xml'文件。 – user944849