Maven WAR Plugin
  1. Maven WAR Plugin
  2. MWAR-211

Ability to rename a dependency's jar when putting it on the lib folder

    Details

    • Type: New Feature New Feature
    • Status: Closed Closed
    • Priority: Major Major
    • Resolution: Not A Bug
    • Affects Version/s: None
    • Fix Version/s: None
    • Component/s: None
    • Labels:
      None
    • Number of attachments :
      1

      Description

      Maven put on my 'lib' folder the jars of my project's dependencies named like <artefactId>-<version>.jar

      This is a problem when we need to reference the jar filename from sourcecode, because if we change the dependency version, we have to track all source code references to it and correct them. This is the case when importing a taglib into a jsp page

      It would be better if Maven put only <artefactId>.jar on the lib folder. And even better if it let us use any custom name we want for the dependencies. If no name is specified, then it could use the current pattern.

      1. TestMaven.rar
        2 kB
        Magno Machado Paulo

        Issue Links

          Activity

          Hide
          Benjamin Bentmann added a comment -

          More than likely, you refer to some Maven plugin and not the Maven core. What exactly is "putting it on the lib folder"? Do you have a POM or debug log to look at?

          Show
          Benjamin Bentmann added a comment - More than likely, you refer to some Maven plugin and not the Maven core. What exactly is "putting it on the lib folder"? Do you have a POM or debug log to look at?
          Hide
          Magno Machado Paulo added a comment -

          Sorry, I think I wasn't clear...
          Let's try again..
          I'm going to attach a project on this issue where you can see what I'm saying.
          First, do a "mvn package" on the project.
          Then, go to TestMaven/target/TestMaven/WEB-INF/lib
          Among other files, there's a "mentawai-1.14.1.jar" there. What I want is force Maven to rename this jar.
          To understand why do I whant this, look at the "TestMaven/src/main/webapp/index.jsp" file.
          The first line on thie file is:
          <%@ taglib uri="/WEB-INF/lib/mentawai-1.14.1.jar" prefix="mtw" %>
          Now imagine I have this line on a lot of source files, and I decide to use a new version of the library. I would have to go on any source file and correct the references.

          Now, imagine Maven had renamed this jar to, say, "mentawai.jar". What I'd have on my index.jsp would be:
          <%@ taglib uri="/WEB-INF/lib/mentawai.jar" prefix="mtw" %>

          And if I decide to move to a different version, I don't have to correct any references.

          I think we could have an addicional tag on the dependency declaration, something like this:
          <dependency>
          <groupId>org.mentaframework</groupId>
          <artifactId>mentawai</artifactId>
          <version>1.14.1</version>
          <scope>compile</scope>
          <finalName>mentarai.jar<finalName> <- This is a new tag
          </dependency>
          And, in the case where this new tag isn't used, Maven would use the current pattern, so it would be 100% backward compatible.

          Show
          Magno Machado Paulo added a comment - Sorry, I think I wasn't clear... Let's try again.. I'm going to attach a project on this issue where you can see what I'm saying. First, do a "mvn package" on the project. Then, go to TestMaven/target/TestMaven/WEB-INF/lib Among other files, there's a "mentawai-1.14.1.jar" there. What I want is force Maven to rename this jar. To understand why do I whant this, look at the "TestMaven/src/main/webapp/index.jsp" file. The first line on thie file is: <%@ taglib uri="/WEB-INF/lib/mentawai-1.14.1.jar" prefix="mtw" %> Now imagine I have this line on a lot of source files, and I decide to use a new version of the library. I would have to go on any source file and correct the references. Now, imagine Maven had renamed this jar to, say, "mentawai.jar". What I'd have on my index.jsp would be: <%@ taglib uri="/WEB-INF/lib/mentawai.jar" prefix="mtw" %> And if I decide to move to a different version, I don't have to correct any references. I think we could have an addicional tag on the dependency declaration, something like this: <dependency> <groupId>org.mentaframework</groupId> <artifactId>mentawai</artifactId> <version>1.14.1</version> <scope>compile</scope> <finalName>mentarai.jar<finalName> <- This is a new tag </dependency> And, in the case where this new tag isn't used, Maven would use the current pattern, so it would be 100% backward compatible.
          Hide
          Magno Machado Paulo added a comment -

          Test project

          Show
          Magno Machado Paulo added a comment - Test project
          Hide
          Benjamin Bentmann added a comment - - edited

          I was told the example File Name Mapping from the Maven WAR Plugin could be what you want.

          Show
          Benjamin Bentmann added a comment - - edited I was told the example File Name Mapping from the Maven WAR Plugin could be what you want.
          Hide
          Johan Sj÷berg added a comment - - edited

          If "File Name Mapping" renames TLDs etc. as well, perhaps a tag like <archiveName>myname.jar</archiveName> would be great to complement <archiveClasses>true</archiveClasses>; to be able to replace the default <artefactId>-<version>.jar with myname.jar.

          Show
          Johan Sj÷berg added a comment - - edited If "File Name Mapping" renames TLDs etc. as well, perhaps a tag like <archiveName>myname.jar</archiveName> would be great to complement <archiveClasses>true</archiveClasses>; to be able to replace the default <artefactId>-<version>.jar with myname.jar.
          Hide
          Johan Sj÷berg added a comment -

          Using <outputFileNameMapping> to control the name of the jar-file produced by the <archiveClasses> tag has SERIOUS side effects. Sure, the jar-file produced from our sources are given the name, but so are also every other external dependency (declared by maven <dependency>...</dependency> tags).

          So again, I really propose a tag similar to <archiveName>myname.jar</archiveName>, to be able to control the name of the jar produced from the project sources.

          pom.xml excerpt using outputFileNameMapping:

          <plugin>
          <groupId>org.apache.maven.plugins</groupId>
          <artifactId>maven-war-plugin</artifactId>
          <version>2.1-beta-1</version>
          <configuration>
          <archiveClasses>true</archiveClasses>
          <outputFileNameMapping>prefix-$

          {project.artifactId}

          -$

          {project.version}

          .jar</outputFileNameMapping>
          </configuration>
          </plugin>

          Show
          Johan Sj÷berg added a comment - Using <outputFileNameMapping> to control the name of the jar-file produced by the <archiveClasses> tag has SERIOUS side effects. Sure, the jar-file produced from our sources are given the name, but so are also every other external dependency (declared by maven <dependency>...</dependency> tags). So again, I really propose a tag similar to <archiveName>myname.jar</archiveName>, to be able to control the name of the jar produced from the project sources. pom.xml excerpt using outputFileNameMapping: <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-war-plugin</artifactId> <version>2.1-beta-1</version> <configuration> <archiveClasses>true</archiveClasses> <outputFileNameMapping>prefix-$ {project.artifactId} -$ {project.version} .jar</outputFileNameMapping> </configuration> </plugin>
          Hide
          Dennis Lundberg added a comment -

          Johan,

          Your comments are about other issues than this one.

          I haven't seen another issue about renaming TLDs, please file a new issue for that with a description of what it is you want to do.

          There are other issues about the name of the project's own JAR file, like MWAR-176. Please add your suggestions there. Or if you feel the need for it - create a new issue.

          Show
          Dennis Lundberg added a comment - Johan, Your comments are about other issues than this one. I haven't seen another issue about renaming TLDs, please file a new issue for that with a description of what it is you want to do. There are other issues about the name of the project's own JAR file, like MWAR-176 . Please add your suggestions there. Or if you feel the need for it - create a new issue.
          Hide
          Dennis Lundberg added a comment -

          The solution for the original problem in this issue is, as Benjamin mentioned, to add some configuration for the WAR Plugin, like this:

                  <configuration>
                    <outputFileNameMapping>@{artifactId}@.@{extension}@</outputFileNameMapping>
                  </configuration>
          
          Show
          Dennis Lundberg added a comment - The solution for the original problem in this issue is, as Benjamin mentioned, to add some configuration for the WAR Plugin, like this: <configuration> <outputFileNameMapping> @{artifactId}@.@{extension}@ </outputFileNameMapping> </configuration>

            People

            • Assignee:
              Unassigned
              Reporter:
              Magno Machado Paulo
            • Votes:
              3 Vote for this issue
              Watchers:
              5 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: