views:

21

answers:

1

I have a module that is used by creating a custom class loader. The class loader should therefore be created with the path to the module and also all dependencies.

I'm looking for a way to make it productive to work with this mechanism in both dev and production environments.

I thought the build can generate two files listing all dependency paths. A 'dev' file and 'production' file (then in the code I'd choose the right file based on some system property):

  • dev: dependencies should be paths to thirdparty jars in the local maven repository or 'target\classes' for other modules (which will allow to compile with the IDE and not need a full build for each change)
  • production: all jars should be copied to a 'lib' folder and the dependencies should list them (without full path). Alternatively, create an uber jar, and then the (?)

So I'm looking for pointers to plugins & pom snippets to help me with this.

A: 

Some hints:

  • For the dev part, the Maven Dependency Plugin and its dependency:build-classpath can help (and supports writing the output to a file). Another option would be to use the Maven AntRun plugin, it has access to the Maven runtime classpath, it should be easy to write the property to a file.

  • For the prod part, I assume you'll use the Maven Assembly Plugin or the Shade Plugin or another equivalent and I wonder if you couldn't generate a classpath entry in the MANIFEST.MF and rely on it.

Pascal Thivent
does dependency:build-classpath write the "dev" paths ("target\classes") or only the repo paths? i can instruct the jar plugin to generate manifest.mf, but i think the paths would be to the repo paths
IttayD
@IttayD: No, `dependency:build-classpath` doesn't include `target/classes` (why didn't you try?). Regarding the MANIFEST.MF, the classpath entry shouldn't point to the repo path (or your jar wouldn't be portable). Anyway, I've added another (potentially better) suggestion.
Pascal Thivent