Deploying Java project to Heroku without Maven-supported dependencies - java

Is anyone working with Heroku for Java?
I have one Java project which I want to deploy on Heroku. That project uses some external JAR files which contains important dependencies.
Can anyone tell me how to deploy my project with these JAR files to Heroku? Maven is not able to download these JAR files on Heroku.

We just published a guide showing how to add dependencies like this to your project:
http://devcenter.heroku.com/articles/local-maven-dependencies
Let me know if this works for you.

You need to setup a local Maven repository containing your jars. Include that repo in your git repo. And add the repo to the pom.xml file:
<repositories>
<repository>
<id>local-libs-dir</id>
<name>locallib</name>
<url>file:${project.basedir}/libs</url>
</repository>
</repositories>
The jar files must be in the standard Maven repo layout and have md5 & sha1 checksums.

You can use jcabi-heroku-maven-plugin, which automates the entire deployment process:
<plugin>
<groupId>com.jcabi</groupId>
<artifactId>jcabi-heroku-maven-plugin</artifactId>
<version>0.4.1</version>
<configuration>
<name>my-test-app</name>
<artifacts>
<artifact>com.example:example-app:jar::${project.version}</artifact>
</artifacts>
<procfile>web: java -Xmx256m -jar ./example-app.jar \${PORT}</procfile>
</configuration>
<executions>
<execution>
<goals>
<goal>deploy</goal>
</goals>
</execution>
</executions>
</plugin>
Besides that, you have to deploy your artifact (JAR/WAR) to your repository, so that Maven inside Heroku can download it during deployment.

Related

Adding Jars (More than One) to maven Classpath is giving errors

