Maven dependency on another Maven project - linux

I'm currently having trouble trying to add add the dependency of another Maven project (specifically Aerospike) into my project. I already did a mvn install on the Aerospike project so in my repository (on Linux: ~/.m2/repository/com/aerospike/aerospike-client/3.0.6) I see a aerospike-client-3.0.6.jar.lastUpdated file. However, when I add the dependency
<dependency>
<groupId>com.aerospike</groupId>
<artifactId>aerospike-client</artifactId>
<version>3.0.6</version>
<scope>compile</scope>
</dependency>
into my project and perform an mvn install, it returns this error:
[INFO] ------------------------------------------------------------------------
[INFO] Building in-memory database poc 0.0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[WARNING] The POM for com.aerospike:aerospike-client:jar:3.0.6 is missing, no dependency information available
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 0.601s
[INFO] Finished at: Fri Aug 16 11:49:43 EDT 2013
[INFO] Final Memory: 18M/954M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal on project: Could not resolve dependencies for project: Failure to find com.aerospike:aerospike-client:jar:3.0.6 in http://repository.jboss.org/nexus/content/groups/public was cached in the local repository, resolution will not be reattempted until the update interval of jboss-public-repository-group has elapsed or updates are forced -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/DependencyResolutionException
Thanks in advance!

Problem
The console output says that Maven is searching for com.aerospike:aerospike artifact in the JBoss public repository but that artifact isn't there.
Failure to find com.aerospike:aerospike-client:jar:3.0.6 in
http://repository.jboss.org/nexus/content/groups/public
The OP stated that he installed it locally.
Discussion
Maven is trying to download a locally installed artifact from a remote repository that does not have that artifact. By default dependencies are first searched in local repository. AFAIK, the only thing that can override this behavior are the artifact update policies defined in settings.xml.
AFAIK, the offline build (-o) should override any such policies.
I tried to reproduce this situation by deleting dependencies from my local repo and intentionally declaring nonexistent dependencies and Maven acted as documented (offline build does not try to download). I have not played with update policies though.
Solution
Following up on the comments, I have verified the offline build procedure in the following environment:
Apache Maven 3.1.0
Java version: 1.7.0_25, vendor: Oracle Corporation
OS name: "linux", version: "3.2.0-23-generic", arch: "amd64", family: "unix"
The offline build procedure in short:
download all the online dependencies
install all the offline dependencies
run offline build
All the commands are run from the project root folder.
First, comment all the dependencies that are not found in any remote repository from your pom, e.g.:
<!--
<dependency>
<groupId>does</groupId>
<artifactId>not</artifactId>
<version>exist</version>
</dependency>
-->
Prepare the offline build by downloading all the dependencies:
mvn dependency:go-offline
If you don't comment out the missing dependencies this goal will fail. You can verify it by observing that Maven has successfully downloaded all the artifacts in your console output.
Next, install the missing dependencies manually in your local repo:
mvn install:install-file -Dfile=<PATH_TO_MISSING_DEP_JAR_FILE>
-DgroupId=does
-DartifactId=not
-Dversion=exist
-Dpackaging=jar
That will produce not-exist.jar (a copy of <PATH_TO_MISSING_DEP_JAR_FILE>) and not-exist.pom along with metadata files in your local repository under <LOCAL_REPO_PATH>/.m2/repository/does/not/exist/
Verify that those files exist under that exact directory structure.
Default locations of your local repository for different platforms are here, but if it isn't there, then run:
mvn help:effective-settings > settings.log
which will dump the interpolated settings for your project to settings.log file. Open it with a text editor and read the path of your local repo under:
<settings>
...
<localRepository>/path/to/local/repo/</localRepository>
...
</settings>
Now you can run your build in offline mode:
mvn clean install -o
You can set offline mode in your settings file also, but that will set offline mode for a specified user or system-wide as opposed to command line switch which is per project when you want it.
Conclusion
Carefully run this procedure exactly as described, and if you still can't build your project, then please run:
mvn help:effective-pom > pom.log
mvn help:effective-settings > settings.log
and post the contents of pom.log and settings.log files here.

Related

How to migrate the artifacts of a maven project which has a parent artifact into Azure Artifacts?

I'm trying to migrate the artifacts of a maven project from Sonatype Nexus to Azure Artifacts and I'm following the steps described here.
So it's basically
mvn clean install: Creates a local copy of the artifacts.
Change the repository and distribution management URL and point to the destination Azure feed url.
mvn deploy: Deploys the artifacts into Azure feed.
This must work. But the project that I'm working on has a parent, which is provided to us externally and is not in maven central. That parent is not getting deployed and is missing from Azure Artifact feed and is resulting in an error.
Sample pom.xml
<project xmlns....>
<parent>
<groupId>parent.pom..
..
</parent>
<groupId>main.project...
<name>project..
<version>x.x..
<packaging>pom..
....
....
</project>
Getting error on trying to build the project from Azure Artifact.
C:/...MainProject> mvn clean install
...
...
[ERROR][ERROR] Some problems were encountered while processing the POMs
[FATAL] Non-resolvable parent POM for main.project...: Could not transfer the artifact parent.pom
Tried to create a small project with only parent pom as dependency and tried to upload it Azure Artifact feed.
But a similar error is being thrown up.
According to your description, please check if there is a proxy in your internet.
And try to delete the .m2 local Directory and run mvn clean install again to check if it works.
You can refer to this answer.

