Using your own JAR files in a java application

Code: 
KB-E1040
Applies to: 
jboss, java
Issue: 

You create a Java application that uses a jar file not available in a public maven repository. When trying to deploy the application that uses a non-public jar, you get a Maven error such as:
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:2.3.2:compile (default-compile) on project helloworld: Compilation failure: Compilation failure: [ERROR]

Resolution: 

This error is caused by Maven on the gear not being able to see your custom jar file. Since OpenShift uses Maven to manage the build process your jar file must be visible to Maven and be added as a dependency. The jar has to be placed in a location where Maven can see it and then the pom.xml needs to be updated to pull in the custom jar. In this case the jar could be your own code or a custom version a standard jar.

Here are the steps to get it working

1) add the jar to the root of your local git repo

2) add a line like below to .openshift/action_hooks/pre_build:

mvn install:install-file -Dfile=../../app-root/repo/test-1.0.jar -DgroupId=org.brutus -DartifactId=test -Dversion=1.0 -Dpackaging=jar

where: jboss1 is the name of your application test-1.0 is the name of your jar groupId/artifactId/version need to match the corresponding dependency in your pom

3) Update your pom with the dependency. Do not set the scope of your dependency to "provided" or it won't be included in your war. Since JBoss does not have your jar included, Maven needs to place your jar in the war file. Here is an example using the jar from above:

<dependency>
      <groupId>org.brutus</groupId>
      <artifactId>test</artifactId>
      <version>1.0</version>
</dependency>

4) do a "git commit -a" and a "git push" and it should now work on the server.

Tags: