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).
Related
Updating question; I am trying to implement readyapi with maven, followed the steps here https://support.smartbear.com/readyapi/docs/integrations/maven/example.html#pom but not able to resolve plugin issue. Any help?
<repository>
<id>com.teamdev</id>
<url>https://europe-maven.pkg.dev/jxbrowser/releases</url>
</repository>
</repositories>
<!-- Add the SmartBear ReadyAPI plugin repository. -->
<!-- Maven will download the plugin from the specified URL. -->
<pluginRepositories>
<pluginRepository>
<id>SmartBearPluginRepository</id>
<url>http://smartbearsoftware.com/repository/maven2</url>
</pluginRepository>
</pluginRepositories>
<build>
<plugins>
<plugin>
<groupId>com.smartbear</groupId>
<artifactId>ready-api-maven-plugin</artifactId>
<version>3.0.0</version>
<executions>
<execution>
<phase>test</phase>
<goals>
<goal>test</goal>
</goals>
<configuration>
<projectFile>Sample-SOAP-project.xml</projectFile>
<readyApiProperties>
<property>
<name>readyAPI</name>
<value>C:\per\ReadyAPI\ReadyAPI-3.0.0\bin</value>
</property>
</readyApiProperties>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>```
I was trying to integrate maven through pom and it didn't work so I installed packages manually
This is the root cause of the problem. You did so manually and maven can't find them now.
Let's do this the proper way. Create a pom, which tries to import the necessary dependencies using mvn and then post it here. It will be easier to debug that than to figure out how to add dependencies of the right version manually.
Edit your post with the new pom and post a comment here.
EDIT:
OK, so the reason why you are unable to download this stuff from Maven, its because maven blocks blocks external HTTP repositories by default since some version.
Here's a solution from the mvn team about how to fix this.
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?
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.
i have third part jar file which doesn't exist remotely the file located inside the project directory , i want to add this jar into the local repository when i execute mvn install, my current code for doing that
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-install-plugin</artifactId>
<version>2.4</version>
<executions>
<execution>
<phase>initialize</phase>
<goals>
<goal>install-file</goal>
</goals>
<configuration>
<groupId>myJar1.0</groupId>
<artifactId>myJar1.0</artifactId>
<version>1.0</version>
<packaging>jar</packaging>
<file>myJar1.0.jar</file>
</configuration>
</execution>
</executions>
</plugin>
Actually its not so complicated.
There are 2 cases that you need to issue Maven’s command to include a jar into the Maven local repository manually.
The jar you want to use doesn’t exist in the Maven center repository.
You created a custom jar, and need to use for another Maven project.
Steps:
1. mvn install:
put your jar somewhere, lets assume its under c:\:
mvn install:install-file -Dfile=c:\myJar{version}.jar
-DgroupId=YOUR_GROUP -DartifactId=myJar -Dversion={version} -Dpackaging=jar
Now, the "myJar" jar is copied to your Maven local repository.
2. pom.xml:
After installed, just declares the myJar coordinate in pom.xml.
<dependency>
<groupId>YOUR_GROUP</groupId>
<artifactId>myJar</artifactId>
<version>{version}</version>
</dependency>
3. Done
Build it, now the "myJar" jar is able to retrieve from your Maven local repository.
NOTE: this example was based on the another example which I encourage you to read for further information.
Using a repository manager is the best solution. However, here's a solution that can be setup entirely through pom.xml configuration (without developer interventions):
Add a local repository pointing to your jar location:
<repositories>
<repository>
<id>project-local-repo</id>
<url>file://${project.basedir}/src/lib/</url>
</repository>
</repositories>
Move/rename your library to ${project.basedir}/src/lib/some-group-name/myJar-1.0.jar
And then you can include the dependency:
<dependency>
<groupId>some-group-name</groupId>
<artifactId>myJar</artifactId>
<version>1.0</version>
</dependency>
The dependency will be picked up at every build.
I wrote a similar answer here: running Spring Boot for REST
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.