Java – is there any way to add mywebapp-1.0-snapshot-classes Jar from attachclasses configuration in Maven war plugin to mywebapp-1.0-snapshot jar?

According to Maven war plugin FAQ,

<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>

Is there any way to get mywebapp-1.0-snapshot Jar instead of mywebapp-1.0-snapshot-classes jar?

to update::

I want to generate war and jar Although I can do this by applying the profile mentioned in changing packaging based on active profile in POM But I'd like to know the above problem

Solution

Short answer: No, you can't

By viewing the Maven war plugin source code, in warmojo In Java (line 292), you can simply modify the Maven war plugin configuration to see that it cannot meet your requirements:

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 );
    }

Since the classssclassifier parameter defaults to "classes", you cannot modify this behavior: the classifier will never be null

You can rename the file after it is generated, or you can modify the source code of Maven war plugin and use it as a custom plug-in

As a final consideration, null classsclassifier is not recommended: it may be misleading I don't know your project requirements

I hope I can help you

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>