6

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>am@structr.org</email>
        </developer>
        <developer>
            <name>Christian Morgner</name>
            <email>cm@structr.org</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;structr@structr.org&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:git@github.com: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

Robb Hoff
  • 1,719
  • 2
  • 17
  • 32
  • Running on Windows? Try using `\ instead of `/ as the directory separator. – Jesper Dec 04 '13 at 13:00
  • 1
    The interesting part of the POM would be your Maven dependencies since they will be added by Maven when using the `exec` goal. I guess, there is more then "target/lib/*;target/structr-ui-0.8.2.jar" that you added. – Rafael Winterhalter Dec 04 '13 at 13:01
  • 2
    @jesper - If proper interfaces are used Java will convert forward slash into the platform-appropriate separator. – Hot Licks Dec 04 '13 at 13:05
  • You most likely have a problem with incompatible jar files. Probably the two execution environments differ somehow in their class paths. – Hot Licks Dec 04 '13 at 13:06
  • hi all, I've posted the whole pom.xml file in my question, perhaps it's possible determine something from it? – Robb Hoff Dec 04 '13 at 13:16
  • NoClassDefError means you are missing a class in your classpath. Can you confirm that the `structr-ui-0.8.2.jar` JAR has those two classes in that spot? you can use the command `jar -tvf structr-ui-0.8.2.jar`. Also make sure the jar is where you say it is, which looks to be a `target` folder under the current folder. You may also try to add `../` to the front of your jar paths. – CodeChimp Dec 04 '13 at 15:30
  • 4
    @CodeChimp - Actually, not quite. A missing class will cause ClassNotFoundException. NoClassDefFoundError is when a class is located but is not found to be valid, usually because of a mismatch (version change) in other classes it needs to reference to be verified. In some cases this can be due to a missing class but in most cases not. – Hot Licks Dec 04 '13 at 17:38
  • @HotLicks, you are correct. Still, you should be able to verify the JAR. If you are getting that at runtime, it means something has changed. – CodeChimp Dec 04 '13 at 18:30
  • There are three jar files that must have been produced from the other Structr modules during compile time that are in the target/lib directory, they are structr-core-0.8.2.jar, structr-rest-0.8.2.jar and structr-server-0.8.2.jar. The structr-core-0.8.2.jar file contains the classes entity.AbstractNode and EntityContext that were referred to in the stack-trace – Robb Hoff Dec 04 '13 at 19:21
  • @CodeChimp - Yep, at least 50% of the time the error is due to compiling with one version of a JAR and running with a different version. (But unfortunately the error is a "garbage can" one, and can be raised for all sorts of unrelated problems, and the error text is pretty much zero help.) – Hot Licks Dec 04 '13 at 19:28
  • I would start by searching my computer for all instances of the JARs in question. I am guessing Maven is using a different version than when you run from CLI. You should be able to look at the byte count of the JARs. Somewhere you missed copying a library or something. – CodeChimp Dec 04 '13 at 21:22
  • Hi CodeChimp, it turns out there are other jars containing the classes in question, in the directory C:\Users\Robert\.m2\repository. There are structr-core-0.8.2.jar which has the same bytecount, then there are two others with slightly different sizes (structr-core-0.8-20130913.160642-60.jar and structr-core-0.9-20130919.223214-12.jar) .. because I tried out different things previously .. maybe it has something to do with it – Robb Hoff Dec 04 '13 at 21:31
  • Yep, when you have the same class (though different versions) in multiple JARs you're at big risk of NCDF error. – Hot Licks Dec 05 '13 at 01:16
  • Do a mvn clean, mvn install -DskipTests again from base project folder, go to structr-ui and try to run it again, it works for me without problems. – vzamanillo Dec 12 '13 at 18:04

2 Answers2

3

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.

Dave
  • 21,524
  • 28
  • 141
  • 221
  • Hi, i tried running `mvn -X exec:exec`, and in the debugging stream I got `Executing command line: java -server -Dfile.encoding=utf-8 -XX:+UseNUMA -Xms1g -Xmx1g -classpath target/lib/*;target/structr-ui-0.8.2.jar org.structr.Ui` - this corresponds well with the pom entry. Still, on running the command directly I get the same errors as before. – Robb Hoff Dec 09 '13 at 10:13
  • I added the traces on my server (they were too long to add to the question itself) http://roberthoff.com/files/mvn_exec_trace.txt and http://roberthoff.com/files/java_trace.txt – Robb Hoff Dec 09 '13 at 10:34
1

Notice the maven-dependency-plugin in the pom. It copies all dependencies during the package phase to target/lib folder and then they are on classpath. Following should work:

maven clean package -DskipTests
java -cp target/lib/*;target/structr-ui-0.8.2.jar org.structr.Ui
František Hartman
  • 14,436
  • 2
  • 40
  • 60
  • I tried this but it didn't make a difference. It had already copied all the libraries to `target/lib` with maven install. – Robb Hoff Dec 10 '13 at 22:37