Error on starting maven - java

I am trying to create a simple maven project and stumbled on an error upon executing this conmmand in the command line:
mvn archetype:generate -DgroupId={project-packaging} -DartifactId={project-name} -DarchetypeArtifactId=maven-archetype-quickstart -DinteractiveMode=false
I am using fresh out of the box maven so I still don't have a settings.xml. Maven says that I don't have the archetype plugin and upon looking for solutions I found out that the maven central repo is not accessible in my network(maybe configured in firewall). How can I proceed now?
Thanks

If you don't have net access, try downloading the required artifacts and placing them in your local repository. The local repository path would be in the settings.xml file placed in your maven installation directory/conf. You can also try connecting to the maven central repository using a proxy setting if it is feasible.

Related

How to employ internal maven repo to generate a maven project Skeleton

I normally use this mvn command to generate a maven project skeleton:
mvn archetype:generate -DarchetypeGroupId=org.apache.maven.archetypes -DgroupId=com.mycompany.app -DartifactId=my-app
The thing is that maven goes maven official repo (repo.maven.apache.org) for artifacts downloading. It failed if I tried to do this from behind the company's firewall. The company does have a maven repo mirror site, but I don't know how to re-direct maven to use that one rather than the official maven repo site.
Is there a configure change / walk around in this case?
You need to configure the repository in the settings.xml.
If your company has a repository, they maybe already have a standard settings.xml.

Maven Dependencies are not installing in eclipse

I am using the maven embedded eclipse.
Tried :
Deleting the whole m2 repository.
Maven->Update Project.
Run as -> Maven Build
User settings file does not exist(Please don't tell me it has to something with this file)
settings.Xml file
This file is only required if you are using a proxy and i am not
I have every dependency present in pom.xml file of my project but still eclipse is not able to import all these dependencies in the project
I have attached the photo below. Please help me to resolve my issue
mvn dependency:tree
Maven Dependencies
POM.xml file
List of dependency present in pom file of my project
None of the methods mentioned above worked so please help me to solve this issue.
Is there anything related to maven or eclipse version ?
When you execute mvn dependency:tree result shows an error related to "i cannot obtain some jar", it may be due to private reporitory.
If you are working with private repository, make sure you configure access in $HOME/.m2/settings.xml
On another hand I see you are working with snapshots. If you are trying to bind projects you have in your local host machine, ensure you are executing mvn install (or better mvn source:jar install) sucessfully and your system's maven is pointing the same .m2 path that refers Eclipse maven plugin
It seems using the Spring framework Maven repository via HTTP instead of HTTPS causing this issue.
In your pom.xml file replace http://maven.springframework.org with https://maven.springframework.org.

Maven archetype:generate plugin 3.0 how to specify remote repository

I tried to create maven project using archetype which is absent in Maven central repo, but exists in another remote repository.
In maven-archetype-plugin version 2.4 I could use -DarchetypeRepository param for specify another repo where maven should look for my archetype.
In the new version (3.0) this param doesn't work. (Proof: http://maven.apache.org/archetype/maven-archetype-plugin/generate-mojo.html#archetypeCatalog)
So I needed to use old version of plugin and wrote long command such as
$ mvn org.apache.maven.plugins:maven-archetype-plugin:2.4:generate -DarchetypeGroupId=some.id -DarchetypeArtifactId=some.another.id -DarchetypeVersion=some.version -DarchetypeRepository=repo.url
How can I do the same command using maven-archetype-plugin:3.0?
I tried to use archetypeCatalog=repo.url, but it doesn't work this way, I can only set local or remote repo with it.
Thanks.
Plugin developer's answer:
Allowing to set a URL via commandline is considered to be a security leak, so specifying the repository (id: archetype) in the settings.xml is the right way.
From the Maven Archetype plugin reference:
As of Maven Archetype Plugin 3.0.0 the archetype resolution has changed: it is not possible anymore to specify the repository via the command line (with -DarchetypeRepository=repo.url), but instead the repositories as already defined for Maven are used.
This means that you must add a repository entry to your settings.xml, see the link above.
You can specify your repository in your settings.xml as [archetypeArtifactId]-repo. This is defined as one of the FAQs.
If you do not have authentication, don't specify it in settings.xml.
OR
I just ran the following command,
mvn org.apache.maven.plugins:maven-archetype-plugin:3.0.0:generate
-DarchetypeGroupId=org.grails
-DarchetypeArtifactId=grails-maven-archetype
-DarchetypeVersion=1.0
-DarchetypeCatalog=http://snapshots.repository.codehaus.org
and it gave me following warning,
[WARNING] Archetype not found in any catalog. Falling back to central
repository (http://repo.maven.apache.org/maven2).
[WARNING] Use -DarchetypeRepository= if archetype's repository is elsewhere.

MVN install, cannot find artifact in local repository

I did mvn install and get this error message
Failed to execute goal on project core: Could not resolve dependencies for project test:core:jar:2.0.1-SNAPSHOT: Could not find artifact lib-net:lib-net:jar:1.0.8 in central (http://repo.maven.apache.org/maven2)
this dependency is a Project of mine, which is available in the local repository ~/.m2
so I tried mvn install -o to force maven to use my local repository, and I get this
Failed to execute goal on project core: Could not resolve dependencies for project test:core:jar:2.0.1-SNAPSHOT: The repository system is offline but the artifact lib-net:lib-net:jar:1.0.8 is not available in the local repository.
I tried to delete my local repository and install everything again, but it doesn't solve my problem!
Any sugestions?
The problem is with maven version. I had the same issue on my Jenkins machine. I followed these steps and it resolved my issue:
Delete the specific older libraries in ~/.m2/
Change the version of maven to apache-maven-3.5.0
Re-run the maven goals
Think I know way how to do it properly
Download sources of your library locally
Go to ~/.m2/ and search for your lib
Delete it from here
perform "mvn clean install" for your library
search for your lib in ~/.m2/
try to "mvn clean install" on your main project
... ?
Profit
If it will no work, check that you use correct artifact id and group id.

How to provide artifacts to a maven project if those are not in public repository?

I cloned an open source library project from Github, that I'd like to use for my own Java project. This library depends on some other jars that cannot be found in any public repository. This causes mvn package to fail:
[ERROR] Failed to execute goal on project commons-gdx-core:
Could not resolve dependencies for project
com.gemserk.commons.gdx:commons-gdx-core:jar:0.0.11-SNAPSHOT:
The following artifacts could not be resolved:
com.badlogic.gdx:gdx:jar:0.9.8-SNAPSHOT,
com.gemserk.animation4j:animation4j-core:jar:0.2.2-SNAPSHOT,
com.gemserk.vecmath:vecmath:jar:1.5.3-GEMSERK:
Could not find artifact com.badlogic.gdx:gdx:jar:0.9.8-SNAPSHOT -> [Help 1]
I think I can get these jars from other sources but I don't know how to tell maven where to look for them.
as example, we have Oracle JDBC driver. You must install it into your local maven repository.
Download your lib to local folder (i.e.: Path/to/private/library.jar)
mvn install:install-file -Dfile= -DgroupId=
-DartifactId= -Dversion= -Dpackaging=jar
Or, a more advanced way, if you have a Maven Repository (like Sonatype Nexus), you can deploy it on repository and map it on your project. But, I think that you need the first option.
Use the repositories and repository tags to point to the private repositories in your pom file or update your settings.xml in the same way. Maven will download the artifacts once you tell it where to look.
Answers from apast and Chris are both correct. But if you change your computer or clean up your local repository, you project still can't be compiled. What I suggest is using system dependencies and add the jar under git version control. Here's an example.

Categories

Resources