Maven und Glassfish java.lang.NoClassDefFoundError:

Hi,

ich habe ein Maven Projekt mit Modulen erstellt. Meine JSF WebApplikation ist ein solches Modul und hat eine Dependency auf ein anderes Modul. Wenn ich die WebApplikation ausführe erhalte ich immer die Exception:

java.lang.NoClassDefFoundError: code/elephant/domainmodel/Question

Das Root Maven Projekt (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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>code.elephant</groupId>
<artifactId>code.elephant</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>pom</packaging>
<properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <maven-compiler-plugin.version>3.0</maven-compiler-plugin.version>
</properties>
<build>
    <pluginManagement>
        <plugins>
            <plugin>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>${maven-compiler-plugin.version}</version>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-shade-plugin</artifactId>
                <version>1.6</version>
                <executions>
                    <execution>
                        <phase>package</phase>
                        <goals>
                            <goal>shade</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </pluginManagement>
</build>
<modules>
    <module>DomainModel</module>
    <module>WebApp</module>
    <module>Contract</module>
    <module>Dao</module>
</modules>
<name>code.elephant</name>

Das Maven Modul DomainModel

<?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/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <artifactId>code.elephant</artifactId>
        <groupId>code.elephant</groupId>
        <version>1.0-SNAPSHOT</version>
    </parent>
    <groupId>code.elephant</groupId>
    <artifactId>DomainModel</artifactId>
    <version>1.0-SNAPSHOT</version>
    <packaging>jar</packaging>
    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <maven.compiler.source>1.8</maven.compiler.source>
        <maven.compiler.target>1.8</maven.compiler.target>
    </properties>
</project>

die WebApp (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/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <artifactId>code.elephant</artifactId>
        <groupId>code.elephant</groupId>
        <version>1.0-SNAPSHOT</version>
    </parent>

    <groupId>code.elephant</groupId>
    <artifactId>WebApp</artifactId>
    <version>1.0-SNAPSHOT</version>
    <packaging>war</packaging>

    <name>WebApp</name>

    <properties>
        <endorsed.dir>${project.build.directory}/endorsed</endorsed.dir>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>
    
    <dependencies>
        <dependency>
            <groupId>${project.groupId}</groupId>
            <artifactId>Dao</artifactId>
            <version>${project.version}</version>
        </dependency>
        <dependency>
            <groupId>${project.groupId}</groupId>
            <artifactId>DomainModel</artifactId>
            <version>${project.version}</version>
        </dependency>
        <dependency>
            <groupId>javax</groupId>
            <artifactId>javaee-web-api</artifactId>
            <version>7.0</version>
            <scope>provided</scope>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.1</version>
                <configuration>
                    <source>1.7</source>
                    <target>1.7</target>
                    <compilerArguments>
                        <endorseddirs>${endorsed.dir}</endorseddirs>
                    </compilerArguments>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-war-plugin</artifactId>
                <version>2.3</version>
                <configuration>
                    <failOnMissingWebXml>false</failOnMissingWebXml>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-dependency-plugin</artifactId>
                <version>2.6</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>7.0</version>
                                    <type>jar</type>
                                </artifactItem>
                            </artifactItems>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

</project>

Hat jemand eine Idee warum das nicht geht? Parent und Dependecies sind ja eingetragen?. Hier der ganze Code vom Projekt https://github.com/mfe-/SEPM/ . Wäre echt super, wenn mir jemand dazu einen Tipp geben könnte. lg

Ich habe das ganze gerade mal gebaut und auf Payara laufen lassen (Glassfish habe ich gerade nicht).

mvn package auf das Webprojekt, danach über Netbeans auf Payara deployed -> Keine Probleme. Ich sehe auch, dass das erstellte WAR das DomainModel jar im Lib Verzeichnis hat. Kannst du noch einmal genau die Schritte aufzeigen, wie du baust?

[details=Log von Payara]```
Information: Loading application [wstx-services] at [/__wstx-services]
Information: WS-TX Services successfully started.
Information: Loading application [WebApplication1] at [/WebApplication1]
Information: Loading application WebApplication1 done in 4.357 ms
Information: Payara Server 4.1.1.162 #badassfish (116) startup time : Felix (1.835ms), startup services(4.871ms), total(6.706ms)
Information: Cleaning JarFileFactory Cache to prevent jar FD leaks
Information: Grizzly Framework 2.3.24 started in: 3ms - bound to [/0.0.0.0:7676]
Information: HV000001: Hibernate Validator 5.1.2.Final
Information: Registered com.sun.enterprise.glassfish.bootstrap.osgi.EmbeddedOSGiGlassFishImpl@479f2dc2 as OSGi service registration: org.apache.felix.framework.ServiceRegistrationImpl@19058533.
Information: JMXStartupService has started JMXConnector on JMXService URL service:jmx:rmi://mbp:8686/jndi/rmi://mbp:8686/jmxrmi
Information: /Applications/NetBeans/payara41/glassfish/domains/domain1/autodeploy/bundles does not exist, please create it.
Information: Created HTTP listener http-listener-2 on host/port 0.0.0.0:8181
Information: Grizzly Framework 2.3.24 started in: 1ms - bound to [/0.0.0.0:8181]
Information: Created HTTP listener http-listener-1 on host/port 0.0.0.0:8080
Information: Grizzly Framework 2.3.24 started in: 1ms - bound to [/0.0.0.0:8080]
Information: Mojarra 2.2.13 ( 20160203-1910 unable to get svn info) für Kontext ‘/WebApp’ wird initialisiert.
Information: Loading application [WebApp] at [/WebApp]
Information: WebApp was successfully deployed in 1.770 milliseconds.
Information: yoyoyo


Edit: Da ich mit Glassfish in letzter Zeit öfters mal böse Überraschungen hatte, habe ich es doch auch noch mal mit diesem Probiert, selbes Ergebnis (Glassfish 4.1.1):

[details=Log von Glassfish]

Information: Mojarra 2.2.12 ( 20150720-0848 https://svn.java.net/svn/mojarra~svn/tags/2.2.12@14885) für Kontext ‘/WebApp’ wird initialisiert.
Information: Loading application [WebApp] at [/WebApp]
Information: WebApp was successfully deployed in 189 milliseconds.
Information: yoyoyo

Hallo,

ich habe mir mal die POM’s angeschaut und das ganze mal ein wenig aktualisiert und auch die Vererbung in Maven genutzt…habe einen Pull Request auf das Projekt gemacht…

Nach den Anpassungen baut das Projekt auch einwandfrei, da es vorher nämlich nicht mal durch gebaut hat…

BTW: Das Contract Module scheint nirgendwo benötigt zu werden?
Gruß
Karl Heinz

1 „Gefällt mir“

Hey danke euch zwei.

Ich denke das Problem lag auch daran, dass

1.) NetBeans kein mvn install gemacht hat (fehlendes goal)
2.) Die Maven Packete nicht aktuell waren import elephant.core.domainmodel.Question; vs import code.elephant.domainmodel.*; ?

Das Contract Module sollte eigentlich schon verwendet werden, evtl. ist die GitHub Version noch nicht up to date.
Danke für den PR kama!