【问题标题】:Error (org.codehaus.mojo) when adding persistence to Maven-Java-project?向 Maven-Java-project 添加持久性时出错(org.codehaus.mojo)?
【发布时间】:2014-03-24 00:33:50
【问题描述】:

当向我的 Maven-Java 项目添加持久性时,我可以成功构建和编译(Netbeans 中的“清理和构建项目”,我想它确实 mvn 站点)项目,但我不会之后无法启动它(Netbeans 中的“运行项目”)。

我已经尝试了一段时间没有成功。例如,我尝试删除 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>

【问题讨论】:

  • 我只能猜测,但错误消息显示了方向:Exception in thread "main" java.lang.SecurityException: Invalid signature file digest for Manifest main attributes 所以不是 maven 是调用过程的问题。我假设您正在通过 exec-maven-plugin:exec 启动一个 java 进程?如果没有完整的 pom 和配置,很难猜出哪里出了问题。
  • 我刚刚添加了完整的 pom.xml。里面有没有配置错误?
  • 你试过手动调用吗?
  • 你到底是什么意思?你的意思是像“mvn site”+ java -jar myfile.jar?

标签: java mysql maven jpa persistence


【解决方案1】:

我最近在 NetBeans 中遇到了类似的问题,现在找到了解决方法。当我添加一个 EntityClass 并让 NetBeans 自动添加持久性单元等时,问题首先开始。

问题似乎是由持久性单元将文件添加到您的项目 META-INF 文件夹中造成的,该文件夹将使用不同的技术来计算 jar 签名或类似的东西。

要删除这些文件,请在 pom 中的 exec-maven-plugin 之后添加:

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

希望有帮助!

【讨论】:

  • 有同样的问题,但你在这里描述的解决方案对我不起作用。构建失败在插件 org.codehaus.mojo:exec-maven-plugin:1.2 中找不到目标“删除”
  • 奇怪,你在 pom.xml 中定义了目标吗?
  • 嗨 @Andrey 不,我的 JavaFX 项目也不起作用。我确实注意到 Netbeans JavaFX POM 文件在最终构建文件中使用“classes/”,您可以在“target/classes/META-INF/”中看到 .SF 等文件...使用此信息,TrueZip 插件至少 find 使用以下文件:&lt;directory&gt;${project.build.directory}/classes/META-INF&lt;/directory&gt;。但是没有任何收获,我仍然收到“无效签名...”错误。 w.
  • 另见:“Invalid signature file” when attempting to run a .jar ... 这对于我的 非 JavaFX 项目工作。传递它,以防有人发现适用于 JavaFX 的变体。
  • @Andrey .. 你可能想看看我关于这个话题的问题:stackoverflow.com/questions/25842559/…
猜你喜欢
  • 2017-12-17
  • 1970-01-01
  • 1970-01-01
  • 2012-12-19
  • 1970-01-01
  • 2019-06-02
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多