**最新情况**
我试图重现错误,并尝试创建一个最小、完整和可验证的示例。不幸的是,即使在执行从头开始重新启动技术之后,我也无法自己复制错误。
当我手动执行hibernate3 3:hbm2java命令时,应用程序就可以工作了。
尽管如此,它似乎并没有按计划工作。
当我运行应用程序时,会显示一个巨大的错误日志。下面是前几行:
at ClassRealm[plexus.core, parent: null] (via modules: org.eclipse.sisu.wire.WireModule -> org.eclipse.sisu.plexus.PlexusBindingModule)
while locating org.apache.maven.project.ProjectBuilder
while locating org.apache.maven.DefaultMaven
12 errors我已经把我的配置推到这个回购上了。它需要一个(在mem) MySQL db与pw:“密码”才能工作。
https://github.com/Weirdfishees/reverse-engineering.git
这是我的配置:
pom:
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.3</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>hibernate3-maven-plugin</artifactId>
<version>2.2</version>
<configuration>
<components>
<component>
<name>hbm2java</name>
<outputDirectory>src/main/java</outputDirectory>
<implementation>jdbcconfiguration</implementation>
</component>
</components>
<componentProperties>
<revengfile>/src/main/resources/META-INF/reveng.xml</revengfile>
<configurationfile>/src/main/resources/META-INF/hibernate.cfg.xml</configurationfile>
<jdk5>true</jdk5>
<ejb3>true</ejb3>
</componentProperties>
</configuration>
<dependencies>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.0.8</version>
</dependency>
<dependency>
<groupId>cglib</groupId>
<artifactId>cglib-nodep</artifactId>
<version>2.1_3</version>
</dependency>
</dependencies>
</plugin>
</plugins><dependencies>
<!-- ... -->
<!-- this is not needed for the example, but after executing hibernate3:hbm2java, no compile errors will show -->
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>5.1.0.Final</version>
</dependency>
<!-- to prevent error SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder". -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<version>1.7.18</version>
</dependency>
<!-- ... -->
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-embedder</artifactId>
<version>3.3.3</version>
</dependency>
<dependency>
<groupId>org.eclipse.aether</groupId>
<artifactId>aether-connector-wagon</artifactId>
<version>0.9.0.M2</version>
</dependency>
<dependency>
<groupId>org.apache.maven.wagon</groupId>
<artifactId>wagon-http-lightweight</artifactId>
<version>2.5</version>
</dependency>hibernate.cfg.xml
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE hibernate-configuration SYSTEM "http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="hibernate.connection.url">jdbc:mysql://localhost:3306/sakila?autoreconnect=true&usessl=false?autoreconnect=true&usessl=false</property>
<property name="hibernate.connection.username">root</property>
<property name="hibernate.connection.password">password</property>
<property name="hibernate.show_sql">true</property>
<property name="hibernate.current_session_context_class">thread</property>
</session-factory>
</hibernate-configuration>reveng.xml
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE hibernate-reverse-engineering SYSTEM "http://hibernate.sourceforge.net/hibernate-reverse-engineering-3.0.dtd">
<hibernate-reverse-engineering>
<schema-selection match-schema="sakila"/>
<table-filter match-name=".*" package="nl.sander.m.localhost.sakila"/>和application.java
package reverseengineer;
import java.io.File;
import org.apache.maven.cli.MavenCli;
public class Application {
public static void main(String[] args) {
System.setProperty("maven.multiModuleProjectDirectory", new File(".").getAbsolutePath());
MavenCli cli = new MavenCli();
cli.doMain(new String[]{"hibernate3:hbm2java"}, ".", System.out, System.out);
}
}我的问题没变。
如何以编程方式运行hibernate3 3:hbm2java?
-不能复制-但是更多的信息--
引言
大家好,堆栈溢出用户,我有一个关于Maven Embedder使用的问题。
在我总结到实际的代码部分之前,我想和大家分享一下我的问题的上下文。
我正在构建一个接收用户输入的GUI应用程序(javaFX)。基于此输入,应用程序动态生成两个hibernate配置文件(hibernate.cfg.xml和reveng.xml)。基于这些配置文件(提供连接详细信息),应用程序的下列所需功能是automatically (没有用户交互),反向工程数据库,并创建所有表的POJO类(自下而上开发)。
当我手动执行maven 3:hbm2java参数时(使用命令行或只在-> maven构建时运行eclipse )。->目标mvn 3:hbm2java)我想要的所有类都创建了所需的包。
但是,目标是以编程方式执行mvn 3:hbm2java,而不是手动执行。
研究
我尝试了以下几种选择:
Running Maven from Java code in Windows?
private void executeHbmToJava() {
try {
Runtime.getRuntime().exec("cmd \\c hibernate3:hbm2java");
} catch (IOException e) {
e.printStackTrace();
}
}此选项不会抛出任何错误,但是程序中似乎不会发生任何事情(在刷新eclipse中的视图之后,所需的类就不存在了.)
即使这个选项有效,由于应用程序的上下文,我更喜欢使用Maven Embedder (应用程序将使用跨平台)。
此外,我更喜欢使用而不是来使用来自user3254289的答案,并建议使用Maven调用。
问题
基于MariuszS对How to run maven from java?问题的回答
我已将我的应用程序配置如下:
pom依赖关系:
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-embedder</artifactId>
<version>3.1.1</version>
</dependency>
<dependency>
<groupId>org.eclipse.aether</groupId>
<artifactId>aether-connector-wagon</artifactId>
<version>0.9.0.M2</version>
</dependency>
<dependency>
<groupId>org.apache.maven.wagon</groupId>
<artifactId>wagon-http-lightweight</artifactId>
<version>2.5</version>
</dependency>使用从https://github.com/mariuszs/maven-cli-example获取的下列(调整)方法
private void executeHbmToJava() {
System.out.println(new File(".").getAbsolutePath());
MavenCli cli = new MavenCli();
cli.doMain(new String[]{"clean", "install"}, ".", System.out, System.out);
// desired is the following
// cli.doMain(new String[]{"hibernate3:hbm2java"}, ".", System.out, System.out);
}出现以下错误:
Exception in thread "JavaFX Application Thread" java.lang.RuntimeException: java.lang.reflect.InvocationTargetException
Caused by: java.lang.NoSuchMethodError: org.codehaus.plexus.DefaultPlexusContainer.<init>(Lorg/codehaus/plexus/ContainerConfiguration;[Lcom/google/inject/Module;)V我对MAVEN_HOME变量执行了一些检查。由于我可以在cmd和eclipse中执行mvn命令,所以我认为这些设置是正确的(如果我错了,请纠正我)。
Maven
$ mvn -v
Apache Maven 3.3.3 (7994120775791599e205a5524ec3e0dfe41d4a06; 2015-04- 22T13:57:37+02:00)
Maven home: C:\Program Files\Apache Software Foundation\apache-maven-3.3.3\bin\..
Java version: 1.8.0_45, vendor: Oracle Corporation
Java home: C:\Program Files\Java\jdk1.8.0_45\jre
Default locale: nl_NL, platform encoding: Cp1252
OS name: "windows 8.1", version: "6.3", arch: "amd64", family: "dos"Java
$ java -version
java version "1.8.0_71"
Java(TM) SE Runtime Environment (build 1.8.0_71-b15)
Java HotSpot(TM) 64-Bit Server VM (build 25.71-b15, mixed mode)有谁知道如何克服这个错误并实现我想要的目标:从java运行时自动触发mvn hibernate3 3:hbm2java??
TL;DR
如何在使用Maven Embedder时修复java.lang.NoSuchMethodError?
Caused by: java.lang.NoSuchMethodError: org.codehaus.plexus.DefaultPlexusContainer.<init> (Lorg/codehaus/plexus/ContainerConfiguration;[Lcom/google/inject/Module;)V给予:
private void executeHbmToJava() {
System.out.println(new File(".").getAbsolutePath());
MavenCli cli = new MavenCli();
cli.doMain(new String[]{"clean", "install"}, ".", System.out, System.out);
// desired is the following
// cli.doMain(new String[]{"hibernate3:hbm2java"}, ".", System.out, System.out);
}发布于 2016-02-28 18:48:03
我设法解决了这个问题。感谢Tunaki链接到最小、完整和可验证的示例。通过运用这些技巧,我设法解决了这个问题。
根据Mykel Alvis https://stackoverflow.com/a/30439890的回答,我调整了pom如下:
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<version>1.7.5</version>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-embedder</artifactId>
<version>3.3.3</version>
</dependency>
<dependency>
<groupId>org.eclipse.aether</groupId>
<artifactId>aether-connector-basic</artifactId>
<version>1.0.2.v20150114</version>
</dependency>
<dependency>
<groupId>org.eclipse.aether</groupId>
<artifactId>aether-transport-wagon</artifactId>
<version>1.0.2.v20150114</version>
</dependency>
<dependency>
<groupId>org.apache.maven.wagon</groupId>
<artifactId>wagon-http</artifactId>
<version>2.9</version>
</dependency>
<dependency>
<groupId>org.apache.maven.wagon</groupId>
<artifactId>wagon-provider-api</artifactId>
<version>2.9</version>
</dependency>
<dependency>
<groupId>org.apache.maven.wagon</groupId>
<artifactId>wagon-http-lightweight</artifactId>
<version>2.9</version>
</dependency>此外,我禁用了应用程序的这一部分未使用的所有其他依赖项。以上依赖项和注释未使用依赖项的结合解决了这个问题。
工作提取版本在https://github.com/Weirdfishees/reverse-engineering.git上。
https://stackoverflow.com/questions/35684728
复制相似问题