Question

I'm currently working on changing building process of legacy project. Right now it is built by a custom-made solution and our aim is to adjust it to a standard one - maven.

This is a standalone application and current output of a build is a directory with following structure:

 OUR_APPLICATION
 |
 |_bin
 | |_start.sh
 | |_stop.sh
 |
 |_etc
 | |_app.properties
 |
 |_jar
 | |_app_classes1.jar
 | |_app_classes2.jar
 |
 |_lib
   |_third_party_library.jar

I am wondering what's the best way to achieve similar output with maven and still follow best practises (or at least break them as little as possible).

I'm leaning towards creation of multi-module project (separate modules for Java code, configuration files and shell scripts) and then using maven-assembly-plugin for combining it all together, but I'm not entirely sure how (if at all) it can be properly done. Still I'm not sure whether its the best fit for me and I will be very grateful for any feedback.

Était-ce utile?

La solution

You are on the right way (imo): Maven is a good tool for producing deployable artifacts. And the maven-assembly-plugin fits the needs that you described. It could produce a ZIP file containing the application structure you described.

The default artifact type that Maven produces is simply a JAR. This is ok for libraries. The application structure that you described seems to have three of them: app_classe1.jar, app_classes2.jar, and third_party_library.jar (I know, there could be more of them).

The Maven setup that I would suggest (and keep in mind: other ways exist): Create a multi-module project, which has modules for each application JAR and one module for assembling them. The parent project then simply builds them all. Like this:

ParentProject
 |
 |-- pom.xml (the parent one, that describes all modules)
 |
 |-- Module1 (producing app_classes1.jar)
 |    |
 |    |-- pom.xml
 |    |-- src/...
 |
 |-- Module2 (producing app_classes2.jar)
 |    |
 |    |-- pom.xml
 |    |-- src/...
 |
 |-- AssemblyModule (the one that produces a ZIP, for example)
      |
      |-- pom.xml (with type POM because it does not produce a JAR)

The assembly module should not have the default artifact type (JAR), but should be set to type POM. The pom.xml of that assembly module then configures the maven-assembly-plugin to create a ZIP file. The content of this ZIP file is highly configurable. Additionally, this plugin attaches the result artifact (the ZIP) to the build, so that it will be uploaded to a repository, if that is also configured.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top