如何用maven只构建java文件?(How to build only java files with maven?)

编程入门 行业动态 更新时间:2024-10-21 09:09:44
如何用maven只构建java文件?(How to build only java files with maven?)

我的项目层次结构如下所示

myProject--->POM.xml myProject--->src--->main--->java---> java files under different sub directories myProject--->src--->main--->resources---> non java files under different sub directories myProject--->src--->main--->webApp---> non java files under different sub directories

我想构建项目,以便它只构建java文件,并在最终的jar文件中只包含相应的类文件

这是我在pom.xml中的相关代码,但它没有找到任何要编译的java文件。 我不确定我在这里缺少什么?

<build> <pluginManagement> <plugins> <plugin> <artifactId>maven-jar-plugin</artifactId> <configuration> <verbose>true</verbose> <includes> <include>**/*.java</include> </includes> </configuration> </plugin> </plugins> </pluginManagement> </build>

更新: -我收到信息消息为No sources to compile但子目录中有java文件

i have my project hierarchy like below

myProject--->POM.xml myProject--->src--->main--->java---> java files under different sub directories myProject--->src--->main--->resources---> non java files under different sub directories myProject--->src--->main--->webApp---> non java files under different sub directories

i want to build the project so that it builds only java files and only include the corresponding class files in final jar file

Here is my relevant code from pom.xml but it does not find any java files to compile. I am not sure what i am missing here?

<build> <pluginManagement> <plugins> <plugin> <artifactId>maven-jar-plugin</artifactId> <configuration> <verbose>true</verbose> <includes> <include>**/*.java</include> </includes> </configuration> </plugin> </plugins> </pluginManagement> </build>

UPDATE:- I get info message as No sources to compile but there are java file in subdirectories

最满意答案

我假设你想摆脱像.xml , .xhtml , .properties等文件? 尝试添加

<resources/>

或者您可以禁用执行,请参见此处:

如何将Maven构建速度提高30%:抑制未使用的插件执行

取消resource:default-resources和war:default-war执行。

实际上你必须这样做,因为war插件不服从<resources> 。

仍然, jar插件将添加META-INF目录。 可以在使用clean插件的package阶段之前删除它。

查看此页面以获得进一步研究。

I assume that you want to get rid of files like .xml, .xhtml, .properties etc? Try to add

<resources/>

Or you can disable the executions, see here:

How to speed up Maven builds by 30 %: Supressing unused plugin executions

Suppress the resource:default-resources and war:default-war executions.

Actually you'll have to, because the war plugin doesn't obey <resources>.

Still, the jar plugin will add META-INF dir. That can be deleted before the package phase using the clean plugin.

Check this page for further studies.

更多推荐

本文发布于:2023-08-05 08:15:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1428881.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:如何用   文件   maven   java   build

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!