Maven资源文件,将java类文件和属性文件放在同一目录中 [英] Maven resource files, put java class files and property files in same directory

查看:102
本文介绍了Maven资源文件,将java类文件和属性文件放在同一目录中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在同一目录中有java类文件和属性文件。



src / main / java / com / berlin / Test.class



src / main / java / com / berlin / Test.properties



使用我构建的maven jar和maven目标,我想要这些出现在同一目录中。但当我做'mvn package'时,maven将类文件和属性文件放在不同的地方。



..输出:
jar -tvf file.jar :



Sat Jun 11 08:24:32 EDT 2011 main / java / com / berlin / Test.properties



<我希望:
星期六6月11日08:24:32 EDT 2011 com / berlin / Test.properties
星期六6月11日08:24:32 EDT 2011 com / berlin / Test.class



...



我的pom的一部分:

 < build> 
< finalName> $ {project.artifactId}< / finalName>
< sourceDirectory> src< / sourceDirectory>
< testSourceDirectory> test< / testSourceDirectory>
< resources>
< resource>
< directory> src< / directory>
< includes>
< include> **< / include>
< / includes>
<排除>
< exclude> ** / * .java< / exclude>
< /排除>
< / resource>
< / resources>
< plugins>
< plugin>
< artifactId> maven-compiler-plugin< / artifactId>
< configuration>
< source> $ {java.source.version}< / source>
< target> $ {java.target.version}< / target>
< / configuration>
< / plugin>
< plugin>
< artifactId> maven-surefire-plugin< / artifactId>
< configuration>
< skipTests> true< / skipTests>
< / configuration>
< / plugin>
< / plugins>


解决方案

出于Maven的原因,你应该将属性文件放入src / main / resources,而不是在src / main / java目录中(保持相同的子文件夹结构)。



这就是说,得到你想要的东西你需要更换(在你的pom.xml中) src ,带 src / main / java 。未经测试,但如果您有问题请分享。


I have java class files and property files in the same directory.

src/main/java/com/berlin/Test.class

src/main/java/com/berlin/Test.properties

With the maven jar I build and the maven target, I want these to appear in the same directory. but maven is placing the class files and property files in different places when I do 'mvn package'.

.. Output: jar -tvf file.jar:

Sat Jun 11 08:24:32 EDT 2011 main/java/com/berlin/Test.properties

I want: Sat Jun 11 08:24:32 EDT 2011 com/berlin/Test.properties Sat Jun 11 08:24:32 EDT 2011 com/berlin/Test.class

...

Part of my pom:

<build>
        <finalName>${project.artifactId}</finalName>
        <sourceDirectory>src</sourceDirectory>
        <testSourceDirectory>test</testSourceDirectory>
        <resources>
            <resource>
                <directory>src</directory>
                <includes>
                    <include>**</include>
                </includes>
                <excludes>
                    <exclude>**/*.java</exclude>
                </excludes>
            </resource>
        </resources>
<plugins>
            <plugin>
                <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                    <source>${java.source.version}</source>
                    <target>${java.target.version}</target>
                </configuration>
            </plugin>           
            <plugin>
                <artifactId>maven-surefire-plugin</artifactId>
                <configuration>
                    <skipTests>true</skipTests>
                </configuration>
            </plugin>            
        </plugins>

解决方案

For the Maven reasons, you should place properties file into src/main/resources, not in src/main/java directory (keeping the same subfolder structure).

That being said, to get what you want you need to replace (in your pom.xml) src with src/main/java. Not tested, but if you have problems please share.

这篇关于Maven资源文件,将java类文件和属性文件放在同一目录中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