2014-02-22 43 views
1

當添加持久化到我的Maven的Java的項目,我可以成功地建立和編譯(「清理並生成項目」在NetBeans中,我想它確實MVN網站)的項目,但我不能夠啓動之後(Netbeans的「運行項目」)。將持久性添加到Maven-Java-project時出現錯誤(org.codehaus.mojo)?

我一直在嘗試一段時間沒有成功。例如,我嘗試刪除pom.xml中的org.codehaus.mojo插件,儘管我的成功沒有任何變化。

有誰知道這個問題?我的MySQL數據庫設置有任何錯誤的配置嗎?或者在pom.xml中有錯誤?或者在persistence.xml中?

從NetBeans IDE的錯誤:

cd /home/myuser/NetBeansProjects/mavenglasses; JAVA_HOME=/home/myuser/jdk1.7.0_51 /home/myuser/netbeans-7.4/java/maven/bin/mvn "-Dexec.args=-jar ${basedir}/target/mavenglasses-1.0.jar" -Dexec.executable=/home/myuser/jdk1.7.0_51/bin/java org.codehaus.mojo:exec-maven-plugin:1.2.1:exec 
Running NetBeans Compile On Save execution. Phase execution is skipped and output directories of dependency projects (with Compile on Save turned on) will be used instead of their jar artifacts. 
Scanning for projects... 

------------------------------------------------------------------------ 
Building mavenglasses 1.0 
------------------------------------------------------------------------ 

--- exec-maven-plugin:1.2.1:exec (default-cli) @ mavenglasses --- 
Exception in thread "main" java.lang.SecurityException: Invalid signature file digest for Manifest main attributes 
    at sun.security.util.SignatureFileVerifier.processImpl(SignatureFileVerifier.java:240) 
    at sun.security.util.SignatureFileVerifier.process(SignatureFileVerifier.java:193) 
    at java.util.jar.JarVerifier.processEntry(JarVerifier.java:264) 
    at java.util.jar.JarVerifier.update(JarVerifier.java:218) 
    at java.util.jar.JarFile.initializeVerifier(JarFile.java:345) 
    at java.util.jar.JarFile.getInputStream(JarFile.java:412) 
    at sun.misc.JarIndex.getJarIndex(JarIndex.java:137) 
    at sun.misc.URLClassPath$JarLoader$1.run(URLClassPath.java:674) 
    at sun.misc.URLClassPath$JarLoader$1.run(URLClassPath.java:666) 
    at java.security.AccessController.doPrivileged(Native Method) 
    at sun.misc.URLClassPath$JarLoader.ensureOpen(URLClassPath.java:665) 
    at sun.misc.URLClassPath$JarLoader.<init>(URLClassPath.java:638) 
    at sun.misc.URLClassPath$3.run(URLClassPath.java:366) 
    at sun.misc.URLClassPath$3.run(URLClassPath.java:356) 
    at java.security.AccessController.doPrivileged(Native Method) 
    at sun.misc.URLClassPath.getLoader(URLClassPath.java:355) 
    at sun.misc.URLClassPath.getLoader(URLClassPath.java:332) 
    at sun.misc.URLClassPath.getResource(URLClassPath.java:198) 
    at java.net.URLClassLoader$1.run(URLClassLoader.java:358) 
    at java.net.URLClassLoader$1.run(URLClassLoader.java:355) 
    at java.security.AccessController.doPrivileged(Native Method) 
    at java.net.URLClassLoader.findClass(URLClassLoader.java:354) 
    at java.lang.ClassLoader.loadClass(ClassLoader.java:425) 
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308) 
    at java.lang.ClassLoader.loadClass(ClassLoader.java:358) 
    at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:482) 
------------------------------------------------------------------------ 
BUILD FAILURE 
------------------------------------------------------------------------ 
Total time: 0.850s 
Finished at: Sun Feb 23 02:29:03 CET 2014 
Final Memory: 6M/105M 
------------------------------------------------------------------------ 
Failed to execute goal org.codehaus.mojo:exec-maven-plugin:1.2.1:exec (default-cli) on project mavenglasses: Command execution failed. Process exited with an error: 1 (Exit value: 1) -> [Help 1] 

To see the full stack trace of the errors, re-run Maven with the -e switch. 
Re-run Maven using the -X switch to enable full debug logging. 

