无法禁用空JAR的生成(maven-jar-plugin) [英] Unable to disable generation of empty JAR (maven-jar-plugin)

查看:426
本文介绍了无法禁用空JAR的生成(maven-jar-plugin)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有时,我的Talend Open Studio组件具有资源,但没有Java源(它们纯粹是元数据组件).在这种情况下,我需要禁用JAR文件的生成.

Sometimes, my Talend Open Studio components have resources but not Java sources (they are purely metadata components). I need to disable the generation of JAR files in such a case.

我通过以下方式配置了maven-jar-plugin:

I configured the maven-jar-plugin this way:

<plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-jar-plugin</artifactId>
        <version>2.4</version>
        <configuration>
            <forceCreation>false</forceCreation>
            <skipIfEmpty>true</skipIfEmpty>
            <useDefaultManifestFile>false</useDefaultManifestFile>
        </configuration>
      </plugin>

但是我仍然获得带有pom.properties,pom.cml,清单和一个仅包含类{}"的空文件App.class的$ {project.name} .jar文件.

but I still get the ${project.name}.jar file with pom.properties, pom.cml, the manifest and an empty file App.class containing only "class {}"

虽然我可以使用以下方式禁用所有Maven内容的包含:

While I can disable the includes of all maven stuff using this:

<archive>
<addMavenDescriptor>false</addMavenDescriptor>
</archive>

我仍然在其中包含清单文件的JAR中

I still get a JAR with the manifest file inside it

我是否配置了一些配置参数?

Are there some configuration parameters I misconfigured?

推荐答案

我自己找到了解决方案,即使这只是一种解决方法.如果/src/main/java目录不存在,我将使用delete antrun任务删除JAR:

I found the solution by myself, even if it's only a workaround. I delete the JAR using a delete antrun task if /src/main/java directory doesn't exist:

<!-- remove the empty JAR if not needed -->
<if>
    <not><available file="${basedir}/src/main/java" type="dir" /></not>
    <then>
    <delete file="${project.build.directory}/${project.name}-${project.version}.jar"/>
    </then>
</if>

此任务需要antcontrib才能正常工作,并且,如果您计划使用maven发行版本,则此操作将不起作用(但对于仅元数据组件(如Talend Open Studio插件)是可以的)

this task requires antcontrib to work properly and, ofc, it doesn't work if you plan to do releases with maven (but it's ok for metadata-only components, like Talend Open Studio plugins)

这篇关于无法禁用空JAR的生成(maven-jar-plugin)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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