mvnw not generating test directory for jhipster 4.10.0

I have deleted the default test directory generated by ./mvnw. Now running maven doesn't generate test repository no more. I need some help please

How to include the spark-examples.jar as a dependency within a maven/sbt project?

The spark-examples.jar is apparently not published to maven. That is a complication when attempting to build atop those classes in an maven /sbt project.
Further compounding this problem is that it seems that mvn install were set up to skip when going through the process of downloading spark, building from source, and installing locally:
mvn -pl examples install
[INFO] --- maven-install-plugin:2.5.2:install (default-install) # spark-examples_2.11 ---
[INFO] Skipping artifact installation
It seems I will have to spelunk into the spark examples pom.xml to see how to re-enable installation? Overall this is a non trivial process: any pointers to a quicker path appreciated.
It appears that a band-aid would be as hinted in the OP: remove the skip from the install plugin invocation:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-install-plugin</artifactId>
<configuration>
<!-- <skip>true</skip> -->
</configuration>
A more straightforward approach to adding the spark-examples dependency would still be appreciated (and likely awarded).

javafx self-contained package

I created the javafx standalone application using netbeans by copying the following snippet into build.xml file
<target name ="-post-jfx-deploy">
<fx:deploy width="${javafx.run.width}" height="${javafx.run.height}"
nativeBundles="all"
outdir="${basedir}/${dist.dir}" outfile="${application.title}">
<fx:application name="${application.title}" mainClass="${javafx.main.class}"/>
<fx:resources>
<fx:fileset dir="${basedir}/${dist.dir}" includes="*.jar"/>
</fx:resources>
<fx:info title="${application.title}" vendor="${application.vendor}"/>
</fx:deploy>
</target>
I had jdk environment for x64 bit version so it created application that runs in only x64 bit version of windows or operating systems. Can anyone tell how should I change the deploy method to make application runnable on x86 bit systems. By default netbeans took up 64bit version of jdk environment
You could combine Maven with Ant on the following way:
Defining a Maven artifact for JDK
Using maven-dependency-plugin
Using unzip Ant task
Using <fx:platform>
Defining Maven artifact for JDK
Defining Maven artifacts for JDK x86 and JDK x64. It may sounds weird at first time, but thinking in a continuous integration environment, it makes sense at all.
You just zip an ordinary JDK folder and deploy it as a Maven artifact.
Then your Maven project will depend on:
<properties>
<jdk.version>1.8.112</jdk.version>
<!-- can be '64' or '32' -->
<cpu.arch>64</cpu.arch>
</properties>
</dependencies>
<!-- other dependencies goes here -->
<dependency>
<groupId>com.my.company</groupId>
<artifactId>jre-linux-${cpu.arch}</artifactId>
<version>${jre.version}</version>
<type>zip</type>
<scope>runtime</scope>
</dependency>
</dependencies>
Note: I'm running on Debian, but it's totally applicable to Windows environment too.
Using maven-dependency-plugin
Add the maven-dependency-plugin. It will copy all your dependencies (includind your JDK zip file defined on dependencies section) to the /target/dist/lib folder.
We'll use it soon.
The plugin configuration looks like:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>copy-dependencies</id>
<phase>install</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<includeScope>runtime</includeScope>
<outputDirectory>${application.dist}/lib</outputDirectory>
<overWriteReleases>false</overWriteReleases>
<overWriteSnapshots>true</overWriteSnapshots>
<overWriteIfNewer>true</overWriteIfNewer>
</configuration>
</execution>
</executions>
</plugin>
Using unzip Ant task
Now before your JavaFX Ant tasks, you must tell Ant to extract your JDK dependency into a folder.
It must be set BEFORE the task who will bundle your JavaFX application.
<unzip src="${application.dist}/lib/jdk-linux-${cpu.arch}-${jdk.version}.zip"
dest="${extra.dir}/jdk"/>
Using <fx:platform>
And finally, at your <fx:deploy> tag you must add a <fx:platform> child tag, adding the basedir attribute as your previous jdk folder, like:
<fx:deploy ...>
<fx:platform javafx="8.0+" basedir="${extra.dir}/jdk" />
</fx:deploy>
The Maven logs will be similar to this:
[INFO] --- maven-antrun-plugin:1.7:run (default) # my-app ---
[INFO] Executing tasks
main:
[unzip] Expanding: /home/danilo/development/temp/my-app/target/dist/lib/jdk-linux-64-1.8.112.zip into /home/danilo/development/temp/my-app/target/extras/jdk
Using base JDK at: /home/danilo/development/temp/my-app/target/extras/jdk/jre
Using base JDK at: /home/danilo/development/temp/my-app/target/extras/jdk/jre
Creating app bundle: /home/danilo/development/temp/my-app/target/dist/bundles/my-app
Debian packages should specify a license. The absence of a license will cause some linux distributions to complain about the quality of the application.
Using default package resource [menu icon] (add package/linux/my-app.png to the class path to customize)
Using default package resource [Menu shortcut descriptor] (add package/linux/my-app.desktop to the class path to customize)
Using default package resource [DEB control file] (add package/linux/control to the class path to customize)
Using default package resource [DEB preinstall script] (add package/linux/preinst to the class path to customize)
Using default package resource [DEB prerm script] (add package/linux/prerm to the class path to customize)
Using default package resource [DEB postinstall script] (add package/linux/postinst to the class path to customize)
Using default package resource [DEB postrm script] (add package/linux/postrm to the class path to customize)
Using custom package resource [DEB copyright file] (loaded from package/linux/copyright)
dpkg-deb: construindo pacote 'my-app' em '/home/danilo/development/temp/my-app/target/dist/bundles/my-app-1.0.deb'.
Package (.deb) saved to: /home/danilo/development/temp/my-app/target/dist/bundles/my-app-1.0.deb
Config files are saved to /tmp/fxbundler8773603423891700338/linux. Use them to customize package.
Bundler RPM Bundle skipped because of a configuration problem: Can not find rpmbuild {0} or newer.
Advice to fix: Install packages needed to build RPM, version {0} or newer.
[INFO] Executed tasks
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 8:34.875s
[INFO] Final Memory: 22M/253M
[INFO] ------------------------------------------------------------------------
Conclusion
When you need to deliver your application on a x86 environment, just override the cpu.arch Maven property at build time:
mvn -Dcpu.arch=32 clean install
Now it's easier to set up your continuous integration. If you would use Jenkins CI, for example, you can create 2 different jobs and run it as needed.
I pushed the whole project to a Github repository. You can check it here: https://github.com/daniloguimaraes/javafx-multiple-jre-versions

