简体   繁体   中英

Getting the filename of a jar-with-dependencies as a variable

I'm using the maven-assembly-plugin to package my jar file with dependencies, which works fine and correctly generates a jar file. The output file from this is specified with finalName :

<plugin>
    <!--Many lines omitted-->
    <artifactId>maven-assembly-plugin</artifactId>
    <version>2.5.5</version>
    <configuration>
        <finalName>MyFinalJar-${project.version}</finalName>
    </configuration>
</plugin>

Now, I need to access this finalName in another plugin, which does some packaging of the jar file. I have the ${project.build.finalName} variable, but that doesn't give me the jar-with-dependencies, it just gives me the plain jar that I don't want.

How can I access this final jar filename without repeating myself?

On the top of your pom file declare:

<properties>
  <finalproject.name>someprojectname</finalproject.name>
</properties>

and then use it everywhere else using:

${finalproject.name}

for example:

<configuration>
    <finalName>${finalproject.name}</finalName>
</configuration>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM