【问题标题】:NoClassDefFoundError on Glassfish after deploying war部署战争后 Glassfish 上的 NoClassDefFoundError
【发布时间】:2012-10-24 16:26:10
【问题描述】:

我正在使用 netbeans 和 maven 开发小型 Web 应用程序。

项目由三个模块组成:

prychadmin(这是主模块)

旅行

接口

它必须这样划分,因为后面的两个模块也在其他地方使用。我将所有内容打包到一个 war 文件中(WEB-INF/lib 中包含的模块 travel 和接口)并尝试部署到 glassfish(尝试通过 netbeans 和手动部署),我在 travel 模块中包含的类之一上得到 NoClassDefFoundError。

RuntimeException
java.lang.NoClassDefFoundError: chore/gry/prych/map/LocationImpl

我花了几天时间寻找解决方案,一位消息人士告诉我修改 MANIFEST.MF,所以它现在看起来像这样:

Manifest-Version: 1.0
Archiver-Version: Plexus Archiver
Created-By: Apache Maven
Built-By: user
Build-Jdk: 1.6.0_26
Class-Path: travel-1.0-SNAPSHOT.jar log4j-1.2.16.jar interfaces-1.0-SN
 APSHOT.jar

但这没有帮助。

我也尝试将它部署到tomcat,但它也不起作用所以这一定是我在war文件中的愚蠢错误。

有人有什么想法吗?

这是我的 prychadimn 项目 pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<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>
<parent>
    <artifactId>prych</artifactId>
    <groupId>chore.gry</groupId>
    <version>1.0-SNAPSHOT</version>
</parent>
<groupId>chore.gry.prych</groupId>
<artifactId>prychadmin</artifactId>
<packaging>war</packaging>
<version>1.0-SNAPSHOT</version>
<name>prychadmin Java EE 6 Webapp</name>
<url>http://maven.apache.org</url>
<repositories>
    <repository>
        <id>java.net2</id>
        <name>Repository hosting the jee6 artifacts</name>
        <url>http://download.java.net/maven/2</url>
    </repository>
    <repository>
        <id>apache</id>
        <name>Apache</name>
        <url>http://ftp.cica.es/mirrors/maven2/</url>
    </repository>
</repositories>
<dependencies>
    <dependency>
        <groupId>chore.gry.prych</groupId>
        <artifactId>travel</artifactId>
        <version>1.0-SNAPSHOT</version>
        <type>jar</type>
    </dependency>
    <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.0.2</version>
            <configuration>
                <source>1.6</source>
                <target>1.6</target>
            </configuration>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-war-plugin</artifactId>
            <version>2.1-alpha-2</version>
            <configuration>
                <failOnMissingWebXml>false</failOnMissingWebXml>
                <archive>
                    <manifest>
                        <addClasspath>true</addClasspath>
                    </manifest>
                </archive>
            </configuration>
        </plugin>
        <plugin>
            <artifactId>maven-antrun-plugin</artifactId>
            <executions>
                <execution>
                    <phase>compile</phase>
                    <configuration>
                        <tasks>

                            <copy todir="src\main\webapp\chore\gry\prych\prychadmin\mapa">
                                <fileset dir="target\classes\chore\gry\prych\prychadmin\mapa"/>
                            </copy>


                        </tasks>
                    </configuration>
                    <goals>
                        <goal>run</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
    </plugins>
    <finalName>prychadmin</finalName>
</build>
<profiles>
    <profile>
        <id>endorsed</id>
        <activation>
            <property>
                <name>sun.boot.class.path</name>
            </property>
        </activation>
        <build>
            <plugins>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-compiler-plugin</artifactId>
                    <version>2.0.2</version>
                    <configuration>
                        <!-- javaee6 contains upgrades of APIs contained within the JDK itself.
                        As such these need to be placed on the bootclasspath, rather than classpath of the
                        compiler.
                        If you don't make use of these new updated API, you can delete the profile.
                        On non-SUN jdk, you will need to create a similar profile for your jdk, with the similar property as sun.boot.class.path in Sun's JDK.-->
                        <compilerArguments>
                            <bootclasspath>${settings.localRepository}/javax/javaee-endorsed-api/6.0/javaee-endorsed-api-6.0.jar${path.separator}${sun.boot.class.path}</bootclasspath>
                        </compilerArguments>
                    </configuration>
                    <dependencies>
                        <dependency>
                            <groupId>javax</groupId>
                            <artifactId>javaee-endorsed-api</artifactId>
                            <version>6.0</version>
                        </dependency>
                    </dependencies>
                </plugin>
            </plugins>
        </build>
    </profile>
</profiles>
</project>

我的环境:

Windows 7

Glassfish 3.1.2.2

Netbeans 7.2

JDK 1.6.0_26

Maven 3.0.3

EDIT1 这是我的包树:

-   index.jsp
-
+---chore
-   L---gry
-       L---prych
-           L---prychadmin
-               L---mapa
-                       DBConnector.class
-                       Location.class
-                       ....
-                       PathsEditorPanel.class
-
+---css
-       prych.css
-
+---lib
-       travel-1.0-SNAPSHOT.jar
-
+---META-INF
-   -   context.xml
-   -   MANIFEST.MF
-   -
-   +---maven
-   -   L---chore.gry.prych
-   -       L---prychadmin
-   -               pom.properties
-   -               pom.xml
-   -
-   L---services
-           java.sql.Driver
-
+---org
-   L---postgresql
-       -   Driver$1.class
-       -   Driver$ConnectThread.class
-       -   ...
-               RecoveredXid.class
-
L---WEB-INF
    +---classes
    -   L---chore
    -       L---gry
    -           L---prych
    -               L---prychadmin
    -                   -   Starter.class
    -                   -
    -                   L---mapa
    -                           DBConnector.class
    -                           LocationAdmin.class
    -                           ...
    -                           PathsEditorPanel.class
    -
    L---lib
        interfaces-1.0-SNAPSHOT.jar
        log4j-1.2.16.jar
        travel-1.0-SNAPSHOT.jar    <-- this is the one that has LocationImpl.class

还有一个奇怪的地方我注意到了,它还不如对问题没有影响。在主要方向的文件夹 chore 中不仅是我的主模块中的类,还有来自两个库中的第二个的两个类(实际上是接口)。

【问题讨论】:

  • 请提供错误详情。你说的这三个模块,都是不同的应用或者包吗?
  • 我在描述中添加了确切的错误消息。这三个模块是不同的包,只有 prychadmin 是应用程序,其他两个是带有类的简单 jar。

标签: java maven web-applications glassfish war


【解决方案1】:

尝试通过将您的应用程序相关的 jar 文件添加到两个域 ext (domain1/lib/ext) 目录中。

【讨论】:

  • 刚刚试了一下,还是不行,是不是应该重启一下?我查看了 glassfish 网络管理工具,但它在此应用程序的库下没有显示任何内容
  • 尝试移除 GlassFish。从域->部署和域->生成和域->eclipse应用程序和域->osgi缓存目录中删除所有内容。
【解决方案2】:

您不需要修改清单文件。从错误消息来看,缺少的类似乎是您的主模块中的类。你能确保该类存在于 WEB-INF/classes 中吗?

【讨论】:

  • 这个类在 lib 目录下的 .jar 包中,我三重检查了这个。好吧,我可以将 .class 文件复制到 classes 文件夹,但我认为没有意义,我想找出为什么它不能按设计方式工作,在 lib 中使用 .jar,而不是使用有问题的解决方法。当然,如果一切都失败了,我会使用这个解决方法,但我非常希望以正确的方式来做。
  • 如果你说它在tomcat上不起作用,显然结构不对。你能在war文件中列出目录结构吗?特别是关于找不到的类
  • 我添加到问题描述中
  • 你的战争结构似乎不对。您为什么不先手动尝试清理它们并尝试使用tomcat?看起来很乱。
  • 什么看起来不完全正确,您认为我应该删除什么?正如您在上面的 pom.xml 中看到的那样,这场战争是使用 maven-war-plugin 生成的。
猜你喜欢
  • 1970-01-01
  • 2023-03-21
  • 1970-01-01
  • 2015-11-18
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-02-10
相关资源
最近更新 更多