ExpDev ExpDev - 1 month ago 13
Java Question

Java: Maven and Library compiling

I'm trying to compile a project which has got Maven dependencies and normal dependencies (the ones you would add the .jar to your buildpath/lib). However, I can only choose one ;( Either, I compile with Maven, or I compile with artifacts, and that won't make the project work.

I use

<build>
<plugins>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<archive>
<manifest>
<mainClass>me.expdev.testproject.Main</mainClass>
</manifest>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
</plugin>
</plugins>
</build>


and

mvn clean compile assembly:single


to compile. But I also have 5 jars (which are not available as Maven) which I need included in the packaging jar output! It works fine when I run Main in my IDE.

I USE IntelliJ Community Edition.

Answer

You can package the 3rd party jars as Maven artifacts.

mvn install:install-file -Dfile=<path-to-file> -DgroupId=<group-id> \
-DartifactId=<artifact-id> -Dversion=<version> -Dpackaging=jar

The <group-id>, <artifact-id> and <version> fields are completely up to you to fill, choose values that seem appropriate to you. The artifact will be available to Maven by these values. See other Maven artifacts already in your project for examples. For the group id, choose some prefix to make it clear that it's not a publicly published jar, to avoid confusion. For example custom., as in custom.some.package, but it's really up to you.

For more details, see: Guide to installing 3rd party JARs

Also keep in mind that other developers who want to use the project will have to do the same, and manually install the jars in their local Maven repositories. Another option is to run your own Maven repository. See this article: http://stuartsierra.com/2009/09/08/run-your-own-maven-repository .