Maven does not find local dependency - java

TL;DR
Maven does not find <importedGroupid>:<importedArtifactid>:jar:1.0 in repository file://<homeDirectory>/.m2/repository/. The package actually is in <homeDirectory>/.m2/repository/<importedGroupid>/<importedArtifactid>/1.0/
I do not presume to understand Maven, but the two potential reasons I could imagine are:
it gets confused with : and / (i.e. UNIX style path seperator vs. whatever : means in Maven), or
if : and / are actually interpreted as the same, the path it searches for includes another subdirectory level jar that is not present in the real directory structure.
Detailed Explanation
I was trying to import a package locally in Maven (as the package is not deployed online). Various answers (e.g., this, and this) on stackoverflow recommend running mvn install on the jar containing the package like so (assuming the jar is in /usr/share/java, is version 1.0, etc. etc.):
mvn install:install-file -Dfile=/usr/share/java/<importedArtifactid>-1.0-SNAPSHOT.jar -DgroupId=<importedGroupid> -DartifactId=<importedArtifactid> -Dversion=1.0 -Dpackaging=JAR -DgeneratePom=true
and defining this in the current package's pom.xml by adding:
<repository>
<id>repository</id>
<url>file://${user.home}/.m2/repository/</url>
</repository>
The mvn install command deploys the package into <homeDirectory>/.m2/repository/. So far, this works fine:
<prompt> $ mvn install:install-file -Dfile=/usr/share/java/<importedArtifactid>-1.0-SNAPSHOT.jar -DgroupId=<importedGroupid> -DartifactId=<importedArtifactid> -Dversion=1.0 -Dpackaging=JAR -DgeneratePom=true
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building <currentDirectoryProject> 1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-install-plugin:2.4:install-file (default-cli) # <currentDirectoryProjectArtifactid> ---
[INFO] Installing /usr/share/java/economicsl-1.0-SNAPSHOT.jar to <homeDirectory>/.m2/repository/<importedGroupid>/<importedArtifactid>/1.0/<importedArtifactid>-1.0.JAR
[INFO] Installing /tmp/mvninstall256012398997457078.pom to <homeDirectory>/.m2/repository/<importedGroupid>/<importedArtifactid>/1.0/<importedArtifactid>-1.0.pom
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 0.489 s
[INFO] Finished at: 2017-05-11T19:11:12+01:00
[INFO] Final Memory: 9M/292M
[INFO] ------------------------------------------------------------------------
<prompt> $
The package also appears in <homeDirectory>/.m2/repository/
<prompt> $ ls `<homeDirectory>/.m2/repository/<importedGroupid>/<importedArtifactid>/1.0/`
<importedArtifactid>-1.0.JAR <importedArtifactid>-1.0.jar.lastUpdated <importedArtifactid>-1.0.pom _remote.repositories
<prompt> $
However, building the project that attempts to import the package fails:
<prompt> $ mvn package -U
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building <currentDirectoryProject> 1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
Downloading: file://<homeDirectory>/.m2/repository/<importedGroupid>/<importedArtifactid>/1.0/<importedArtifactid>-1.0.jar
Downloading: https://repo.maven.apache.org/maven2/<importedGroupid>/<importedArtifactid>/1.0/<importedArtifactid>-1.0.jar
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 0.730 s
[INFO] Finished at: 2017-05-12T17:59:43+01:00
[INFO] Final Memory: 13M/292M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal on project <currentDirectoryProjectArtifactid>: Could not resolve dependencies for project <currentDirectoryProjectGroupid>:<currentDirectoryProjectArtifactid>:jar:1.0-SNAPSHOT: Could not find artifact <importedGroupid>:<importedArtifactid>:jar:1.0 in repository (file://<homeDirectory>/.m2/repository/) -> [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
<prompt> $
If an absolute path to the jar in /usr/share/java is defined in the pom.xml, the project builds successfully with a warning about not using absolute paths, but execution fails as it does not find the package again this time.
Maven version is Apache Maven 3.3.9.
Placeholders
<currentDirectoryProject> The project that is supposed to import the other package. All terminal commands are executed from the root directory of this project (this is where its pom.xml resides).
<currentDirectoryProjectArtifactid> ArtifactID of the project that is supposed to import the other package.
<currentDirectoryProjectGroupid> GroupID of the project that is supposed to import the other package.
<importedArtifactid> ArtifactID of the project that is to be imported
<importedGroupid> GroupID of the project that is to be imported
<homeDirectory> the user's home directory, i.e. /home/<userName>
<prompt> terminal prompt

You have a file extension "JAR" in upper case and maven is looking "jar" in lower case. If your file system is case sensitive, then that's important.

Related

The system cannot find the file specified while trying to install JAR with sources with Maven

I was using the followig command to build the project
mvn compile exec:java clean install
and it was working. I wished it to install sources to local repository and wrote
mvn compile exec:java source:jar clean install
and now it fails with
...
[INFO] Replacing original artifact with shaded artifact.
[INFO] Replacing MYSOURCEPATH\target\my-library-1.12.1.jar with MYSOURCEPATH\target\my-library-1.12.1-shaded.jar
[INFO] Dependency-reduced POM written at: MYSOURCEPATH\dependency-reduced-pom.xml
[INFO] Dependency-reduced POM written at: MYSOURCEPATH\dependency-reduced-pom.xml
[INFO]
[INFO] --- maven-install-plugin:2.4:install (default-install) # my-library ---
[INFO] Installing MYSOURCEPATH\target\my-library-1.12.1.jar to MYLOCALREPOPATH\MYLIBRARYPATH\1.12.1\my-library-1.12.1.jar
[INFO] Installing MYSOURCEPATH\dependency-reduced-pom.xml to MYLOCALREPOPATH\MYLIBRARYPATH\1.12.1\my-library-1.12.1.pom
[INFO] Installing MYSOURCEPATH\target\my-library-1.12.1-sources.jar to MYLOCALREPOPATH\MYLIBRARYPATH\1.12.1\my-library-1.12.1-sources.jar
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 23.280 s
[INFO] Finished at: 2018-02-26T18:38:23+03:00
[INFO] Final Memory: 46M/1373M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-install-plugin:2.4:install (default-install) on project my-library: Failed to install artifact my.library.fqn:my-library:jar:sources:1.12.1: MYSOURCEPATH\target\my-library-1.12.1-sources.jar (The system cannot find the file specified) -> [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/MojoExecutionException
how to fix/overcome?
Try
mvn clean source:jar compile install exec:java
Or just:
mvn clean source:jar install exec:java
So basically you need to put the "clean" before the "source:jar"
or else installation for sources will fail

Unable to download jersey-quickstart-webapp from maven

I am trying download a jersey-quickstart-webapp using maven. I am unable to figure out what is wrong with my command below.
mvn archetype:generate -DarchetypeGroupId=org.glassfish.jersey.archetypes -DarchetypeArtifactId=jersey-quickstart-webapp -DarchetypeVersion=2.2
The errors I get are below: what am I doing wrong here?
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building Maven Stub Project (No POM) 1
[INFO] >>> maven-archetype-plugin:3.0.0:generate (default-cli) > generate-sources # standalone-pom
[INFO] Generating project in Interactive mode
[WARNING] No archetype found in remote catalog. Defaulting to internal catalog
[WARNING] Archetype not found in any catalog. Falling back to central repository
(http://repo.maven.apache.org/maven2).
[WARNING] Use -DarchetypeRepository=<your repository> if archetype's repository is elsewhere.
Downloading: http://repo.maven.apache.org/maven2/org/glassfish/jersey/archetypes/jersey-quickstart-webapp/2.2/jersey-quickstart-webapp-2.2.pom
Downloading: https://repo.maven.apache.org/maven2/org/glassfish/jersey/archetypes/jersey-quickstart-webapp/2.2/jersey-quickstart-webapp-2.2.pom
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 3.330 s
[INFO] Finished at: 2017-03-29T20:46:00+05:30
[INFO] Final Memory: 14M/139M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-archetype-plugin:3.0.0:generate (default-cli) on project standalone-pom: The desired archetype does not exist (org.glassfish.jersey.archetypes:jersey-quickstart-webapp:2.2) -> [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.
The version you have specified is wrong(NOT 2.2 its 2.25.1). Try to run this:
mvn archetype:generate -DarchetypeGroupId=org.glassfish.jersey.archetypes -DarchetypeArtifactId=jersey-quickstart-webapp -DarchetypeVersion=2.25.1
The issue was not with the command but the settings.xml.
I had to add my local artifactory setton

WordCount example runs in Eclipse, but not in terminal

I tried running first of the WordCount examples and it works in Eclipse (I have Windows 7 OS), but not in shell, using the command:
mvn compile exec:java -Dexec.mainClass=com.google.cloud.dataflow.examples.MinimalWordCount
I have installed Maven and configured JAVA_HOME and Path variables and so on, however, I'm not sure what I must have missed. This is the output:
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building Tutorial 0.0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) # Tutorial ---
[WARNING] Using platform encoding (Cp1250 actually) to copy filtered resources,
i.e. build is platform dependent!
[INFO] skip non existing resourceDirectory C:\Java\eclipse-jee-luna-SR2-win32-x8
6_64\eclipse\workspace\Tutorial\src\main\resources
[INFO]
[INFO] --- maven-compiler-plugin:3.3:compile (default-compile) # Tutorial --
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] --- exec-maven-plugin:1.4.0:java (default-cli) # Tutorial ---
[WARNING]
java.lang.ClassNotFoundException: com.google.cloud.dataflow.examples.MinimalWord
Count
at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
at org.codehaus.mojo.exec.ExecJavaMojo$1.run(ExecJavaMojo.java:281)
at java.lang.Thread.run(Thread.java:744)
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 3.011 s
[INFO] Finished at: 2015-11-03T01:11:57+01:00
[INFO] Final Memory: 17M/178M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.codehaus.mojo:exec-maven-plugin:1.4.0:java
(default-cli) on project Tutorial: An exception occured while executing the Java
class. com.google.cloud.dataflow.examples.MinimalWordCount -> [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/MojoExecutionE
xception-
I am in the dark about how to proceed and would very much appreciate ideas of where to look next and other things to try.
Thanks!
You may have run into an issue with the documentation.
The command line you are using should work if you have cloned GoogleCloudPlatform/DataflowJavaSDK-examples. The mention of the particular repo to clone is way back in "getting started", not at all obvious if you head straight to WordCount Example Pipeline.
But if you generated the project from the Cloud Dataflow Plugin for Eclipse (or via a Maven archetype) then the examples are placed into your Java package. So instead of com.google.cloud.dataflow.examples.MinimalWordCount you will use the name my.java.project.MinimalWordCount, where my.java.project is whatever package name you chose when you created the project.
Or if you have cloned the SDK itself from GoogleCloudPlatform/DataflowJavaSDK then you will need to add -pl examples to your command line. This is because the SDK's repository is factored into maven modules; this flag instructs maven to run in the context of the examples module.
If you have a multi-module maven project (DataflowJavaSDK, not DataflowJavaSDK-examples), you can do mvn compile in the top directory, then cd into examples and then issue the mvn exec:java -Dexec.mainClass=... command there.

The POM for org.picketlink.distribution:picketlink-jbas7:jar:2.8.0. is missing, no dependency information available

I'm trying to run the picketlink quickstarts from:
https://github.com/jboss-developer/jboss-picketlink-quickstarts
More specifically:
https://github.com/jboss-developer/jboss-picketlink-quickstarts/tree/master/picketlink-federation-saml-idp-basic
But in each attempt to install the maven dependencies I get the next error:
Could not find artifact org.picketlink.distribution:picketlink-jbas7:jar:2.8.0.Beta1-SNAPSHOT
Here is the whole log after my $ mvn clean package jboss-as:deploy
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building PicketLink Quickstart: picketlink-federation-saml-idp-basic 2.8.0.Beta1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[WARNING] The POM for org.picketlink.distribution:picketlink-jbas7:jar:2.8.0.Beta1-SNAPSHOT is missing, no dependency information available
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 0.650 s
[INFO] Finished at: 2015-10-17T01:39:15-05:00
[INFO] Final Memory: 6M/80M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal on project picketlink-federation-saml-idp-basic: Could not resolve dependencies for project org.picketlink.quickstarts:picketlink-federation-saml-idp-basic:war:2.8.0.Beta1-SNAPSHOT: Could not find artifact org.picketlink.distribution:picketlink-jbas7:jar:2.8.0.Beta1-SNAPSHOT -> [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
I've seen that you might need to add a settings.xml to your maven folder, but I don't know how to make or what to put in that file.
As you already said, maven is telling you that org.picketlink.distribution:picketlink-jbas7:jar:2.8.0.Beta1-SNAPSHOT dependency is missing and I believe this is because you didn't install it previously.
As I can see jboss-picketlink-quickstarts is a bunch of projects which have a parent pom.xml where you can find your project as a module:
<module>picketlink-federation-saml-idp-basic</module>
So, you have to clone the whole jboss-picketlink-quickstarts project and run mvn install from the parent project.
This will lead you with all dependencies that you will need resolved into your local maven repository (usually ~/.m2/repository).
Try it, it will solve your dependency. Some times you have to call maven with -U to force -SNAPSHOT dependencies.
Hope it helps!

Maven 3: Maven in 5 minutes "mvn archetype:generate..." command NOT WORKING

I installed Maven 3.1.1 for the first time. In the "Maven in 5 Minutes" getting-started guide
http://maven.apache.org/guides/getting-started/maven-in-five-minutes.html
it says to verify the installation with
mvn --version
I got the expected response:
Apache Maven 3.1.1 (0728685237757ffbf44136acec0402957f723d9a; 2013-09-17 11:22:22-0400)
Maven home: C:\applications\programming\apache-maven-3.1.1
Java version: 1.6.0_17, vendor: Sun Microsystems Inc.
Java home: C:\applications\programming\java_6_17\jre
Default locale: en_US, platform encoding: Cp1252
OS name: "windows 7", version: "6.1", arch: "x86", family: "windows"
In the next step, under "Creating a project" it says to create a new directory, open a command prompt in that directory, and execute
mvn archetype:generate -DgroupId=com.mycompany.app -DartifactId=my-app -DarchetypeArtifactId=maven-archetype-quickstart -DinteractiveMode=false
I created a directory called xjmaven, ran the command in it, and it's not working. This is the response:
[R:\jeffy\programming\sandbox\xjmaven]mvn archetype:generate -DgroupId=xbnjava -DartifactId=XBN-Java -Darchetype ArtifactId=maven-archetype-quickstart -DinteractiveMode=false
[INFO] Scanning for projects...
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 0.251s
[INFO] Finished at: Sat Nov 23 12:11:56 EST 2013
[INFO] Final Memory: 2M/4M
[INFO] ------------------------------------------------------------------------
[ERROR] The goal you specified requires a project to execute but there is no POM in this directory (R:\jeffy\programming\sandbox\xjmaven). Please verify you invoked Maven from the correct directory. -> [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/MissingProjectException
I looked up the parameters groupId, artifactId and archetypeArtifactId, and have tried some different values (as you can see above), but I still get the same BUILD FAILURE response.
I manually put the pom.xml file (from in the same webpage) in the xjmaven directory, and ran it again. It downloaded a bunch of stuff (although not to xjmaven), but then failed with this message:
[INFO] Generating project in Interactive mode
Downloading: http://repo.maven.apache.org/maven2/org/apache/maven/archetypes/true/1.0/true-1.0.jar
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Skipping Maven Quick Start Archetype
[INFO] This project has been banned from the build due to previous failures.
[INFO] ------------------------------------------------------------------------
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 45.047s
[INFO] Finished at: Sat Nov 23 12:04:01 EST 2013
[INFO] Final Memory: 7M/17M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-archetype-plugin:2.2:generate (default-cli) on project XBN-Java: The desired archetype does not exist (org.apache.maven.archetypes:true:1.0) -> [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/MojoFailureException
Repeating the command gives this response:
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building Maven Quick Start Archetype 1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] >>> maven-archetype-plugin:2.2:generate (default-cli) # XBN-Java >>>
[INFO]
[INFO] <<< maven-archetype-plugin:2.2:generate (default-cli) # XBN-Java <<<
[INFO]
[INFO] --- maven-archetype-plugin:2.2:generate (default-cli) # XBN-Java ---
[INFO] Generating project in Interactive mode
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Skipping Maven Quick Start Archetype
[INFO] This project has been banned from the build due to previous failures.
[INFO] ------------------------------------------------------------------------
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 4.444s
[INFO] Finished at: Sat Nov 23 12:04:32 EST 2013
[INFO] Final Memory: 8M/14M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-archetype-plugin:2.2:generate (default-cli) on project XBN-Java: The desired archetype does not exist (org.apache.maven.archetypes:true:1.0) -> [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/MojoFailureException
I deleted pom.xml (it's the only file in the directory...the stuff it downloaded is not there), and started over again. Everything happens (badly) as I write above.
I remember trying Maven a few years ago, and could also not get past the getting-started stage.
If anyone has some advice on how to get past this, it would be appreciated. Really frustrated.
Maybe you are using Windows PowerShell?
If so, you'll need to put quotes around the parameter definitions:
mvn archetype:generate "-DarchetypeGroupId=org.apache.maven.archetypes" "-DgroupId=com.mycompany.app" "-DartifactId=my-app"
You have some syntactical errors while executing the generate goal. Moreover, you need not create the pom.xml or any dir sturcture. You will notice that the generate goal creates a directory with the same name given as the artifactId.
e.g. you are missing the convention like -DgroupId should be com.company.app (not a big issue though), having space in -Darchetype ArtifactId, etc.
I just tried below and it worked :
mvn archetype:generate -DgroupId=com.mycompany.app -DartifactId=my-app -DarchetypeArtifactId=maven-archetype-quickstart -DinteractiveMode=false
I was having a similar issue on powershell. I switched to command prompt and executed the same command and it works fine. Command that works on command prompt: mvn archetype:generate -DgroupId=com.myapp-DartifactId=hellomaven -DarchetypeArtifactId=maven-archetype-quickstart -DinteractiveMode=false
The one that runs on powershell:
mvn archetype:generate "-DarchetypeGroupId=org.apache.maven.archetypes" "-DgroupId=com.myapp" "-DartifactId=my-app"

Categories

Resources