2013-12-04 3 views
5

Я компилирую и запускаю некоторый исходный код, который я получил от проекта Structr (https://github.com/structr/structr). Я могу правильно запустить программу с помощью команды maven maven, но не используя JVM-команду java.java.lang.NoClassDefFoundError при запуске проекта с Java, но работает при работе с mvn exec: exec

Этап компиляции хорошо сочетается с maven clean install -DskipTests

При управлении передний конец (в каталоге structr-Ui), она идет хорошо, если используется maven exec:exec, но не на java -cp target/lib/*;target/structr-ui-0.8.2.jar org.structr.Ui. У меня есть трассировка стека, указывающая java.lang.NoClassDefFoundError на org.structr.core.entity.AbstractNode и org.structr.core.EntityContext. Что я нахожу странным о том, что файл Maven pom.xml в ехес записи мы имеем

 <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> 

Весь 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> 
     <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> 

mvn exec:exec выглядит утверждение эквивалентно Java JVM. Этот вопрос может быть в основном; Что делает maven по-разному, чем java, что в случае maven правильная работа программы?

Edit - дополнительный Maven и отладка Java информация

На mvn -X exec:exec, выход приведен здесь http://roberthoff.com/files/mvn_exec_trace.txt

И java -server -Dfile.encoding=utf-8 -XX:+UseNUMA -Xms1g -Xmx1g -classpath target/lib/* ;target/structr-ui-0.8.2.jar org.structr.Ui мы имеем http://roberthoff.com/files/java_trace.txt

+0

Работает в Windows? Попробуйте использовать '\ вместо'/в качестве разделителя каталога. – Jesper

+1

Интересной частью POM будут ваши зависимости Maven, так как они будут добавлены Maven при использовании цели 'exec'. Я предполагаю, что вы добавили больше «target/lib/*; target/structr-ui-0.8.2.jar». –

+2

@jesper - Если используются правильные интерфейсы, Java преобразует косую черту в подходящий для платформы разделитель. –

ответ

3

У вас есть действительный вопрос здесь, потому что, согласно к Maven documentation on the exec:exec goal вам понадобится строфа <\classpath> в вашей конфигурации, чтобы включить весь путь к модулю проекта.

Однако, по-видимому, Maven запускает программу с полностью (и правильно) настроенным пулом классов по какой-либо причине.

Чтобы решить проблему, я запустил Maven с аргументом командной строки и тщательно просмотрел вывод отладки, пока не найду точную команду, которую он запускает. Затем я попробую запустить его из того же каталога, гарантируя, что я использую ту же самую установку Java и вижу, работает ли она.

+0

Привет, я попробовал запустить 'mvn -X exec: exec', а в потоке отладки я получил' Выполнение командной строки: java -server -Dfile.encoding = utf-8 -XX: + UseNUMA -Xms1g -Xmx1g -classpath target /lib/*;target/structr-ui-0.8.2.jar org.structr.Ui' - это хорошо соответствует записи pom. Тем не менее, при запуске команды я получаю те же ошибки, что и раньше. – area5one

+0

Я добавил следы на моем сервере (они были слишком длинны, чтобы добавить к самому вопросу) http://roberthoff.com/files/mvn_exec_trace.txt и http://roberthoff.com/files/java_trace.txt – area5one

1

Обратите внимание на плагин maven-dependency в pom. Он копирует все зависимости во время фазы пакета в папку target/lib, а затем они находятся в пути к классам. Следующее должно работать:

maven clean package -DskipTests 
java -cp target/lib/*;target/structr-ui-0.8.2.jar org.structr.Ui 
+0

Я пробовал но это не имело значения. Он уже скопировал все библиотеки в 'target/lib' с установкой maven. – area5one

Смежные вопросы