java - hyperjaxb3 不生成文件

标签 java xml hibernate maven hyperjaxb

我正在尝试通过学习来学习 hyperjaxb this tutorial .我按照所有说明进行操作,一直到标题部分 What was Generated?。这包括以下步骤:

1.) download the <a href="http://confluence.highsource.org/display/HJ3/Downloads">Basic Project Template for Hibernate and Maven</a>
2.) unzip the file
3.) install the xml and xsd files in the assigned locations
4.) open up `cmd.exe`
5.) navigate to the directory of the unzipped root folder
6.) run mvn clean install  

但是没有生成任何东西。没有/generated-sources/xjc目录,也没有PurchaseOrderType.java。我对整个目录结构进行了关键字搜索,以确认在运行 mvn clean install 后这些资源不存在。我还将目录结构导入到一个新的 eclipse maven 项目中,并在新的 eclipse maven 项目中尝试了 run as...maven cleanrun as...maven build,但同样缺乏结果。

我该怎么做才能让本教程生成预期生成的文件?

此外,是否有更好的方法从 xsd 生成 JPA 实体?


编辑:

按照@kapep 的建议,我尝试了 mvn generate-sources 并得到了以下结果:

然后我再次尝试 mvn clean install,得到以下结果:

您可以在打印屏幕中看到缺少 org.apache.maven.plugins:maven-compiler-plugin 的警告。我在我机器上的 .m2 存储库中找到了相应的文件夹并将其删除,然后从 eclipse 中执行了一个 maven update project 以重新下载该库。然后,我又执行了一次 mvn clean install,但仍然没有结果。没有生成任何内容,没有 java 文件,没有 generated-sources 目录。没有什么。

我还能尝试什么?


第二次编辑:

教程应用程序仍然没有生成预期的文件,但是,我能够通过将 pom 的 maven-compiler-plugin 部分更改为以下内容来消除打印屏幕中的警告消息:

<plugin>
    <inherited>true</inherited>
    <artifactId>maven-compiler-plugin</artifactId>
    <version>2.3.2</version>
    <configuration>
        <source>1.6</source>
        <target>1.6</target>
    </configuration>
</plugin>  

请注意,除了指定版本外,我还将sourcetarget1.5更改为1.6,根据@Todd 的建议 in this posting .我假设这些指的是 JDK 版本。我的安装使用 JDK 1.6。我不知道这是否会导致任何问题。

我还能尝试什么?

最佳答案

更新

最后,OP 似乎在项目的根目录而不是 target\generated-source\xjc 中寻找生成的类,尽管 tutorial 清楚地说明了在哪里寻找:

If you browse the target/generated-sources/xjc directory, you'll find few generated java files, for instance PurchaseOrderType.java.


再一次,我不明白这个。适合我。

我的步骤是:

这就是我得到的,干净整洁:

[INFO] Scanning for projects...
[WARNING] 
[WARNING] Some problems were encountered while building the effective model for org.jvnet.hyperjaxb3:hyperjaxb3-ejb-template-basic-maven:jar:0.6.0
[WARNING] 'build.plugins.plugin.version' for org.apache.maven.plugins:maven-compiler-plugin is missing. @ line 75, column 12
[WARNING] 
[WARNING] It is highly recommended to fix these problems because they threaten the stability of your build.
[WARNING] 
[WARNING] For this reason, future Maven versions might no longer support building such malformed projects.
[WARNING] 
[INFO] 
[INFO] Using the builder org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder with a thread count of 1
[INFO]                                                                         
[INFO] ------------------------------------------------------------------------
[INFO] Building Hyperjaxb3 Samples [po-initial:maven] 0.6.0
[INFO] ------------------------------------------------------------------------
[INFO] 
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ hyperjaxb3-ejb-template-basic-maven ---
[INFO] Deleting C:\Projects\workspaces\hj3\dist\hyperjaxb3-ejb-template-basic-0.6.0\target
[INFO] 
[INFO] --- maven-hyperjaxb3-plugin:0.6.0:generate (default) @ hyperjaxb3-ejb-template-basic-maven ---
[INFO] Sources are not up-to-date; XJC execution will be executed.
[WARNING] According to the Java Persistence API specification, section 2.1, entities must be top-level classes:
"The entity class must be a top-level class."
Your JAXB model is not customized as with top-level local scoping, please use the <jaxb:globalBinding localScoping="toplevel"/> global bindings customization.
        org.jvnet.hyperjaxb3.ejb.plugin.EjbPlugin

[WARNING] According to the Java Persistence API specification, section 2.1, entities must implement the serializable interface:
"If an entity instance is to be passed by value as a detached object
(e.g., through a remote interface), the entity class must implement
 the Serializable interface."
Your JAXB model is not customized as serializable, please use the <jaxb:serializable/> global bindings customization element to make your model serializable.
        org.jvnet.hyperjaxb3.ejb.plugin.EjbPlugin

[INFO] 
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ hyperjaxb3-ejb-template-basic-maven ---
[WARNING] Using platform encoding (Cp1252 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] Copying 2 resources
[INFO] Copying 0 resource
[INFO] Copying 1 resource
[INFO] 
[INFO] --- maven-compiler-plugin:2.5.1:compile (default-compile) @ hyperjaxb3-ejb-template-basic-maven ---
[WARNING] File encoding has not been set, using platform encoding Cp1252, i.e. build is platform dependent!
[INFO] Compiling 5 source files to C:\Projects\workspaces\hj3\dist\hyperjaxb3-ejb-template-basic-0.6.0\target\classes
[INFO] 
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ hyperjaxb3-ejb-template-basic-maven ---
[WARNING] Using platform encoding (Cp1252 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] Copying 2 resources
[INFO] 
[INFO] --- maven-compiler-plugin:2.5.1:testCompile (default-testCompile) @ hyperjaxb3-ejb-template-basic-maven ---
[WARNING] File encoding has not been set, using platform encoding Cp1252, i.e. build is platform dependent!
[INFO] Compiling 5 source files to C:\Projects\workspaces\hj3\dist\hyperjaxb3-ejb-template-basic-0.6.0\target\test-classes
[INFO] 
[INFO] --- maven-surefire-plugin:2.12.4:test (default-test) @ hyperjaxb3-ejb-template-basic-maven ---
[INFO] Surefire report directory: C:\Projects\workspaces\hj3\dist\hyperjaxb3-ejb-template-basic-0.6.0\target\surefire-reports

-------------------------------------------------------
 T E S T S
-------------------------------------------------------
Running RoundtripTest
Detected [file:/C:/Projects/workspaces/hj3/dist/hyperjaxb3-ejb-template-basic-0.6.0/target/classes/META-INF/persistence.xml].
    RoundtripTest

Loading entity manager factory properties.
    RoundtripTest

Loading entity manager factory properties from [file:/C:/Projects/workspaces/hj3/dist/hyperjaxb3-ejb-template-basic-0.6.0/target/test-classes/persistence.properties].
    RoundtripTest

Testing samples.
    RoundtripTest

Sample directory [C:\Projects\workspaces\hj3\dist\hyperjaxb3-ejb-template-basic-0.6.0\src\test\samples].
    RoundtripTest

Testing sample [po.xml].
    RoundtripTest

Unmarshalling.
    RoundtripTest

Opening session.
    RoundtripTest

Saving the object.
    RoundtripTest

Opening session.
    RoundtripTest

Loading the object.
    RoundtripTest

Closing the session.
    RoundtripTest

Initial object:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<purchaseOrder orderDate="1999-10-20">
    <shipTo country="US">
        <name>Alice Smith</name>
        <street>123 Maple Street</street>
        <city>Mill Valley</city>
        <state>CA</state>
        <zip>90952</zip>
    </shipTo>
    <billTo country="US">
        <name>Robert Smith</name>
        <street>8 Oak Avenue</street>
        <city>Old Town</city>
        <state>PA</state>
        <zip>95819</zip>
    </billTo>
    <comment>Hurry, my lawn is going wild!</comment>
    <items>
        <item partNum="872-AA">
            <productName>Lawnmower</productName>
            <quantity>1</quantity>
            <USPrice>148.95</USPrice>
            <comment>Confirm this is electric</comment>
        </item>
        <item partNum="926-AA">
            <productName>Baby Monitor</productName>
            <quantity>1</quantity>
            <USPrice>39.98</USPrice>
            <shipDate>1999-05-21</shipDate>
        </item>
    </items>
</purchaseOrder>

    RoundtripTest

