加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > Java > 正文

java – 有没有办法将mywebapp-1.0-SNAPSHOT-classes.jar从maven

发布时间:2020-12-15 04:11:44 所属栏目:Java 来源:网络整理
导读:根据 maven-war-plugin FAQ, If you can’t move the classes to another project,you can deploy the classes and resources included in your webapp as an “attached” artifact,with a classifier,by using the following configuration: project ... a
根据 maven-war-plugin FAQ,

If you can’t move the classes to another project,you can deploy the classes and resources included in your webapp as an “attached” artifact,with a classifier,by using the following configuration:

<project>
  ...
  <artifactId>mywebapp</artifactId>
  <version>1.0-SNAPSHOT</version>
  ...
  <build>
    <plugins>
      <plugin>
        <artifactId>maven-war-plugin</artifactId>
        <version>2.3</version>
        <configuration>
          <attachClasses>true</attachClasses>
        </configuration>
      </plugin>
    </plugins>
  </build>
  ...
</project>

This will result in two artifacts being deployed: mywebapp-1.0-SNAPSHOT.war and mywebapp-1.0-SNAPSHOT-classes.jar.

有没有办法可以获得mywebapp-1.0-SNAPSHOT.jar而不是mywebapp-1.0-SNAPSHOT-classes.jar?

更新::

我想要生成战争以及jar.虽然我可以通过应用Changing packaging based on active profile in pom中提到的配置文件来做到这一点.但我很想知道上面的问题.

解决方法

简答:不,你不能.

通过查看maven-war-plugin源代码,在WarMojo.java(第292行)中,您可以通过简单地修改maven-war-plugin配置来看到无法满足您的要求:

protected static File getTargetFile( File basedir,String finalName,String classifier,String type )
    {
        if ( classifier == null )
        {
            classifier = "";
        }
        else if ( classifier.trim().length() > 0 && !classifier.startsWith( "-" ) )
        {
            classifier = "-" + classifier;
        }

        return new File( basedir,finalName + classifier + "." + type );
    }

由于classesClassifier参数默认为“classes”,因此您无法修改此行为:分类器永远不会为null.

您可以在生成文件后重命名该文件,也可以修改maven-war-plugin的源代码,并将其用作自定义插件.

作为最后的考虑,不建议使用null classesClassifier:它可能会产生误导.我不知道你的项目要求.

希望能帮助到你.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读