How can I package a maven jar and output multiple copies of the resulting JAR file to different folders?

Viewed 104

Pretty much what the title says. I'm building Minecraft Spigot plugins for servers running under BungeeCord and running the mvn package plugin in IntelliJ results in the generated JAR file being located in the project's "target" folder. Instead, I need to output multiple copies of the generated JAR into multiple "plugin" folders for various servers. I'm not sure how or if this is possible to do with Maven, but I would like to know if there is a way to do that in pom.xml. Having to copy the JAR every time I build it slows down the development process. Any help would be greatly appreciated!

1 Answers

You should be able achieve the same thing with symlinks (symbolic link). It allows the file system a way to have a reference to another file location without actually making an explicit copy (kind of like a shortcut). This is also more in the spirit of maven's philosophy that each project should build only one artifact.

How you make symlinks depends on your operating system. You would need to make a symlink for each separate location that you need to "copy" to.

Mac / Linux:

ln -s /project/target/my.jar /project/server/plugin1

Windows:

mklink /project/target/my.jar /project/server/plugin1

Other info about symlinks (e.g. if you need to delete):

https://www.howtogeek.com/howto/16226/complete-guide-to-symbolic-links-symlinks-on-windows-or-linux/ https://www.howtogeek.com/297721/how-to-create-and-use-symbolic-links-aka-symlinks-on-a-mac/

Building multiple jars is fairly tricky in maven. See this post for some additional details - it suggests using a maven ant plugin if this is what you really want, but I would recommend against this approach. Symlinks should be easier to work with.

Ant to Maven - multiple build targets

Related