2

Main-Method-class"Bootstrap.class"がsrc/testフォルダーにあるプロジェクトがあります。だから私は<classpathScope>test</classpathScope> 実行できるように使用します

mvn exec:java

私の問題:「java.lang.IllegalArgumentException:Unknown entity:」が発生します。これは、main/javaにある特定のクラスをインポートしているためです。どうすればこれを解決できるかについての考えはありますか?

これは私のポンです:

<?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>
<groupId>eu.peadrtx</groupId>
<artifactId>register</artifactId>
<packaging>war</packaging>
<version>1.6-SNAPSHOT</version>
<name>eu.peadrtx.register</name>

<properties>
    <!-- Convenience property to set the GWT version -->
    <gwtVersion>2.4.0</gwtVersion>

    <!-- GWT needs at least java 1.6 -->
    <maven.compiler.source>1.6</maven.compiler.source>
    <maven.compiler.target>1.6</maven.compiler.target>

    <!-- Don't let your Mac use a crazy non-standard encoding -->
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
</properties>

<!-- notwendig für einige gwt dependencies -->
<repositories>
    <repository>
        <id>gwt-maven-rewraps</id>
        <url>http://gwt-maven-rewraps.googlecode.com/hg/</url>
    </repository>
    <repository>
        <id>cobogw</id>
        <name>Maven2 Repository for cobogw library</name>
        <url>http://cobogw.googlecode.com/svn/maven2</url>
    </repository>
    <repository>
        <id>openehealth.releases</id>
        <name>Open eHealth Maven Repository</name>
        <url>http://repo.openehealth.org/maven2/releases</url>
        <releases>
            <enabled>true</enabled>
        </releases>
        <snapshots>
            <enabled>false</enabled>
        </snapshots>
    </repository>
    <repository>
        <id>openehealth.snapshots</id>
        <name>Open eHealth Maven Repository</name>
        <url>http://repo.openehealth.org/maven2/snapshots</url>
        <releases>
            <enabled>false</enabled>
        </releases>
        <snapshots>
            <enabled>true</enabled>
        </snapshots>
    </repository>
    <repository>
        <id>java.net</id>
        <name>java.net Maven Repository</name>
        <url>http://download.java.net/maven/2/</url>
    </repository>
    <repository>
        <id>codehaus nexus</id>
        <name>Codehaus Nexus Maven Repository</name>
        <url>https://nexus.codehaus.org/content/repositories/releases/</url>
    </repository>
    <repository>
        <id>codehaus</id>
        <name>Codehaus Maven Repository</name>
        <url>http://repository.codehaus.org</url>
    </repository>
    <repository>
        <id>jboss</id>
        <name>JBoss Maven Repository</name>
        <url>http://repository.jboss.org/nexus/content/groups/public-jboss/</url>
    </repository>
    <repository>
        <id>hapi-sf</id>
        <name>HAPI Sourceforge Repository</name>
        <url>http://hl7api.sourceforge.net/m2</url>
    </repository>
</repositories> 

<dependencies>

    ...

    <!-- dependencies for the Unit tests -->

    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <version>4.8.1</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>com.google.gwt</groupId>
        <artifactId>gwt-dev</artifactId>
        <version>${gwtVersion}</version>
    </dependency>
    <dependency>
        <groupId>org.apache.commons</groupId>
        <artifactId>commons-exec</artifactId>
        <version>1.1</version>
    </dependency>
    <dependency>
        <groupId>org.apache.httpcomponents</groupId>
        <artifactId>httpclient</artifactId>
        <version>4.1.2</version>
    </dependency>
    <dependency>
        <groupId>org.apache.httpcomponents</groupId>
        <artifactId>httpcore</artifactId>
        <version>4.1.2</version>
    </dependency>
    <dependency>
        <groupId>org.json</groupId>
        <artifactId>json</artifactId>
        <version>20080701</version>
    </dependency>
    <dependency>
        <groupId>org.mockito</groupId>
        <artifactId>mockito-all</artifactId>
        <version>1.8.5</version>
    </dependency>       
    <dependency>
        <groupId>org.seleniumhq.selenium</groupId>
        <artifactId>selenium-java</artifactId>
        <version>2.15.0</version>
    </dependency>


</dependencies>

<build>
    <!-- Generate compiled stuff in the folder used for development mode -->
    <outputDirectory>target/www/WEB-INF/classes</outputDirectory>
    <resources>
        <resource>
            <directory>src/main/resources</directory>
            <filtering>true</filtering>
        </resource>
    </resources>
    <testResources>
        <testResource>
            <directory>src/test/resources</directory>
            <filtering>true</filtering>
        </testResource>
    </testResources>
    <plugins>
        <plugin>
            <groupId>org.bsc.maven</groupId>
            <artifactId>maven-processor-plugin</artifactId>
            <version>2.0.5</version>
            <executions>
                <execution>
                    <id>process</id>
                    <goals>
                        <goal>process</goal>
                    </goals>
                    <phase>generate-sources</phase>
                </execution>
            </executions>
        </plugin>

        <!-- GWT Maven Plugin -->
        <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>gwt-maven-plugin</artifactId>
            <version>2.4.0</version>
            <dependencies>
                <dependency>
                    <groupId>com.google.gwt</groupId>
                    <artifactId>gwt-user</artifactId>
                    <version>${gwtVersion}</version>
                </dependency>
                <dependency>
                    <groupId>com.google.gwt</groupId>
                    <artifactId>gwt-dev</artifactId>
                    <version>${gwtVersion}</version>
                </dependency>
                <dependency>
                    <groupId>com.google.gwt</groupId>
                    <artifactId>gwt-servlet</artifactId>
                    <version>${gwtVersion}</version>
                </dependency>
            </dependencies>
            <!-- JS is only needed in the package phase, this speeds up testing -->
            <executions>
                <execution>
                    <phase>prepare-package</phase>
                    <goals>
                        <goal>compile</goal>
                        <goal>test</goal> 
                     </goals>
                </execution>  
            </executions>

            <!-- Plugin configuration. There are many available options, see gwt-maven-plugin 
                documentation at codehaus.org -->

            <!-- add gwt:18n and gwt:css configuration see -> http://mojo.codehaus.org/gwt-maven-plugin/i18n-mojo.html#i18nConstantsBundles -->
            <configuration>
                <extraJvmArgs>-javaagent:target/www/WEB-INF/lib/lombok-0.10.8.jar=ECJ -XX:MaxPermSize=384m -Xmx512m -Xss124m</extraJvmArgs>
                <!-- URL that should be automatically opened in the GWT shell (gwt:run). -->
                <runTarget>Register.html</runTarget>
                <!-- Location of the develop-mode web application structure (gwt:run). -->
                <hostedWebapp>target/www</hostedWebapp>
                <!-- Ask GWT to create the Story of Your Compile (SOYC) (gwt:compile) -->
                <compileReport>true</compileReport>
                <module>eu.paedrtx.register.Register</module>
                <logLevel>INFO</logLevel>
                <style>${gwt.style}</style>
            </configuration>
        </plugin>

        <plugin>
          <groupId>org.codehaus.mojo</groupId>
          <artifactId>exec-maven-plugin</artifactId>
          <version>1.2.1</version>
          <executions>
            <execution>
              <id>my-execution</id>
              <phase>prepare-package</phase>
              <goals>
                <goal>java</goal>
              </goals>
            </execution>
          </executions>
          <configuration>
            <mainClass>eu.paedrtx.register.server.utility.Bootstrap</mainClass>
            <classpathScope>test</classpathScope>
          </configuration>
        </plugin>

        <!-- Add source folders to test classpath in order to run gwt-tests as 
            normal junit-tests -->
        <plugin>
            <artifactId>maven-surefire-plugin</artifactId>
            <version>2.5</version>
            <configuration>
                <additionalClasspathElements>
                    <additionalClasspathElement>${project.build.sourceDirectory}</additionalClasspathElement>
                    <additionalClasspathElement>${project.build.testSourceDirectory}</additionalClasspathElement>
                </additionalClasspathElements>
                <useManifestOnlyJar>false</useManifestOnlyJar>
                <forkMode>always</forkMode>
                <!-- Folder for generated testing stuff -->
                <systemProperties>
                    <property>
                        <name>gwt.args</name>
                        <value>-out ${project.build.directory}/${project.build.finalName}</value>
                    </property>
                </systemProperties>
            </configuration>
        </plugin>
        <!-- Copy static web files before executing gwt:run-->
        <plugin>
            <artifactId>maven-resources-plugin</artifactId>
            <version>2.4.2</version>
            <executions>
                <execution>
                    <phase>compile</phase>
                    <goals>
                        <goal>copy-resources</goal>
                    </goals>
                    <configuration>
                        <outputDirectory>target/www</outputDirectory>
                        <resources>
                            <resource>
                                <directory>src/main/webapp</directory>
                            </resource>
                        </resources>
                        <encoding>UTF-8</encoding>
                    </configuration>
                </execution>
            </executions>
        </plugin>
         <!-- Delete gwt generated stuff -->
        <plugin>
            <artifactId>maven-clean-plugin</artifactId>
            <version>2.3</version>
            <configuration>
            <filesets>
                <fileset><directory>src/main/webapp/register</directory></fileset>
                <fileset><directory>src/main/webapp/WEB-INF/classes</directory></fileset>
                <fileset><directory>tomcat</directory></fileset>
                <fileset><directory>www-test</directory></fileset>
                <fileset><directory>.gwt-tmp</directory></fileset>
            </filesets>
            </configuration>
        </plugin>
        <plugin>
            <artifactId>maven-eclipse-plugin</artifactId>
            <version>2.7</version>  <!--  Note 2.8 does not work with AspectJ aspect path -->
            <configuration>
                <downloadSources>true</downloadSources>
                <downloadJavadocs>false</downloadJavadocs>
                <wtpversion>2.0</wtpversion>
                <additionalBuildcommands>
                <buildCommand>
                   <name>com.google.gwt.eclipse.core.gwtProjectValidator</name>
                </buildCommand>
                </additionalBuildcommands>
                <additionalProjectnatures>
                    <projectnature>com.google.gwt.eclipse.core.gwtNature</projectnature>
                </additionalProjectnatures>
            </configuration>
         </plugin>
    </plugins>
