简体   繁体   English

DTD在Eclipse中的项目目标路径中显示,但在通过Maven命令行使用时不显示

[英]DTDs show up in project target path in Eclipse but not when using via Maven command line

I wasn't sure what the best title is so if anyone has a better suggestion, fire away. 我不确定最好的标题是什么,所以如果有人有更好的建议,请开除。

I'm not sure what information I should be providing, so I'll tell you what is happening. 我不确定应该提供什么信息,所以我将告诉您正在发生的事情。

I have some unit tests that pass fine in Eclipse. 我有一些可以在Eclipse中顺利通过的单元测试。 In these tests, there's some XML that's being validated against a custom built DTD (a slightly modified Apelon DTS DTSConcept if anyone is familiar). 在这些测试中,有一些XML已针对自定义的DTD(如果有人熟悉的话,会稍作修改的Apelon DTS DTSConcept)进行验证。 In eclipse, when I run these tests, I can see in my target path for the project that the dtds show up. 在Eclipse中,当我运行这些测试时,我可以在目标路径中看到dtds显示的项目。

So, dir1/dir2/dtds/myDtd.dtd exists in the target path of the project. 因此,dir1 / dir2 / dtds / myDtd.dtd存在于项目的目标路径中。

However, if I run the unit tests on the command line with maven (mvn clean test), these tests failed because of a MalformedURLException. 但是,如果我使用maven在命令行上运行单元测试(mvn clean测试),则由于MalformedURLException,这些测试将失败。 I was able to get rid of DTD validation and the tests passed, so I knew it had something to do with that. 我能够摆脱DTD验证,并通过了测试,所以我知道它与此有关。 After many things tried, for whatever reason I looked in the target path of the project. 经过许多尝试之后,无论出于何种原因,我都在项目的目标路径中进行查找。 Now, dir1/dir2/dtds/myDtd.dtd did NOT exist. 现在,dir1 / dir2 / dtds / myDtd.dtd不存在。 That seems to be why I'm getting the exception -- the file doesn't exist. 这似乎就是为什么我遇到异常-文件不存在的原因。

I realize this may be too vague, but is there anything that you can think of why I might be having these different results running in Eclipse versus using the Maven command line? 我意识到这可能太含糊,但是您有什么可以想到的原因,为什么我可能会在Eclipse中运行这些不同的结果而不是使用Maven命令行?

I will provide more information as requested, but I wasn't sure what exactly to include. 我会根据要求提供更多信息,但是我不确定要包含什么内容。

Thanks for any assistance. 谢谢你的帮助。

EDIT: Okay, it seems that the problem is that maven simply doesn't copy the DTDs over to the target directory when building. 编辑:好的,看来问题是在构建时Maven根本不会将DTD复制到目标目录。 I may google/ask a separate question for this, but how would I ensure Maven copies those files correctly? 我可以为此谷歌/询问一个单独的问题,但是我将如何确保Maven正确复制这些文件?

Considering that the file is a DTD (not a Java ressource) I think it would be better to put it in the resources/META-INF folder of a default maven project. 考虑到该文件是DTD(不是Java资源),我认为最好将它放在默认Maven项目的resources / META-INF文件夹中。

By default, maven copies all files under resources to the target destination during the process-resources phase, so you could get rid of extra plugin configuration. 默认情况下,maven在流程资源阶段将资源下的所有文件复制到目标位置,因此您可以摆脱多余的插件配置。

It would also require modifying your XML file to point to the new location. 它还需要修改XML文件以指向新位置。

Here's what it would look like in typical maven project strucutre: 这是典型的Maven项目strucutre的外观:

my-app
|-- pom.xml
`-- src
    |-- main
    |   |-- java
    |   |   `-- com
    |   |       `-- mycompany
    |   |           `-- app
    |   |               `-- App.java
    |   `-- resources
    |       `-- META-INF
    |           `-- application.properties
    [            -- myDtd.dtd
    `-- test
        `-- java
            `-- com
                `-- mycompany
                    `-- app
                        `-- AppTest.java

Well, I figured it out :) In case anyone runs into a similar issue and can't quite figure out the plugin initially (like me), here's what worked for me: 好吧,我想出了好方法:)如果有人遇到类似的问题,而最初却无法完全弄清插件(像我一样),这对我有用:

<plugin>
            <!-- Necessary for maven to copy the DTDs to the correct directory. -->
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-resources-plugin</artifactId>
            <executions>
                <execution>
                    <id>copy-resources</id>
                    <!-- here the phase you need -->
                    <phase>compile</phase>
                    <goals>
                        <goal>copy-resources</goal>
                    </goals>
                    <configuration>
                        <outputDirectory>target/classes/com/work/hin/dts/dtd/query</outputDirectory>
                        <resources>
                            <resource>
                                <directory>src/main/java/com/work/hin/dts/dtd/query</directory>
                                <includes>
                                    <include>**/*.dtd</include>
                                </includes>
                                <filtering>true</filtering>
                            </resource>
                        </resources>
                    </configuration>
                </execution>
            </executions>
        </plugin>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM