Setting Local Repository in Maven - maven

I want to add a local Repository to Maven, because i want to use my own archetype for building a maven pom.
One Solution i ve found was to add this to the setting.xml:
/.m2/repository
but it doesn't work.
Has anyone a good solution?

Related

Creating maven project from local Maven repo

I am trying to create a maven project in a Windows virtual machine. But am unable to create as there is a proxy setting that doesn't allow me to connect to https://repo.maven.apache.org/maven2
But I do have another link that have the maven repos. But am not sure how to create the maven project using the link that I have. Can someone help me?
Thanks
You can specify another repository in your pom.xml file, but you’ll have to do it for every maven project you’ll build.
You can also specify that repository in your settings.xml file, which will be available to all maven projects.
See the informations here : https://maven.apache.org/guides/mini/guide-multiple-repositories.html

How to include csjdbc.jar as part of maven dependency?

I have been looking for a dependency for csjdbc.jar in Maven repository so that I can build my app using maven and retrieve that jar on the fly. However, I cannot find a dependency in Maven repository related to that jar. Can anyone help, please?
Hopefully you have already resolved this issue.
csjdbc.jar is not listed in maven repositories. If you have composite software installed you can copy the jar from
~\Composite Software\CIS 6.1.0\apps\jdbc\lib
directory to your local machine's maven repository like below with proper versioning:
C:\maven\repository\composite\csjdbc\6.1\csjdbc-6.1.jar
(I have 6.1 jar)

How to update maven repository manually from the maven build?

We do not have our own repository at the moment. So, when we build with maven it creates .m2 repository in the home directory of the current user.
Now there are two third party jars which are not found in the Maven Central. Suppose one of them is hasp-srm-api.jar. Today the process is this:
a. The pom.xml of the project depending on hasp-srm-api.jar contain these lines:
<dependency>
<groupId>com.safenet</groupId>
<artifactId>hasp</artifactId>
<version>1</version>
</dependency>
b. Before doing the first build we execute the following command:
mvn install:install-file -Dfile=hasp-srm-api.jar -DgroupId=com.safenet -DartifactId=hasp -Dversion=1 -Dpackaging=jar
My question is this - is it possible to automate this step? I would like to be able to tell maven to check whether the hasp artifact exists and if not - install it manually using the aforementioned command line. How can I do it?
NO. It is not possible to have maven automatically deploy an artifact into a repository in the fashion you suggest. This goes for both local and remote repositories. If the artifact exists in a some repository somewhere, you can add that repository to your build's list of known remote repos, but other than that you have to add it yourself.
You can add it to your local .m2 repository, but that will then only be good for that individual environment. Other dev's will have to repeat the process. This is one of the main attractions of running your own repository server( like Nexus ); you can add the artifact to that repository and then everyone in your organization can use it forever. There is still no way to automate the deployment of the artifact, but it's easy to do and is permanent.
Note, setting up a repository manager is very easy to do. It's highly recommended. It makes the whole Maven thing make a whole lot more sense.
The best solution for such problems is using a repository manager which results in installing such kind of dependencies only once into the repository manager and the whole company can use it a usual dependency. That's it.
Other option you have is to write your own maven plugin. May be below link will be right place for you start
MOJO FAQ

maven repositories

I'm new to maven. I'm still failing to grasp the concept of it.
For example I'm looking for com.extjs:gxt:jar:2.2.5 or org.syslog4j:syslog4j:jar:0.9.46. I can't find them in any repo. Yet they seem fairly common packages.
Does that mean I have to download them by hand ? Doesn't it defeat the whole idea of maven ?
Where can I find a good repository that will have all these artifacts so that I don't need to download the jars by hand ?
What am I doing wrong when using maven, this definitely does not seem the way to go...
You're not doing anything wrong. The issue is that those artifacts don't exist in maven central repository. By default, that's the only repository maven will download from. You can add additional repositories (see maven docs) to configure repositories that aren't mirrored to central automatically.
As #Michael said, you are not doing anything wrong.
The default Maven central repository is not going to provide every possible artifact on the earth.
Normally you can have two way to solve it:
1) The artifact you use may be provided by some organization, which they provide their own repository to host those artifact. Tell Maven to lookup those repositories so that Maven can retrieve the corresponding artifact.
or
2) Get the JAR etc and put in your local environment.
There are two most commonly used ways for the above work:
A) Have a "local" maven repository/proxy (e.g. Nexus, Artifactory), and make your Maven points to this repository. Adding new remote repository (1) is mostly done by adding extra repo to proxy under your local Maven repo. Manually handling 3rd party artifact (2) is done by deploying the JAR to your local repo.
B) All done locally by your local Maven. Adding new remote repo (1) is done by updating the settings.xml (or your project POM.xml). Manually handling 3rd party artifact (2) is done by installing 3rd party JAR to local repository.
you can use
<dependency>
<groupId>com.extjs</groupId>
<artifactId>gxt</artifactId>
<version>2.3.0-gwt22</version>
</dependency>

How do I add an artifact to a local maven repository so that it will properly reference its own set of dependencies?

I am developing an application that depends on a number of legacy JAR files and I want the project to build straight out of version control without other users having to install these JARs in their local repository. I cannot add them to the corporate repository so I have created a repository that is local to this project and I have added these JARs to that repository using maven-install-plugin:install-file and setup the repository entry in the POM file so it knows to search the local repository.
This works exactly the way I want...up to a point. The problem is that most of these legacy JAR files have their own set of dependencies. I would like for them to work just like other artifacts that have their own set of dependencies so that maven can resolve everything and include all the necessary files but I can't find a way to do this with any maven-install-plugin:install-file options (or any other maven commands/plugins). I am pretty new at maven so I am probably just ignorant on this point.
As a work around, I attempted to go into the local repository directory and manually edit the POM file for the artifact to include the dependencies. This didn't cause any errors but it is also not pulling in those dependencies.
Can someone out there give me a clue?
The maven-install-plugin:install-file goal has a pomFile attribute. You can use this to specify a POM file for your legacy jar. You would create a POM file that points to all of the dependencies by artifactId in the <dependencies> section. If you have a remote nexus repository you can use the admin screen for the repository to deploy a jar.
Once you edit POM files in your project specific repository, host it as maven repo using Maven Repository Managers (like sonatype nexus). Add your project nexus repo as one of the maven repo in project pom.xml as below
<repositories>
<repository>
<id>my-project-mvn-repo</id>
<name>my-project-mvn-repo</name>
<url>http://<your project maven repo URL here></url>
</repository>
<repositories>
Now all developers should be able to make build. The legacy jar files POM contains dependency. Maven should take care of automatically pulling dependent jars on developer's workspace.

Resources