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

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.

Related

Quickest POM settings to turn an existing Eclipse web project in a Maven-managed project?

I'm converting an existing Eclipse-based web project to a Maven-managed one.
Since the project has lots of dependencies, many of which are custom (they're either internally made or they've been taken from sources that have no public repository), is there some 'magic' Maven POM setting that will let me load every jar from WebContent/WEB-INF/lib and make the project work as before right now, so that I can configure each dependency and do the necessary refactoring to turn it to a proper Maven project with a little more time and care?
I have already seen this question, but the project must continue to compile inside Eclipse, so - or at least I guess - it is not just a matter of using the Maven war plugin
What you want to do is called "installing" your non-mavenized JARs into your maven repository. This can be a local or remote repo that you host.
The command to install to your local repo is something like this: mvn install:install-file -Dfile=My-lib.jar -DgroupId=com.mycompany -DartifactId=My-lib -Dversion=1.2.3 -Dpackaging=jar
You'll want to review the various options for install to suit your project.
Once the non-mavenized dependencies are installed to your repo you can add them to your pom like any other maven dependency. They will be fetched from your local repo.
You will have to set up your own remote repo (like Artifactory) or install each plugin for every developer and CI server in your environment for others on your team to build the project. I strongly reccomend Artifactory, it makes it easy on your and your team to use maven and get dependencies.

Project specific local repository in maven

Is there a maven equivalent of Node.js npm i which fetchs all the dependencies under node_modules directory, or Ruby bundle install --path <directory-path>?
I'm looking for a way to manage the dependencies written in pom.xml on the project's own responsibility. Without anything, all the artifacts are downloaded into ~/.m2/repository which is shared by all existing maven projects.
The version of maven is 3.1.1. Is there any good idea?
If you really like to change the repository for every project you can use the following:
mvn -Dmaven.repo.local=/WhatEverDirYouLike clean install
but it contradicts to the idea of the local repository.

Error on starting maven

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.

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.

How does my firm get a jar into a maven repo so maven projects can access it from inhouse

How does my firm get a jar into a maven repo so maven projects can access it from inhouse.
Can someone please point me to a good step by step details on how to do the following
Make a jar with Maven
Get the jar installed into a local maven repo
I doubt your company wants their private internal code hosted on a public repository:
Install your own repository server inside your own network, I use Archiva. This is the most ideal solution, then you can set up Mavenized projects to automatically upload themselves to your private repository when you do mvn:release and everyone will see the new versions. How to use Archiva is all very well documented.
If they have open source code that want to share, that is different:
You can publish public facing open source code through Sonatype.
If you just want to install a dependency to a local repository:
If you just want to install a .jar locally that is easy and well documented.
mvn install:install-file -Dfile=path-to-your-artifact-jar \
-DgroupId=your.groupId \
-DartifactId=your-artifactId \
-Dversion=version \
-Dpackaging=jar

Categories

Resources