2012-04-04 5 views
2

Ich habe ein Projekt, wo die Main-Method-Klasse "Bootstrap.class" im Ordner src/test ist. So verwende ich <classpathScope>test</classpathScope> der Lage sein,Maven exec plugin- wie man Klassen von main/java importiert, wenn classpathscope = test

mvn exec:java 

Mein Problem auszuführen: Ich erhalte eine „java.lang.IllegalArgumentException: Unknown Einheit:“ Ich bin dazu führen, bestimmte Klassen zu importieren, die an der Haupt/java befinden . Irgendwelche Gedanken darüber, wie ich das lösen kann?

Das ist mein Pom:

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

Der Stacktrace:

[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 
+1

Sieht aus wie ein Fehler mit Hibernate-Konfiguration - siehe [diese verwandten] (http://stackoverflow.com/questions/7887481/how-to-get-rid-of-java-lang- illegalargumentexception-unknown-entity-while-run) SO Frage – Raghuram

+0

das war auch mein erster Gedanke. Aber der Server und meine App starten ohne Probleme. Die genannte Ausnahme wird nur ausgelöst, wenn ich versuche, die Klasse "Bootstrap" (die sich in src/test befindet und eine Hauptmethode enthält) als Java-Anwendung auszuführen. – slowessam

+0

Wie @Raghuram sagte, sieht dies wie ein Hibernate conf-Problem aus - ich vermute, Sie haben keine XML-Mappings definiert oder Java-Annotationen auf die Klasse 'eu.paedrtx.register.server.domain.PaymentDetails' angewendet –

Antwort

0

Ich löste dieses Problem. das Problem war, dass ich 2 persistence.xml eine zum Testen in Test/Ressourcen und die andere für die App in Main/Ressourcen hatte. Ich musste das eine in Test/Ressourcen entfernen und eine andere Persistenz-Einheit in der persistence.xml der Anwendungen hinzufügen.

sehen: How to configure JPA for testing in Maven

0

Try exec Ziel statt java mit Classpath Argument zu verwenden, wie http://mojo.codehaus.org/exec-maven-plugin/examples/example-exec-for-java-programs.html

hier beschrieben Diese wird sich verzweigen JVM und kann viele Probleme beheben, insbesondere mit Tools wie Hibernate, die nicht-triviales Classloading durchführen. Das liegt daran, dass Maven nicht Classloader-Magie verwenden müsste, um den korrekten Klassenpfad in Bearbeitung zu liefern (Maven ist der Java-Prozess selbst, der mit trivialem Klassenpfad gestartet wird, der nur Maven-Bootstrap-Jar enthält). Auf diese Weise wird nur das Argument -cp aufgefüllt und der neue Prozess abgezweigt: einfach und einfach zu diagnostizieren.

Verwandte Themen