[英]exec-maven-plugin hangs with execute Java main class
For a long time, I have a small application in java that uses hibernate SchemaExport to get all actual database structure in a file. 长期以来,我在Java中有一个小型应用程序,该应用程序使用hibernate SchemaExport来获取文件中的所有实际数据库结构。 This was working fine with Hibernate 4.X.
使用Hibernate 4.X可以正常工作。
Basically I execute in a java Main.class: 基本上我在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);
And I launch it each time the project is executed using exec-maven-plugin
: 每当使用
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>
Now, I have just updated to Hibernate 5 (5.2.17.Final). 现在,我刚刚更新到了Hibernate 5(5.2.17.Final)。 And for this purpose, I have updated my code to:
为此,我将代码更新为:
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());
The database script is created correctly. 数据库脚本已正确创建。 But the
exec-maven-process
hangs and not continue to other actions. 但是
exec-maven-process
挂起,没有继续执行其他操作。 For hanging, I refer to that the maven process never ends and not continue with next phases (executing unitary tests). 对于挂起,我指的是maven进程永远不会结束并且不会继续进行下一阶段(执行单一测试)。
What I have tried until now: 到目前为止,我一直尝试:
exec-maven-plugin
option <async>true</async>
but nothing changes. exec-maven-plugin
选项<async>true</async>
但没有任何变化。 System.exit(0)
to the Main class, but maven is killed and not continues to next phases. System.exit(0)
添加到Main类,但是maven被杀死,并且不继续进行下一阶段。 Async process complete, exit value = 0
but the database script is not generated. Async process complete, exit value = 0
但未生成数据库脚本。 Maybe I can go deeper on the script to find the error, but is not my preferred way. Still, I do not understand why changing Hibernate 4 to Hibernate 5 causes the process not to end. 但是,我仍然不明白为什么将Hibernate 4更改为Hibernate 5会导致该过程无法结束。 I have checked the code (basic
System.out
everywhere), and all lines are executed correctly until the end but the process is still live. 我已经检查了代码(到处都是基本的
System.out
),所有行都正确执行到最后,但该过程仍然有效。
Does anybody knows if there is a change of behaviour with Hibernate 5 that causes this undesired behaviour? 有人知道Hibernate 5的行为变化是否导致这种不良行为吗?
If I execute the same class using maven-antrun-plugin
seems that maven continues executing. 如果我使用
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>
It is not exactly an answer for the question, but a good workaround. 这并非完全是问题的答案,而是一个不错的解决方法。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.