Source object:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<purchaseOrder orderDate="1999-10-20" Hjid="1">
    <shipTo country="US" Hjid="2">
        <name>Alice Smith</name>
        <street>123 Maple Street</street>
        <city>Mill Valley</city>
        <state>CA</state>
        <zip>90952</zip>
    </shipTo>
    <billTo country="US" Hjid="1">
        <name>Robert Smith</name>
        <street>8 Oak Avenue</street>
        <city>Old Town</city>
        <state>PA</state>
        <zip>95819</zip>
    </billTo>
    <comment>Hurry, my lawn is going wild!</comment>
    <items Hjid="1">
        <item partNum="872-AA" Hjid="1">
            <productName>Lawnmower</productName>
            <quantity>1</quantity>
            <USPrice>148.95</USPrice>
            <comment>Confirm this is electric</comment>
        </item>
        <item partNum="926-AA" Hjid="2">
            <productName>Baby Monitor</productName>
            <quantity>1</quantity>
            <USPrice>39.98</USPrice>
            <shipDate>1999-05-21</shipDate>
        </item>
    </items>
</purchaseOrder>

    RoundtripTest

Result object:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<purchaseOrder orderDate="1999-10-20" Hjid="1">
    <shipTo country="US" Hjid="2">
        <name>Alice Smith</name>
        <street>123 Maple Street</street>
        <city>Mill Valley</city>
        <state>CA</state>
        <zip>90952</zip>
    </shipTo>
    <billTo country="US" Hjid="1">
        <name>Robert Smith</name>
        <street>8 Oak Avenue</street>
        <city>Old Town</city>
        <state>PA</state>
        <zip>95819</zip>
    </billTo>
    <comment>Hurry, my lawn is going wild!</comment>
    <items Hjid="1">
        <item partNum="872-AA" Hjid="1">
            <productName>Lawnmower</productName>
            <quantity>1</quantity>
            <USPrice>148.95</USPrice>
            <comment>Confirm this is electric</comment>
        </item>
        <item partNum="926-AA" Hjid="2">
            <productName>Baby Monitor</productName>
            <quantity>1</quantity>
            <USPrice>39.98</USPrice>
            <shipDate>1999-05-21</shipDate>
        </item>
    </items>
</purchaseOrder>

    RoundtripTest

Checking the document identity.
    RoundtripTest

Finished testing sample [po.xml].
    RoundtripTest

Finished testing samples.
    RoundtripTest

Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 2.456 sec

Results :

Tests run: 1, Failures: 0, Errors: 0, Skipped: 0

[INFO] 
[INFO] --- maven-jar-plugin:2.4:jar (default-jar) @ hyperjaxb3-ejb-template-basic-maven ---
[INFO] Building jar: C:\Projects\workspaces\hj3\dist\hyperjaxb3-ejb-template-basic-0.6.0\target\hyperjaxb3-ejb-template-basic-maven-0.6.0.jar
[INFO] 
[INFO] --- maven-install-plugin:2.4:install (default-install) @ hyperjaxb3-ejb-template-basic-maven ---
[INFO] Installing C:\Projects\workspaces\hj3\dist\hyperjaxb3-ejb-template-basic-0.6.0\target\hyperjaxb3-ejb-template-basic-maven-0.6.0.jar to C:\Repository\org\jvnet\hyperjaxb3\hyperjaxb3-ejb-template-basic-maven\0.6.0\hyperjaxb3-ejb-template-basic-maven-0.6.0.jar
[INFO] Installing C:\Projects\workspaces\hj3\dist\hyperjaxb3-ejb-template-basic-0.6.0\pom.xml to C:\Repository\org\jvnet\hyperjaxb3\hyperjaxb3-ejb-template-basic-maven\0.6.0\hyperjaxb3-ejb-template-basic-maven-0.6.0.pom
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 11.185 s
[INFO] Finished at: 2014-10-09T00:56:18+01:00
[INFO] Final Memory: 22M/101M
[INFO] ------------------------------------------------------------------------

我不知道为什么它对你不起作用。请发布 mvn clean install -Xdir/b/s 日志,以便我检查您的设置。

关于java - hyperjaxb3 不生成文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25676731/

相关文章:

Python XML 解析器将数字加载为字符串

java - Android Studio 中单选按钮 onClick() 的替代选项

java - Hibernate - 如何在 JSP 表中显示对象列表?

java - 如何在某些情况下允许忽略 javax.validation

java - 构造具有给定预序的二叉树

java - 删除字符串中所有以 "http"开头的单词?

java - io.qameta.allure.testng.AllureTestNg 无法实例化

java - java中hibernate使用的java列表接口(interface)的语法?

java - Gradle Zip:保留目录结构

java - 泄漏的 Java 库慢慢占用所有内存,没有抛出 OutOfMemoryException,解决方法?