</build>

スタックトレース:

[INFO] --- exec-maven-plugin:1.2.1:java (default-cli) @ register ---
[WARNING] 
java.lang.reflect.InvocationTargetException
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.codehaus.mojo.exec.ExecJavaMojo$1.run(ExecJavaMojo.java:297)
    at java.lang.Thread.run(Thread.java:680)
Caused by: java.lang.IllegalArgumentException: Unknown entity: eu.paedrtx.register.server.domain.PaymentDetails
    at org.hibernate.ejb.AbstractEntityManagerImpl.persist(AbstractEntityManagerImpl.java:675)
    at eu.paedrtx.register.server.repository.Repository.create(Repository.java:54)
    at eu.paedrtx.register.server.utility.Bootstrap.main(Bootstrap.java:75)
    ... 6 more
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 6.299s
[INFO] Finished at: Wed Apr 04 13:04:14 CEST 2012
[INFO] Final Memory: 9M/81M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.codehaus.mojo:exec-maven-plugin:1.2.1:java (default-cli) on project register: An exception occured while executing the Java class. null: InvocationTargetException: Unknown entity: eu.paedrtx.register.server.domain.PaymentDetails -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.codehaus.mojo:exec-maven-plugin:1.2.1:java (default-cli) on project register: An exception occured while executing the Java class. null
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:217)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:84)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:59)
    at org.apache.maven.lifecycle.internal.LifecycleStarter.singleThreadedBuild(LifecycleStarter.java:183)
    at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:161)
    at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:319)
    at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:156)
    at org.apache.maven.cli.MavenCli.execute(MavenCli.java:537)
    at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:196)
    at org.apache.maven.cli.MavenCli.main(MavenCli.java:141)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:290)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:230)
    at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:409)
    at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:352)
Caused by: org.apache.maven.plugin.MojoExecutionException: An exception occured while executing the Java class. null
    at org.codehaus.mojo.exec.ExecJavaMojo.execute(ExecJavaMojo.java:352)
    at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:101)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:209)
    ... 19 more
Caused by: java.lang.reflect.InvocationTargetException
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.codehaus.mojo.exec.ExecJavaMojo$1.run(ExecJavaMojo.java:297)
    at java.lang.Thread.run(Thread.java:680)
Caused by: java.lang.IllegalArgumentException: Unknown entity: eu.paedrtx.register.server.domain.PaymentDetails
    at org.hibernate.ejb.AbstractEntityManagerImpl.persist(AbstractEntityManagerImpl.java:675)
    at eu.paedrtx.register.server.repository.Repository.create(Repository.java:54)
    at eu.paedrtx.register.server.utility.Bootstrap.main(Bootstrap.java:75)
    ... 6 more
4

2 に答える 2

0

この問題を解決しました。問題は、test/resources でのテスト用と main/resources のアプリ用の 2 つの persistence.xml があったことです。test/resources の 1 つを削除し、アプリケーションの persistence.xml に別の永続ユニットを追加する必要がありました。

参照 : Maven でのテスト用に JPA を構成する方法

于 2012-04-20T10:57:11.820 に答える
0

ここで説明されているように、クラスパス引数execの代わりにゴールを使用してみてください https://www.mojohaus.org/exec-maven-plugin/examples/example-exec-for-Java-programs.htmljava

これにより JVM がフォークされ、多くの問題が修正される可能性があります。特に、重要なクラスローディングを行う Hibernate などのツールで問題が修正される可能性があります。これは、Maven がクラスローダー マジックを使用して正しいクラスパスをインプロセスで提供する必要がないためです (Maven は、単純なクラスパスで開始される Java プロセス自体であり、Maven ブートストラップ jar のみを含みます)。このようにして、-cp 引数を設定し、新しいプロセスをフォークします。診断が簡単で簡単です。

于 2012-04-14T00:45:42.900 に答える