How host local repository in pom.xml

When ever i tried to Goals >> Compile pom.xml, I am getting the following error.
An internal error was encountered invoking the maven goal: Please check the exception details.
org.apache.maven.artifact.resolver.MultipleArtifactsNotFoundException: Missing:
1) org.apache.httpcomponents:httpcore:jar:4.1.2
Try downloading the file manually from the project website.
Then, install it using the command:
mvn install:install-file -DgroupId=org.apache.httpcomponents -DartifactId=httpcore -Dversion=4.1.2 -Dpackaging=jar -Dfile=/path/to/file
Alternatively, if you host your own repository you can deploy the file there:
mvn deploy:deploy-file -DgroupId=org.apache.httpcomponents -DartifactId=httpcore -Dversion=4.1.2 -Dpackaging=jar -Dfile=/path/to/file -Durl=[url] -DrepositoryId=[id]
Path to dependency:
1) org.apache.httpcomponents:httpcore:jar:4.1.2
1 required artifacts are missing.
As per above error it suggests, Alternatively, if you host your own repository you can deploy the file there.
how can i provide a local repository to pom.xml.
This article explains what you require. Quoting from it:
A maven repository is just a directory somewhere, and that’s about it. In order to use it there are very few steps you need to do.
Choose a directory
Make sure its accessible via some network protocol to everyone who needs it (i.e. serve it via http or ftp or something.
Put the libraries you need in the directory, in a specific format.
Set up your maven builds to read from the repository
(optional) set up your maven builds to deploy your repository
To put existing libraries into the repository, use the maven deploy command.
To set up your build to read from the repository add the following xml to your pom.xml file:
servername-download
description
https://host/path
A detailed article for complete understanding of Maven repositories
Are you sure your Maven setup works? The artifact you're looking for is in the public Maven repository:
http://repo1.maven.org/maven2/org/apache/httpcomponents/httpcore/4.1.2/
It should be found just like any other publicly available artifact. Please check the spelling of the artifact and group in your pom file to make sure that you don't have a typo.
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpcore</artifactId>
<version>4.1.2</version>
</dependency>
What does Maven print before it fails? It usually says where it's checking for the artifact - does the URL I posted above show up?
Do you see similar issues with other artifacts?
You shouldn't have to host this artifact yourself since it's publicly available. It looks like you're running Maven from an IDE - can you try to run it from command line to see if you get the same error there?
To host local repository in pom.xml we have to set up maven properly.
we need to modify settings.xml and provide the local repository path in maven packages and then used it with IDE. So now on words if JAR is not available in my local repository then and then only maven tries to search in its maven repository.
please follow below blog to configure maven properly.
http://chiragsdiary.blogspot.in/2013/02/cxf-webservice-example-step-by-step.html

Resources