Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

java.lang.NoClassDefFoundError on running project with Java, but works when running with mvn exec:exec

I'm compiling and running some source code I got from a project called Structr (https://github.com/structr/structr). I'm able to run the program correctly with a maven mvn command but not using the JVM java command.

The compilation step goes well with maven clean install -DskipTests

On running the front-end (in the structr-ui directory), it goes well if using maven exec:exec but fails on java -cp target/lib/*;target/structr-ui-0.8.2.jar org.structr.Ui. I have some stack trace indicating java.lang.NoClassDefFoundError on org.structr.core.entity.AbstractNode and org.structr.core.EntityContext. What I find strange about this is that the maven pom.xml file in the exec entry we have

        <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>exec-maven-plugin</artifactId>
            <version>1.2.1</version>
            <configuration>
                <executable>java</executable>
                <arguments>
                    <argument>-server</argument>
                    <argument>-Dfile.encoding=utf-8</argument>
                    <argument>-XX:+UseNUMA</argument>
                    <argument>-Xms1g</argument>
                    <argument>-Xmx1g</argument>
                    <argument>-classpath</argument>
                    <argument>target/lib/*;target/structr-ui-0.8.2.jar</argument>
                    <argument>org.structr.Ui</argument>
                </arguments>
            </configuration>
        </plugin>

The entire pom.xml reads

<?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>
        <groupId>org.structr</groupId>
        <artifactId>structr</artifactId>
        <version>0.8.2</version>
    </parent>

    <groupId>org.structr</groupId>
    <artifactId>structr-ui</artifactId>
    <packaging>jar</packaging>
    <version>0.8.2</version>
    <name>structr-ui</name>
    <description>Structr is an open source framework based on the popular Neo4j graph database.</description>
    <developers>
        <developer>
            <name>Axel Morgner</name>
            <email>[email protected]</email>
        </developer>
        <developer>
            <name>Christian Morgner</name>
            <email>[email protected]</email>
        </developer>
    </developers>
    <url>http://structr.org</url>

    <properties>
        <netbeans.hint.license>structr-agpl30</netbeans.hint.license>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>
    <repositories>
        <repository>
            <id>neo4j-releases</id>
            <url>http://m2.neo4j.org/content/repositories/releases</url>
        </repository>
        <repository>
            <id>neo4j-snapshots</id>
            <url>http://m2.neo4j.org/content/repositories/snapshots</url>
        </repository>
        <repository>
            <id>google-diff-patch-match</id>
            <name>google-diff-patch-match</name>
            <url>http://google-diff-match-patch.googlecode.com/svn/trunk/maven/</url>
        </repository>
        <repository>
            <id>jodd</id>
            <url>http://repo1.maven.org/maven2/org/jodd/</url>
        </repository>
        <!--        <repository>
            <id>alfresco-releases</id>
            <url>https://maven.alfresco.com/nexus/content/repositories/releases</url>
        </repository>
        <repository>
            <id>alfresco-snapshots</id>
            <url>https://maven.alfresco.com/nexus/content/repositories/snapshots</url>
        </repository>-->
        <repository>
            <id>snapshots.maven.structr.org</id>
            <url>http://maven.structr.org/artifactory/snapshot</url>
        </repository>
        <repository>
            <id>releases.maven.structr.org</id>
            <url>http://maven.structr.org/artifactory/release</url>
        </repository>
    </repositories>
    <dependencies>
        <dependency>
            <groupId>${project.groupId}</groupId>
            <artifactId>structr-server</artifactId>
            <version>${project.version}</version>
        </dependency>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.11</version>
            <type>jar</type>
            <scope>test</scope>
            <optional>false</optional>
        </dependency>
        <!--        <dependency>
                <artifactId>urlrewritefilter</artifactId>
                <groupId>org.tuckey</groupId>
                <type>jar</type>
                <version>4.0.4</version>
        </dependency>-->
        <dependency>
            <groupId>diff_match_patch</groupId>
            <artifactId>diff_match_patch</artifactId>
            <version>current</version>
        </dependency>
        <dependency>
            <groupId>org.pegdown</groupId>
            <artifactId>pegdown</artifactId>
            <version>1.1.0</version>
        </dependency>
        <dependency>
            <groupId>net.java</groupId>
            <artifactId>textile-j</artifactId>
            <version>2.2</version>
        </dependency>
        <dependency>
            <groupId>javax.ws.rs</groupId>
            <artifactId>javax.ws.rs-api</artifactId>
            <version>2.0-m09</version>
        </dependency>
        <dependency>
            <groupId>com.sun.jersey</groupId>
            <artifactId>jersey-client</artifactId>
            <version>1.9-ea04</version>
        </dependency>
        <!--        <dependency>
            <groupId>org.neo4j</groupId>
            <artifactId>neo4j-rest-graphdb</artifactId>
            <version>1.9.5</version>
        </dependency>-->
        <dependency>
            <groupId>com.flagstone</groupId>
            <artifactId>transform</artifactId>
            <version>3.0.2</version>
        </dependency>
        <dependency>
            <groupId>org.jsoup</groupId>
            <artifactId>jsoup</artifactId>
            <version>1.7.1</version>
        </dependency>
        <dependency>
            <groupId>org.jodd</groupId>
            <artifactId>jodd-lagarto</artifactId>
            <version>3.4.5</version>
        </dependency>
        <!--        <dependency>
            <groupId>org.jodd</groupId>
            <artifactId>jodd-http</artifactId>
            <version>3.4.5</version>
        </dependency>-->
        <dependency>
            <groupId>org.apache.commons</groupId>
            <artifactId>commons-compress</artifactId>
            <version>1.4.1</version>
        </dependency>
        <dependency>
            <groupId>commons-lang</groupId>
            <artifactId>commons-lang</artifactId>
            <version>2.6</version>
        </dependency>
        <dependency>
            <groupId>commons-codec</groupId>
            <artifactId>commons-codec</artifactId>
            <version>1.8</version>
        </dependency>
        <dependency>
            <groupId>commons-httpclient</groupId>
            <artifactId>commons-httpclient</artifactId>
            <version>3.1</version>
        </dependency>
        <dependency>
            <groupId>commons-net</groupId>
            <artifactId>commons-net</artifactId>
            <version>3.3</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>commons-fileupload</groupId>
            <artifactId>commons-fileupload</artifactId>
            <version>1.3</version>
        </dependency>

        <dependency>
            <groupId>org.mockito</groupId>
            <artifactId>mockito-all</artifactId>
            <version>1.9.5</version>
        </dependency>
        <dependency>
            <groupId>org.apache.oltu.oauth2</groupId>
            <artifactId>org.apache.oltu.oauth2.client</artifactId>
            <version>0.31</version>
        </dependency>
        <dependency>
            <groupId>org.twitter4j</groupId>
            <artifactId>twitter4j-core</artifactId>
            <version>3.0.5</version>
        </dependency>
        <dependency>
            <groupId>org.apache.ftpserver</groupId>
            <artifactId>ftpserver-core</artifactId>
            <version>1.0.6</version>
        </dependency>
    </dependencies>
    <build>
        <resources>
            <resource>
                <directory>src/main/resources</directory>
            </resource>
        </resources>
        <testResources>
            <testResource>
                <directory>src/main/resources</directory>
            </testResource>
        </testResources>
        <plugins>
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>exec-maven-plugin</artifactId>
                <version>1.2.1</version>
                <configuration>
                    <executable>java</executable>
                    <arguments>
                        <argument>-server</argument>
                        <argument>-Dfile.encoding=utf-8</argument>
                        <argument>-XX:+UseNUMA</argument>
                        <argument>-Xms1g</argument>
                        <argument>-Xmx1g</argument>
                        <argument>-classpath</argument>
                        <argument>target/lib/*;target/structr-ui-0.8.2.jar</argument>
                        <argument>org.structr.Ui</argument>
                    </arguments>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>2.3.2</version>
                <configuration>
                    <source>1.7</source>
                    <target>1.7</target>
                    <debug>true</debug>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-dependency-plugin</artifactId>
                <version>2.4</version>
                <executions>
                    <execution>
                        <id>copy-dependencies</id>
                        <phase>package</phase>
                        <goals>
                            <goal>copy-dependencies</goal>
                        </goals>
                        <configuration>
                            <outputDirectory>${project.build.directory}/lib</outputDirectory>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-jar-plugin</artifactId>
                <version>2.4</version>
                <configuration>
                    <archive>
                        <manifest>
                            <addClasspath>true</addClasspath>
                            <classpathPrefix>lib</classpathPrefix>
                        </manifest>
                    </archive>
                </configuration>
            </plugin>
            <plugin>
                <artifactId>maven-assembly-plugin</artifactId>
                <version>2.4</version>
                <configuration>
                    <descriptors>
                        <descriptor>src/main/resources/assemblies/dist.xml</descriptor>
                    </descriptors>
                </configuration>
                <executions>
                    <execution>
                        <id>make-assembly</id>
                        <phase>package</phase>
                        <goals>
                            <goal>attached</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.vafer</groupId>
                <artifactId>jdeb</artifactId>
                <version>1.0.1</version>
                <executions>
                    <execution>
                        <phase>package</phase>
                        <goals>
                            <goal>jdeb</goal>
                        </goals>
                        <configuration>
                            <timestamped>true</timestamped>
                            <controlDir>${basedir}/src/main/deb/control</controlDir>
                            <dataSet>
                                <data>
                                    <src>${project.build.directory}/${project.build.finalName}.jar</src>
                                    <type>file</type>
                                    <dst>structr-ui.jar</dst>
                                    <mapper>
                                        <type>perm</type>
                                        <prefix>/usr/lib/${project.artifactId}/</prefix>
                                    </mapper>
                                </data>

                                <data>
                                    <src>${project.build.directory}/lib</src>
                                    <type>directory</type>
                                    <mapper>
                                        <type>perm</type>
                                        <prefix>/usr/lib/${project.artifactId}/lib</prefix>
                                        <filemode>755</filemode>
                                    </mapper>
                                </data>

                                <data>
                                    <src>${basedir}/seed.zip</src>
                                    <type>file</type>
                                    <mapper>
                                        <type>perm</type>
                                        <prefix>/usr/lib/${project.artifactId}/</prefix>
                                        <filemode>755</filemode>
                                    </mapper>
                                </data>

                                <data>
                                    <src>${basedir}/src/main/deb/bin</src>
                                    <type>directory</type>
                                    <mapper>
                                        <type>perm</type>
                                        <prefix>/usr/lib/${project.artifactId}/bin</prefix>
                                        <filemode>755</filemode>
                                    </mapper>
                                </data>

                                <data>
                                    <src>${basedir}/src/main/deb/init.d</src>
                                    <type>directory</type>
                                    <mapper>
                                        <type>perm</type>
                                        <prefix>/etc/init.d</prefix>
                                        <filemode>755</filemode>
                                    </mapper>
                                </data>
                            </dataSet>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-source-plugin</artifactId>
                <version>2.2.1</version>
                <executions>
                    <execution>
                        <id>attach-sources</id>
                        <goals>
                            <goal>jar</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-javadoc-plugin</artifactId>
                <version>2.9.1</version>
                <executions>
                    <execution>
                        <id>attach-javadocs</id>
                        <goals>
                            <goal>jar</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
        <finalName>${project.artifactId}-${project.version}</finalName>
        <!-- Added to make m2e happy, thanks to http://stackoverflow.com/questions/8706017/maven-dependency-plugin-goals-copy-dependencies-unpack-is-not-supported-b -->
        <pluginManagement>
            <plugins>
                <!-- Ignore/Execute plugin execution -->
                <plugin>
                    <groupId>org.eclipse.m2e</groupId>
                    <artifactId>lifecycle-mapping</artifactId>
                    <version>1.0.0</version>
                    <configuration>
                        <lifecycleMappingMetadata>
                            <pluginExecutions>
                                <!-- copy-dependency plugin -->
                                <pluginExecution>
                                    <pluginExecutionFilter>
                                        <groupId>org.apache.maven.plugins</groupId>
                                        <artifactId>maven-dependency-plugin</artifactId>
                                        <versionRange>[1.0.0,)</versionRange>
                                        <goals>
                                            <goal>copy-dependencies</goal>
                                        </goals>
                                    </pluginExecutionFilter>
                                    <action>
                                        <ignore />
                                    </action>
                                </pluginExecution>
                            </pluginExecutions>
                        </lifecycleMappingMetadata>
                    </configuration>
                </plugin>
            </plugins>
        </pluginManagement>
    </build>
    <profiles>
        <profile>
            <id>release-sign-artifacts</id>
            <activation>
                <property>
                    <name>performRelease</name>
                    <value>true</value>
                </property>
            </activation>
            <build>
                <plugins>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-gpg-plugin</artifactId>
                        <version>1.4</version>
                        <executions>
                            <execution>
                                <id>sign-artifacts</id>
                                <phase>verify</phase>
                                <goals>
                                    <goal>sign</goal>
                                </goals>
                            </execution>
                        </executions>
                    </plugin>
                </plugins>
            </build>
        </profile>
    </profiles>

    <licenses>
        <license>
            <name>GNU General Public License, Version 3</name>
            <url>http://www.gnu.org/licenses/agpl-3.0-standalone.html</url>
            <comments>
                Copyright (C) 2010-2013 Axel Morgner, structr &lt;[email protected]&gt;

                This file is part of structr &lt;http://structr.org&gt;.

                structr is free software: you can redistribute it and/or modify
                it under the terms of the GNU Affero General Public License as
                published by the Free Software Foundation, either version 3 of the
                License, or (at your option) any later version.

                structr is distributed in the hope that it will be useful,
                but WITHOUT ANY WARRANTY; without even the implied warranty of
                MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
                GNU General Public License for more details.

                You should have received a copy of the GNU Affero General Public License
                along with structr.  If not, see &lt;http://www.gnu.org/licenses/&gt;.
            </comments>
        </license>
    </licenses>

    <scm>
        <url>https://github.com/structr/structr</url>
        <connection>scm:git:[email protected]:structr/structr.git</connection>
    </scm>

    <distributionManagement>
        <!--        <repository>
            <id>releases.maven.structr.org</id>
            <name>maven.structr.org-releases</name>
            <url>http://maven.structr.org/artifactory/release</url>
        </repository>
        <snapshotRepository>
            <id>snapshots.maven.structr.org</id>
            <name>maven.structr.org-snapshots</name>
            <url>http://maven.structr.org/artifactory/snapshot</url>
        </snapshotRepository>-->
        <repository>
            <id>sonatype-nexus-staging</id>
            <name>Maven Central Staging</name>
            <url>https://oss.sonatype.org/service/local/staging/deploy/maven2</url>
        </repository>
        <snapshotRepository>
            <id>sonatype-nexus-snapshots</id>
            <name>Maven Central Snapshots</name>
            <url>https://oss.sonatype.org/content/repositories/snapshots</url>
        </snapshotRepository>
    </distributionManagement>

</project>

The mvn exec:exec statement looks equivalent to the java JVM statement. This question may be basically; What is maven doing differently than java, that in the maven case making the program run correctly?

Edit - additional maven and java debugging information

On mvn -X exec:exec, The output is given here http://roberthoff.com/files/mvn_exec_trace.txt

And on java -server -Dfile.encoding=utf-8 -XX:+UseNUMA -Xms1g -Xmx1g -classpath target/lib/* ;target/structr-ui-0.8.2.jar org.structr.Ui we have http://roberthoff.com/files/java_trace.txt

like image 516
Rob Hoff Avatar asked Oct 03 '22 06:10

Rob Hoff


1 Answers

You have a valid question here, because according to the Maven documentation on the exec:exec goal you would need to have the <\classpath> stanza in your configuration in order to include the entire project module classpath.

However, it appears as though Maven is running the program with the fully (and properly) configured classpath for some reason.

In order to get to the bottom of the problem, I'd run Maven with the -X command line argument and carefully scan through the debug output until I found the exact command it runs. Then I'd try running it from the same directory, ensuring I am using the same Java installation and see if it works.

like image 181
HDave Avatar answered Oct 13 '22 10:10

HDave