For more information about the errors and possible solutions, please read the following articles: 
[Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException 

完整的persistence.xml:

<?xml version="1.0" encoding="UTF-8"?> 
<persistence version="2.1" xmlns="http://xmlns.jcp.org/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd"> 
    <persistence-unit name="GlassesPU" transaction-type="RESOURCE_LOCAL"> 
    <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider> 
    <class>com.treasury.mavenglasses.Hund</class> 
    <properties> 
     <property name="javax.persistence.jdbc.url" value="jdbc:mysql://localhost:3306/glasses?zeroDateTimeBehavior=convertToNull"/> 
     <property name="javax.persistence.jdbc.password" value="mypwd"/> 
     <property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver"/> 
     <property name="javax.persistence.jdbc.user" value="root"/> 
     <property name="javax.persistence.schema-generation.database.action" value="drop-and-create"/> 
    </properties> 
    </persistence-unit> 
</persistence> 

完整的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>com.treasury</groupId> 
    <artifactId>mavenglasses</artifactId> 
    <version>1.0</version> 
    <packaging>jar</packaging> 

    <name>mavenglasses</name> 

    <properties> 
     <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> 
     <mainClass>com.treasury.mavenglasses.MainApp</mainClass> 
    </properties> 

    <organization> 
     <!-- Used as the 'Vendor' for JNLP generation --> 
     <name>Your Organisation</name> 
    </organization> 

    <build> 
     <plugins> 
      <plugin> 
       <groupId>org.apache.maven.plugins</groupId> 
       <artifactId>maven-dependency-plugin</artifactId> 
       <version>2.6</version> 
       <executions> 
        <execution> 
         <id>unpack-dependencies</id> 
         <phase>package</phase> 
         <goals> 
          <goal>unpack-dependencies</goal> 
         </goals> 
         <configuration> 
          <excludeScope>system</excludeScope> 
          <excludeGroupIds>junit,org.mockito,org.hamcrest</excludeGroupIds> 
          <outputDirectory>${project.build.directory}/classes</outputDirectory> 
         </configuration> 
        </execution> 
       </executions> 
      </plugin> 
      <plugin> 
       <groupId>org.codehaus.mojo</groupId> 
       <artifactId>exec-maven-plugin</artifactId> 
       <version>1.2.1</version> 
       <executions> 
        <execution> 
         <id>unpack-dependencies</id> 

         <phase>package</phase> 
         <goals> 
          <goal>exec</goal> 
         </goals> 
         <configuration> 
          <executable>${java.home}/../bin/javafxpackager</executable> 
          <arguments> 
           <argument>-createjar</argument> 
           <argument>-nocss2bin</argument> 
           <argument>-appclass</argument> 
           <argument>${mainClass}</argument> 
           <argument>-srcdir</argument> 
           <argument>${project.build.directory}/classes</argument> 
           <argument>-outdir</argument> 
           <argument>${project.build.directory}</argument> 
           <argument>-outfile</argument> 
           <argument>${project.build.finalName}.jar</argument> 
          </arguments> 
         </configuration> 
        </execution> 
       </executions> 
      </plugin> 
      <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> 
         <bootclasspath>${sun.boot.class.path}${path.separator}${java.home}/lib/jfxrt.jar</bootclasspath> 
        </compilerArguments> 
       </configuration> 
      </plugin> 
     </plugins> 
    </build> 
    <dependencies> 
     <dependency> 
      <groupId>org.eclipse.persistence</groupId> 
      <artifactId>eclipselink</artifactId> 
      <version>2.5.1</version> 
     </dependency> 
     <dependency> 
      <groupId>org.eclipse.persistence</groupId> 
      <artifactId>org.eclipse.persistence.jpa.modelgen.processor</artifactId> 
      <version>2.5.1</version> 
      <scope>provided</scope> 
     </dependency> 
     <dependency> 
      <groupId>mysql</groupId> 
      <artifactId>mysql-connector-java</artifactId> 
      <version>5.1.29</version> 
     </dependency> 
    </dependencies> 
</project> 
+1

我只能猜測,但錯誤消息顯示方向:'異常線程「main」 java.lang.SecurityException異常:無效的簽名文件的摘要清單主要attributes'所以不是行家的問題是調用進程。我假設你正在通過exec-maven-plugin:exec啓動一個java進程?如果沒有完整的pom和配置,很難猜測出什麼問題。 – khmarbaise

+1

我剛剛添加了完整的pom.xml。 它有一些錯誤配置嗎? – Socrates

+0

您是否嘗試過手動調用它? – khmarbaise

回答

0

我在NetBeans中也有類似的問題,最近發現現在修復。當我增加了一個EntityClass並有NetBeans將自動添加持久性單元等

的問題似乎是由持久性單元將文件添加到您的項目META-INF文件夾會導致其將使用不同的技術的問題第一次啓動計算罐子簽名,或類似的東西。

要刪除這些文件,在你的POM中將exec Maven的插件後補充一點:

<plugin> 
      <groupId>org.codehaus.mojo</groupId> 
      <artifactId>truezip-maven-plugin</artifactId> 
      <version>1.2</version> 
      <executions> 
       <execution> 
        <id>remove-RSA-and-SF-files</id> 
        <goals> 
         <goal>remove</goal> 
        </goals> 
        <phase>package</phase> 
        <configuration> 
         <fileset> 
          <directory>${archive}/META-INF</directory> 
          <includes> 
           <include>**/*.RSA</include> 
           <include>**/*.SF</include> 
           <include>**/*.DSA</include> 
          </includes> 
         </fileset> 
        </configuration> 
       </execution> 
      </executions> 
</plugin> 

你還需要添加歸檔變量,它指向你的.jar文件:

<archive>target/projName-1.0-SNAPSHOT.jar</archive> 

最後添加到您的運行任務nbactions.xml:

<goal>org.codehaus.mojo:truezip-maven-plugin:1.2:remove</goal> 

之前:

<goal>org.codehaus.mojo:exec-maven-plugin:1.2.1:exec</goal> 

希望幫助!

+0

有同樣的問題,但你在這裏描述的解決方案不適合我。 構建失敗 在插件org.codehaus.mojo找不到目標「刪除」:EXEC-Maven的插件:1.2 –

+0

奇怪,你有沒有在你的pom.xml定義的目標? – user473453

+0

嗨@Andrey不,我的** JavaFX **項目也沒有工作。我注意到Netbeans JavaFX POM文件在最終的構建文件中使用了「classes /」,您可以在「target/classes/META-INF /」中看到.SF等文件。使用這些信息,TrueZip插件至少使用' $ {project.build.directory}/classes/META-INF'來查找文件。然而,沒有收益的結果,我仍然得到「無效簽名...」的錯誤。 W上。 – will

相關問題