Is it possible to package a portable maven in the project (and some general direction on how)?

1k Views Asked by At
  • The solution which needs bootstrapping is supplied as java code. Absolutely sure that this is necessary.
  • Receivers of the solution are guaranteed to have a suitable JDK
  • However, receivers of the solution are unable to install Maven (they don't know how to and cannot be taught)

My idea is to include some sort of Maven with the project, such that can be set up in a script like so:

  1. set up maven repo as a folder under the solution folder (using relative reference)
  2. set up anything else maven needs (don't know what, exactly)
  3. call /path/to/maven/mvn compile -f /path/to/oneAndOnly/pom.xml
  4. java /target/MySolutionClas

I am aware of: https://dzone.com/articles/embedding-maven but it gets confusing when he talks about configuring the portable maven into the pom.xml - wait, how is that pom.xml going to mean anything if maven is not configured yet? (PS: I mean no disrespect to the author. I probably got it all wrong)

2

There are 2 best solutions below

0
aballaci On

One could include a shell script that would setup maven if it is not already present.

The same for building and packaging encapsulating the complexities of the setup to just runing a couple of scripts.

0
Joe On

Maven Wrapper aims to do just that, similar to the gradle wrapper seen in many gradle projects.

Running the wrapper goal of the maven wrapper plugin will generate a mvnw script in your project that can be run in place of a globally installed mvn command.

It's part of the maven 3.7.0 release, and documented more fully here: https://maven.apache.org/plugins/maven-wrapper-plugin/index.html

See https://github.com/takari/maven-wrapper for maven < 3.7.0