[英]exec-maven-plugin hangs with execute Java main class
长期以来,我在Java中有一个小型应用程序,该应用程序使用hibernate SchemaExport来获取文件中的所有实际数据库结构。 使用Hibernate 4.X可以正常工作。
基本上我在Java Main.class中执行:
hibernateConfiguration.setProperty("hibernate.hbm2ddl.auto", "create");
hibernateConfiguration.setProperty("hibernate.dialect", dialect.getDialectClass());
hibernateConfiguration.setProperty("hibernate.connection.url", "jdbc:mysql://" + host + ":" + port + "/"
SchemaExport export = new SchemaExport(hibernateConfiguration);
export.setDelimiter(";");
export.setOutputFile(outputFile);
export.setFormat(true);
export.execute(false, false, false, true);
每当使用exec-maven-plugin
执行项目时,我都会启动它:
<!-- Creates the database script BEFORE testing -->
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.6.0</version>
<executions>
<execution>
<phase>compile</phase>
<goals>
<goal>java</goal>
</goals>
</execution>
</executions>
<configuration>
<mainClass>com.schemaexporter.main</mainClass>
<!-- <skip>true</skip> -->
<arguments>
[...] <!-- Some database connection parameters -->
</arguments>
</configuration>
</plugin>
现在,我刚刚更新到了Hibernate 5(5.2.17.Final)。 为此,我将代码更新为:
MetadataSources metadata = new MetadataSources(new StandardServiceRegistryBuilder().applySetting("hibernate.hbm2ddl.auto", "create")
.applySetting("hibernate.connection.driver_class", dialect.getDriver())
.applySetting("hibernate.dialect", dialect.getDialectClass())
.applySetting("hibernate.connection.driver_class", dialect.getDriver())
.applySetting("hibernate.connection.url", "jdbc:mysql://" + host + ":" + port + "/" + databaseName)
.applySetting("hibernate.connection.username", username)
.applySetting("hibernate.connection.password", password).build());
SchemaExport export = new SchemaExport();
export.setDelimiter(";");
export.setOutputFile(directory + File.separator + outputFile);
export.setFormat(true);
export.execute(EnumSet.of(TargetType.SCRIPT), SchemaExport.Action.CREATE, metadata.buildMetadata());
数据库脚本已正确创建。 但是exec-maven-process
挂起,没有继续执行其他操作。 对于挂起,我指的是maven进程永远不会结束并且不会继续进行下一阶段(执行单一测试)。
到目前为止,我一直尝试:
exec-maven-plugin
选项<async>true</async>
但没有任何变化。 System.exit(0)
添加到Main类,但是maven被杀死,并且不继续进行下一阶段。 Async process complete, exit value = 0
但未生成数据库脚本。 也许我可以更深入地研究脚本以查找错误,但这不是我的首选方式。 但是,我仍然不明白为什么将Hibernate 4更改为Hibernate 5会导致该过程无法结束。 我已经检查了代码(到处都是基本的System.out
),所有行都正确执行到最后,但该过程仍然有效。
有人知道Hibernate 5的行为变化是否导致这种不良行为吗?
如果我使用maven-antrun-plugin
执行同一类,则maven会继续执行。
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.8</version>
<executions>
<execution>
<phase>compile</phase>
<configuration>
<target>
<java failonerror="true" classname="com.schemaexporter.main">
<arg value="databaseName" />
<classpath refid="maven.compile.classpath" />
</java>
</target>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
这并非完全是问题的答案,而是一个不错的解决方法。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.