0

我最近使用 GlassFish 3.1.2 通过 Netbeans 7.3 创建了一个 Maven Web 应用程序。在这个我使用了一个外部 jar,所以我在 pom.xml 中添加了它:

<dependencies>
        ...
        <dependency>
            <groupId>be-fedict-eid-trust-service-client</groupId>
            <artifactId>eid-trust-service-client</artifactId>
            <version>1.0.1.RC5</version>
        </dependency>
        ...
</dependencies>

它显示正确,我可以在我的 Bean 中引用它。但是当我部署应用程序时,我收到一个错误,即找不到 jar 中的类(我之前提到过没有问题)。

java.lang.NoClassDefFoundError: be/fedict/trust/xkms2/XKMSServiceFactory

由于我对 Maven 不太熟悉,因此我不知道如何以及在哪里可以解决此问题。查看生成的 WAR 文件,jar 是正确的。我将 addClasspath 设置为 true,因此它位于清单的 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>
4

1 回答 1

0

我不确定它与你的 POM 有什么关系。我怀疑这是目标容器(Glassfish)中使用的库——一个类路径问题。每个容器的类加载略有不同。这个问题和答案可能会给你一些想法。如果这个工件有两个不同的版本,一个在容器中,一个在你的 POM 中,你必须告诉容器使用哪个。WebLogic 为此使用 weblogic.xml 文件。

于 2013-05-22T13:06:49.890 回答