There are multiple jars (10 jars) and I have to use them in classpath in maven project.
These jars are available in my Project-dir/lib folder.
To handle this I tried
<build>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.12.4</version>
<configuration>
<additionalClasspathElements>
<additionalClasspathElement>lib/*.jar</additionalClasspathElement>
</additionalClasspathElements>
</configuration>
</plugin>
</plugins>
</build>
changed lib/*.jar to
1. lib
2. /lib
etc but nothing seems working
Also tried
<repositories>
<repository>
<id>in-project</id>
<name>In Project Repo</name>
<url>lib/*.jar</url>
</repository>
</repositories>
But always faced error (cannot find symbol) on running mvn install
If you want to use jars as dependencies for build or test, they should be inside a Maven repository (not in a lib folder in your project).
The best thing would be to upload them to your company Nexus/Artifactory (if they are not already available from MavenCentral or some other remote Maven repository).
Alternatively, you can use mvn install:install-file to install them to the local repository on your computer.
After that, you can reference them in the pom.xml as dependencies.
Also see: How to add local jar files to a Maven project?

Deploy maven project in to AEM?

I have created a maven project with content and bundle folder i can build the project successfully in eclipse
use this command :-
mvn clean install
but my bundle jar and content zip not reflecting in AEM now i am manually uploading the zip and jar in to AEM but i need to deploy directly from eclipse with out manual intall.
Can anybody help on this ?
install is a phase in the Maven lifecycle during which an artifact is installed in your local Maven repository.
It usually has nothing to do with installing anything in AEM. You need to use specific Maven plugins to achieve that.
If you generated your project based on the Adobe archetype, you need to specify, using a profile, that you want your app deployed.
mvn -PautoInstallPackage install
This profile activates the Maven Vault Plugin and uses it to upload the CRX package to AEM. Here's a snippet from Adobe's AEM archetype where this behaviour is defined.
<profile>
<id>autoInstallPackage</id>
<activation>
<activeByDefault>false</activeByDefault>
</activation>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>com.day.jcr.vault</groupId>
<artifactId>content-package-maven-plugin</artifactId>
<executions>
<execution>
<id>install-package</id>
<goals>
<goal>install</goal>
</goals>
<configuration>
<targetURL>http://${aem.host}:${aem.port}/crx/packmgr/service.jsp</targetURL>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</pluginManagement>
</build>
</profile>
Check out the official documentation for more information.
If, by any chance, your project happens to be using the Maven CRX Plugin (Adobe's archetype and its particular choice of plugins is just one of the options available in the wider AEM community), you need to explicitly invoke the crx:install goal.
mvn install crx:install
The bottom line is, mvn install just takes care of installing artifacts in your local Maven repository. In order to deploy to AEM, you need to invoke something more or set up your project to activate some plugins automatically in a certain phase of the lifecycle.

How Do I Point Maven To Java Source Code Dependencies?

I have an Apache Archiva Repo that I've set up to handle the binary dependencies for a Maven project that I'm working on; however, the project appears to also have some dependencies on local 3rd party source code (Unsure of Distribution License). Is there a way that I can put this source somewhere that Maven can grab it from when needing to do a build? Normally source would be stored in SCM, but that doesn't seem like the right solution for java source files that I'm only using to compile (only needed at compile time), but don't want in my main "/src" directory. Elaborations and best practices appreciated, I'm pretty new to Java Development and Maven.
Possible solutions:
Convince the 3rd party project to deploy the JAR with the class files to Maven Central (if Open Source)
Convince the 3rd party project to deploy the JAR with the class files to your Apache Archiva Repo (if Closed Source and in the same organization)
Convince the 3rd party project to deploy the JAR with the class files to a Maven Repository Manager of their own and register that repo in your Apache Archiva instance (if Closed Source and not in the same organization; not sure if Apache Archiva provides such a feature)
Build the JAR with the class files yourself and deploy it to your Apache Archiva repo. Then declare a dependency to it as usual
You can build the Jar file of the 3rd party source code and place it under you /lib folder and provide the dependency in your pom.xml file, Now when you will build your code the dependencies will be grab from the particular jar file.
<dependency>
<groupId>--grp id name--</groupId>
<artifactId>--artifact id--</artifactId>
<scope>system</scope>
<version>1.0</version>
<systemPath>--${basedir}\lib\{name}.jar--</systemPath> (Path of jar)
</dependency>
</dependencies>
*Remove "-- --" while implementing.
You can use the Build Helper Plugin, e.g:
<project>
...
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>1.7</version>
<executions>
<execution>
<id>add-source</id>
<phase>generate-sources</phase>
<goals>
<goal>add-source</goal>
</goals>
<configuration>
<sources>
<source>path to where your 3rd party source code is present</source>
...
</sources>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>

Deploy All Project Dependencies to a Remote Repository

We hava a new project friend and we want to install the project to his enviroment. But there are too many dependencies that not exists in the maven repository. So maven became useless. We installed an archiva server to install our artifacts there, but we dont want to deploy all that dependencies one by one(not only project jar self, all the dependencies). Is there an automated solution for this situation?
Thanks in advance.
Initially if you tweak your projects pom.xml and add:
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.3</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<outputDirectory>localrepo</outputDirectory>
<useRepositoryLayout>true</useRepositoryLayout>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
and run mvn package this should create a copy of your dependencies in repository directory format inside the localrepo directory (I tried using the command line options to dependency:copy-dependencies but it wouldn't work for me). Now comment out the above from your pom.xml as you probably don't need it anymore.
I've never used Archiva but I imagine at this point you could install the localrepo repository files onto a local web server and configure your Archiva server to mirror it.
Alternatively, if you wanted to produce a minimal effort install for your end user (and distribution size wasn't an issue) you could include this localrepo directory in your distribution and provide maven with a reference to it by adding the following to your pom.xml:
<repositories>
<repository>
<id>local-repo</id>
<name>local-repo</name>
<url>file://${basedir}/localrepo</url>
<releases>
<enabled>true</enabled>
<checksumPolicy>ignore</checksumPolicy>
<updatePolicy>always</updatePolicy>
</releases>
</repository>
</repositories>
This local repository technique is very useful when distributing home grown and 3rd party jar files that are not in public Maven repositories. You can always remove the libraries that are in public repositories.
I find nothing discourages new users from Maven quicker than my trying to explain all that mvn install:install-file palaver that is usually necessary to install 3rd party jars (however enthusiastic I may be about Maven).

Is it best to Mavenize your project jar files or put them in WEB-INF/lib?

I've been doing this for all of the jar files that my Spring MVC project needs:
call mvn install:install-file -DgroupId=vegetables -DartifactId=potatoes -Dversion=1.0 -Dfile=vegetables-1.0.jar -Dpackaging=jar -DgeneratePom=true
Recently I must have exceeded some limit on how many dependencies you can list in your pom.xml file because I got an error that said:
Your command line is too long
So I removed some dependencies from the pom.xml that my project no longer uses and I was able to run the project with maven again.
My question is, should I put install all jar files into my Maven repository as I have been doing so far? Or should I put some of them into the WEB-INF/lib directory?
What's the best practice here?
I've been doing the same that you do with the command line, but by configuring maven-install-plugin in my POM (please read the note at the end):
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-install-plugin</artifactId>
<executions>
<execution>
<id>install-vegetables</id>
<phase>initialize</phase>
<goals>
<goal>install-file</goal>
</goals>
<configuration>
<file>${project.basedir}/lib/vegetables-1.0.jar</file>
<groupId>vegetables</groupId>
<artifactId>potatoes</artifactId>
<version>1.0</version>
<packaging>jar</packaging>
</configuration>
</execution>
<execution>
<id>install-minerals</id>
<phase>initialize</phase>
<goals>
<goal>install-file</goal>
</goals>
<configuration>
<file>${project.basedir}/lib/minerals-1.0.jar</file>
<groupId>minerals</groupId>
<artifactId>rocks</artifactId>
<version>1.0</version>
<packaging>jar</packaging>
</configuration>
</execution>
</executions>
</plugin>
It is much less efficient, because files get installed over and over, but it is much less annoying than making it manually. Anyway, I think you should give it a try.
All your dependencies should reside under the local repository. According to the Maven convention/best practices, you should not keep jar files in your project.
Convert your project to a fully war based Maven project. This will place all your dependencies (jar files) under your webapp's WEB-INF/lib directory. Thus you will not have to worry about long paths.
You just need to add the dependencies in your pom.xml file, no need to install them manually. Maven will download the libraries and put it in your local repository whenever needed. Only if you want to use third party(custom) libraries, you may go for installing it in your local repository.

Categories