Archetype Selection Using m2eclipse - java

I would like to create a new Maven project in Eclipse using an archetype using the New Maven Project wizard. At the "Select an Archetype" step, I have three catalogs to choose from: Nexus Indexer, Internal and Default Local. I don't understand where the content for these catalogs should be coming from. If I click on the "Configure" button, they are all greyed out and I can't modify them.
Only the Internal catalog has any archetypes listed in it. Where are these archetypes coming from? It's not from my local Maven repository because the group/artifacts are not in it (and archetypes in the repo are not listed).
Why is the Nexus Indexer list empty? I've read some posts that the Nexus index needs to be updated, but not how to do this. Is this different than the repository indexes (which are scheduled to be updated daily).
As you can see, I'm a little confused about the whole catalog business and how Maven, m2eclipse and Nexus interact. Any clarification is most welcome!
My setup:
Eclipse: Helios Service Release 2 (Build id: 20110218-0911)
Apache Maven 3.0.3
m2eclipse: 0.12.1.20110112-1712 (set up to use external Maven install)
Sonatype Nexus™ Open Source Edition, Version: 1.9.0.2
My local Maven settings.xml looks like this:
<settings>
<mirrors>
<mirror>
<!--This sends everything else to /public -->
<id>nexus</id>
<mirrorOf>*</mirrorOf>
<url>http://myserver:8080/nexus/content/groups/public</url>
</mirror>
</mirrors>
<profiles>
<profile>
<id>nexus</id>
<!--Enable snapshots for the built in central repo to direct -->
<!--all requests to nexus via the mirror -->
<repositories>
<repository>
<id>central</id>
<url>http://central</url>
<releases><enabled>true</enabled></releases>
<snapshots><enabled>true</enabled></snapshots>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>central</id>
<url>http://central</url>
<releases><enabled>true</enabled></releases>
<snapshots><enabled>true</enabled></snapshots>
</pluginRepository>
</pluginRepositories>
</profile>
</profiles>
<activeProfiles>
<!--make the profile active all the time -->
<activeProfile>nexus</activeProfile>
</activeProfiles>
<servers>
<server>
<id>my-snapshots</id>
<username>user</username>
<password>password</password>
</server>
<server>
<id>my-releases</id>
<username>user</username>
<password>password</password>
</server>
</servers>
</settings>

The default archetype catalog can contain new archetypes. It's a manual process, you've to add them to a custom .xml file within your ~/.m2 directory.
For more information : http://maven.apache.org/archetype/maven-archetype-plugin/specification/archetype-catalog.html
And for reference, here's a template archetype-catalog.xml
<?xml version="1.0" encoding="UTF-8"?>
<archetype-catalog>
<archetypes>
<archetype>
<groupId>com.spedge</groupId>
<artifactId>archetype-application-custom-filter</artifactId>
<version>1.0-SNAPSHOT</version>
</archetype>
</archetypes>
</archetype-catalog>
Additionally, here's a good link on SO about Archetypes : What are the URLs of all the Maven Archetype catalogs that you know about?

Related

Add GitLab private repository as Maven dependency

I have a private repository in GitLab (it's in a group, and I have a Developer role) which I want to add as a dependency for my Maven project.
I've been looking for a while and all I found was that I have to add the following to my pom.xml:
<repositories>
<repository>
<id>gitlab-maven</id>
<url>https://gitlab.com/api/v4/projects/.../packages/maven</url>
</repository>
</repositories>
<distributionManagement>
<repository>
<id>gitlab-maven</id>
<url>https://gitlab.com/api/v4/projects/.../packages/maven</url>
</repository>
<snapshotRepository>
<id>gitlab-maven</id>
<url>https://gitlab.com/api/v4/projects/.../packages/maven</url>
</snapshotRepository>
</distributionManagement>
However, I have no idea how to add the dependency itself (with the groupId and stuff) and I'm not sure how to do authentication to allow Maven to download the project. I've seen something about Personal Access Tokens in GitLab, but I'm not sure how to set that up (I assume I'd only need read-only access?).
First, a few pre-requisites. Since you mentioned you're using a private repository, you'll need to have at least GitLab Silver (hosted on gitlab.com) or GitLab Premium (self-hosted) in order to use the GitLab Maven Packages repository. Also, if you're self-hosted, you'll need to be on GitLab 11.3 or later (should be out this time next week), and have packages_enabled set to true (see Enabling the Packages repository).
For private projects, you'll need a Personal Access Token. The token should have the api scope for Maven to upload artifacts to GitLab. Once you have the token, you configure your settings.xml like this.
<settings>
<servers>
<server>
<id>gitlab-maven</id>
<configuration>
<httpHeaders>
<property>
<name>Private-Token</name>
<value>REPLACE_WITH_YOUR_PERSONAL_ACCESS_TOKEN</value>
</property>
</httpHeaders>
</configuration>
</server>
</servers>
</settings>
In pom.xml, where you have the ellipses, you need to fill in your project ID. To find the ID, just visit the front page of your project on GitLab. It's shown near the top of the pages, just after the name and description of your project. For example, take a look at the mvn-example sample project. Its project ID is 8377576. That goes in the URL.
<repositories>
<repository>
<id>gitlab-maven</id>
<url>https://gitlab.com/api/v4/projects/8377576/packages/maven</url>
</repository>
</repositories>
The mvn-example project's pom.xml file shows a completed example.
With all that set up, you should be able to upload artifacts with mvn deploy.
First of all you should go to your projects "Packages and Registries" it is on the left menu of your Gitlab user interface and find there package registry button(if you can't see it just ask your system administrator) and just leave that tab open and wait for future instructions.
Be aware that if you work in a company that has Gitlab domain, everywhere that I write "https://gitlab.com", you should write your company's gitlab domain.
After that you should generate your "Private-Token" by going to "https://gitlab.com/profile" -> "access tokens" and select api check box and give a name to your token for example "test token" and then press generate.
After that in your java project create file "settings.xml" near your pom.xml and paste there following piece of code that is below and write there your token that you just generated. This settings.xml is required both for uploading and installing artifact.
<settings>
<servers>
<server>
<id>gitlab-maven</id>
<configuration>
<httpHeaders>
<property>
<name>Private-Token</name>
<value>your token</value>
</property>
</httpHeaders>
</configuration>
</server>
</servers>
</settings>
After that go to Gitlab's user inreface and copy your project's id from there. See screenshot:
After that paste following code that is below in your pom.xml. This must be done in the project that should be uploaded in Gitlab's "package registry"
<distributionManagement>
<repository>
<id>gitlab-maven</id>
<url>https://gitlab.com/api/v4/projects/project_id/packages/maven</url>
</repository>
<snapshotRepository>
<id>gitlab-maven</id>
<url>https://gitlab.com/api/v4/projects/project_id/packages/maven</url>
</snapshotRepository>
</distributionManagement>
For uploading artifact open terminal in your ide and paste following command:
mvn deploy -s settings.xml
After that go to "package registry" of your project in Gitlab user interface and see there uploaded artifact.
For installing the settings.xml also needed, and also paste following piece of code that is below in your pom.xml
<repositories>
<repository>
<id>gitlab-maven</id>
<url>https://gitlab.com/api/v4/projects/project_id/packages/maven</url>
</repository>
</repositories>
And in your terminal call: mvn install -s settings.xml or mvn dependency:get -Dartifact={groupId}:{artifactId}:{version}
If there is an error while installing, don't worry, got to your local computer's .m2 folder, find that folder with containing new created artifact(jar), delete it and then go and call the same terminal command once again.
To use your private repository as maven dependency go to your package Registry and click on the package(com/example/demo)
you will see the instruction to add the dependency.
You need to add tag with correct dependency and and tag.
if you will mention private repository url in both and , it will pull and push the artefact from the private repository.
If you want to use the private repository to only download the dependency and push your artifact to the current project registry, then you need to add the and tag of the private repository and tag will the current project one.
Scenario 1:-
<dependency>
<groupId>com.example</groupId>
<artifactId>demo</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
</dependencies>
<repositories>
<repository>
<id>gitlab-maven</id>
<url>https://gitlab.com/api/v4/projects/36104875/packages/maven</url>
</repository>
</repositories>
<distributionManagement>
<repository>
<id>gitlab-maven</id>
<url>https://gitlab.com/api/v4/projects/36104875/packages/maven</url>
</repository>
<snapshotRepository>
<id>gitlab-maven</id>
<url>https://gitlab.com/api/v4/projects/36104875/packages/maven</url>
</snapshotRepository>
</distributionManagement>
2nd scenario:-
<dependency>
<groupId>com.example</groupId>
<artifactId>demo</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
</dependencies>
<repositories>
<repository>
<id>gitlab-maven</id>
<url>https://gitlab.com/api/v4/projects/36104875/packages/maven</url>
</repository>
</repositories>
<distributionManagement>
<snapshotRepository>
<id>gitlab-maven</id>
<url>${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/packages/maven</url>
</snapshotRepository>
<repository>
<id>gitlab-maven</id>
<url>${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/packages/maven</url>
</repository>
</distributionManagement>

Jenkins cannot find maven dependency from local repository

I have added a jar file to my local maven repository by mvn install: install-file which works fine on my local machine. This is the dependency in my pom:
<dependency>
<groupId>com.oracle</groupId>
<artifactId>ojdbc6</artifactId>
<version>${oracle.connector.version}</version>
</dependency>
When running mvn clean install on my machine, everything works just fine.
Now I have a local jenkins instance running (on a Windows machine) which should build my project. The build runs into an error and jenkins says:
Could not find artifact com.oracle:ojdbc6:jar:11.2.0 in mirror1 (http://repo.maven.apache.org/maven2) -> [Help 1]
The project settings for jenkins looks like this:
<?xml version="1.0" encoding="UTF-8" ?>
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0" xmlns:xsi=
"http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation=
"http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/
settings-1.0.0.xsd">
<localRepository>${user.home}/.m2/repository</localRepository>
<servers>
<server>
<id>nexusReleases</id>
<username>deployment</username>
<password>deployment123</password>
</server>
<server>
<id>nexusSnapshots</id>
<username>deployment</username>
<password>deployment123</password>
</server>
</servers>
<mirrors>
<mirror>
<id>mirror1</id>
<mirrorOf>*</mirrorOf>
<name>Maven2 official repo</name>
<url>http://repo.maven.apache.org/maven2</url>
</mirror>
<mirror>
<!--This sends everything else to /public -->
<id>nexus</id>
<mirrorOf>*</mirrorOf>
<url>http://localhost:8081/repository/maven-public/</url>
</mirror>
</mirrors>
<profiles>
<profile>
<id>nexus</id>
<!--Enable snapshots for the built in central repo to direct -->
<!--all requests to nexus via the mirror -->
<repositories>
<repository>
<id>central</id>
<url>http://central</url>
<releases><enabled>true</enabled></releases>
<snapshots><enabled>true</enabled></snapshots>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>central</id>
<url>http://central</url>
<releases><enabled>true</enabled></releases>
<snapshots><enabled>true</enabled></snapshots>
</pluginRepository>
</pluginRepositories>
</profile>
</profiles>
<activeProfiles>
<!--make the profile active all the time -->
<activeProfile>nexus</activeProfile>
</activeProfiles>
</settings>
And of course I've double checked the repository directory in .m2 . The ojdbc6.jar is there.
So what's wrong with my setup?
You might want to check what Jenkins uses as its local repository.
Go to Jenkins verwalten (Manage Jenkins)
Under Maven-Projekt-Konfiguration (Maven project configuration), there should be a setting where the .m2 repository for Jenkins is located.
If that was not the same repository you were using locally, that would explain your error.
Edit: There is also an option for each job whether or not to use a "private repository". That repository will be specific to that job and not share artifacts with any other.
I had the same issue with ojdbc8.jar. The build failed with this dependency in my pom.xml.
<dependency>
<groupId>com.oracle</groupId>
<artifactId>ojdbc8</artifactId>
<version>19.3</version>
</dependency>
I copied the ojdbc8.jar to the Jenkins maven repository. After renaming it to ojdbc8-19.3.jar my build was successful.
Perhaps this helps someone else.
Use the following dependency:
<dependency>
<groupId>com.oracle.ojdbc</groupId>
<artifactId>ojdbc8</artifactId>
<version>19.3.0.0</version>
</dependency>

Maven Auth error with Artifactory

I'm trying to install artifactory in my local computer to manage all my project jars.
I've set up artifactory so it has two users: admin and user, without allowing anonymous login.
Here's my settings.xml:
<?xml version="1.0" encoding="UTF-8"?>
<settings>
<servers>
<server>
<id>central</id>
<username>user</username>
<password>{encrypted-pssw}</password>
</server>
<server>
<id>snapshot</id>
<username>user</username>
<password>{encrypted-pssw}</password>
</server>
</servers>
<mirrors>
<mirror>
<mirrorOf>*</mirrorOf>
<name>remote-repos</name>
<url>http://localhost:8081/artifactory/remote-repos</url>
<id>remote-repos</id>
</mirror>
</mirrors>
<profiles>
<profile>
<id>central</id>
<repositories>
<repository>
<id>artifactory</id>
<url>http://localhost:8081/artifactory/repo</url>
<layout>default</layout>
<name>Artifactory default repo</name>
</repository>
</repositories>
</profile>
</profiles>
<activeProfiles>
<activeProfile>central</activeProfile>
</activeProfiles>
"{encrypted-pssw}" is the passord obtained from encrypting (mvn -ep) the encrypted password from artifactory.
When I try to install ("mvn clean install") or deploy ("mvn deploy") every project it gives me this error:
Could not transfer artifact org.apache.maven.plugins:maven-clean-plugin:pom:2.5 from/to remote-repos (http://localhost:8081/artifactory/remote-repos): Not authorized , ReasonPhrase: Unauthorized. -> [Help 1]
I've tryied the rsa authentication too without any success
EDIT: more informations:
If I try to login with the broswer in the repository it asks for username and password, if I put them (using the encrypted password from artifactory) it allowes me to view the repository.
If I use as the url: http://user:passw#localhost:8081 it works and maven can login, but I need to do a lot of dirty work copying my password all over the projects if I use this workaround (note: the password used in the url is the one I get from the encrypted-password field in Artifactory, not the double-encrypted one I get from the maven command)
This can be due to the following reasons:
Can you check if this user has deploy permission on the remote repositories that are being aggregated under the "remote-repos" virtual repository? If not you should grant the user deploy permissions to the remote repositories that are needed for the builds resolution. If you are not sure you can try using an admin user and see if it worked.
Check if in your Artifactory UI --> Admin --> Security configuration --> "Hide existence of unauthorised resources" is this checkbox checked? If so you will need to define "preemptive authentication" on maven (should be defined in your settings.xml file. See in google on how to add it.
Last thing that comes to my mind, can you double check that the encrypted password was written correctly in the settings.xml file?
Hope this will assist you with finding the root cause of the issue and resolve it.
Please remove all mirrors in your file.
<?xml version="1.0" encoding="UTF-8"?>
<settings>
<servers>
<server>
<id>central</id>
<username>user</username>
<password>{encrypted-pssw}</password>
</server>
<server>
<id>snapshot</id>
<username>user</username>
<password>{encrypted-pssw}</password>
</server>
</servers>
<profiles>
<profile>
<id>central</id>
<repositories>
<repository>
<id>artifactory</id>
<url>http://localhost:8081/artifactory/repo</url>
<layout>default</layout>
<name>Artifactory default repo</name>
</repository>
</repositories>
</profile>
</profiles>
<activeProfiles>
<activeProfile>central</activeProfile>
</activeProfiles>
You should also check which settings.xml. According to the maven website:
There are two locations where a settings.xml file may live:
The Maven install: ${maven.home}/conf/settings.xml
A user’s install: ${user.home}/.m2/settings.xml
I was trying to modify the first settings.xml file with no luck, adding my credentials to the second one worked. If you run your maven command with the -e flag it will also tell you the settings file that it is trying to use

Add mysql connector to a maven / nexus build in eclipse

I'm trying to connect to a mysql database in java and so I have to add mysql-connector-java:jar to my eclipse project. The integration with maven is not working though.
Here is what I have in my settings.xml:
<profile>
<id>default</id>
<properties>
<mvn.path>.../maven-3.0.4/bin/mvn.bat</mvn.path>
<javac.5>...bin/javac.exe</javac.5>
<javac.6>..../javac.exe</javac.6>
</properties>
<repositories>
<repository>
<id>central-repository</id>
<name>OSS central Maven Release Repository</name>
<url>https://oss.sonatype.org/content/repositories/releases</url>
</repository>
<repository>
<id>public-repository-main</id>
<name>Central Repository</name>
<url>https://repo1.maven.org/maven2</url>
</repository>
<repository>
<id>public-repository</id>
<name>OSS Maven Release Repository</name>
<url>https://oss.sonatype.org/content/groups/public</url>
</repository>
</repositories>
</profile>
<interactiveMode>true</interactiveMode>
<!-- offline
| Determines whether maven should attempt to connect to the network when executing
| a build.
| This will have an effect on artifact downloads, artifact deployment, and others.
|
| Default: false <offline>false</offline> -->
<offline>false</offline>
<mirror>
<id>nexus</id>
<mirrorOf>*</mirrorOf>
<url>http://xxxx:8083/nexus/content/groups/public</url>
</mirror>
And here is the error I get when I try to a mvn clean install
Failure to find mysql:mysql-connector-java:jar:5.0.5 in
http://xxxx:8083/nexus/content/groups/public
How can I force nexus to download the artifact from my public repositories to nexus? Do I have to add it manually?
You need to tell maven to use your maven repository. To do this, modify $HOME/.m2/settings.xml as follows:
<?xml version="1.0" encoding="UTF-8"?>
<settings xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">
<mirrors>
<mirror>
<id>nexus</id>
<mirrorOf>*</mirrorOf>
<url>http://xxxx:8083/nexus/content/groups/public</url>
</mirror>
</mirrors>
<proxies></proxies>
<servers></servers>
<pluginGroups></pluginGroups>
<profiles>
<profile>
<id>nexus</id>
<!--Enable snapshots for the built in central repo to direct -->
<!--all requests to nexus via the mirror -->
<repositories>
<repository>
<id>central</id>
<url>http://central</url>
<releases><enabled>true</enabled></releases>
<snapshots><enabled>true</enabled></snapshots>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>central</id>
<url>http://central</url>
<releases><enabled>true</enabled></releases>
<snapshots><enabled>true</enabled></snapshots>
</pluginRepository>
</pluginRepositories>
</profile>
</profiles>
<activeProfiles>
<activeProfile>nexus</activeProfile>
</activeProfiles>
</settings>
The nexus profile is configured to download from the central repository with a bogus URL of http://central.
This URL is overridden by the mirror setting in the same settings.xml file to point to the URL of your single Nexus group. The nexus group is then listed as an active profile in the activeProfiles element.
Suppose you have repository Central that has repository path http://xxxx:8083/nexus/content/repositories/central and also point Remote Storage Location to http://repo1.maven.org/maven2/ you can change http://central to http://xxxx:8083/nexus/content/repositories/central or http://repo1.maven.org/maven2/.
in your pom.xml, use below dependency to getting mysql-connector.
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.33</version>
</dependency>
See also: Getting started with Nexus maven repository manager
Hope this help.
Is there a chance that you have included two different versions for mysql-connector-java?
I used to have an error like that, it turned out I had accidentally included another version, so this specific version was not accessed (it was a transitive dependency, which for peculiar reasons I could not exclude). I moved the dependency in the beginning of all other dependencies (in your case it might be in the end),and it worked. Theoretically having two versions of same dependency should not throw an error.
Here are the available versions of MySQL connector
http://mvnrepository.com/artifact/mysql/mysql-connector-java , click on any version, it will give your the dependency.

How can I tell Maven search only in intranet Repository(Artifactoy) and not in Internet

I installed maven and Artifactory.
Artifactory has an internet connection.
I configured Maven in this way.
<?xml version="1.0" encoding="UTF-8"?>
<settings
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd"
xmlns="http://maven.apache.org/SETTINGS/1.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<localRepository>X:/.m2/repository</localRepository>
<interactiveMode>true</interactiveMode>
<usePluginRegistry>false</usePluginRegistry>
<offline>false</offline>
<profiles>
<profile>
<id>dev</id>
<repositories>
<repository>
<id>MY_Artifactory</id>
<url>http://myServer/artifactory/repo</url>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>MY_Artifactory</id>
<url>http://myServer/artifactory/repo</url>
</pluginRepository>
</pluginRepositories>
</profile>
</profiles>
<activeProfiles>
<activeProfile>dev</activeProfile>
</activeProfiles>
How can I tell Maven that it searches only in Artifactory and that it should try direct with local internet?
<mirrors>
<mirror>
<id>local</id>
<name>Local Artifactory</name>
<url>http://url/for/artifactory</url>
<mirrorOf>central</mirrorOf>
</mirror>
</mirrors>
add this to settings.xml
If you have already configured profiles using below command you can call them.
mvn clean install -P dev
The above will use dev profile .
Edit: Other way is you can override built-in repositories .
Please go through this i feel it is helpful.
http://wiki.jfrog.org/confluence/display/RTF20/Configuring+Artifacts+Resolution
I would recommend to use:
<mirrorOf>*</mirrorOf>
since you want to only resolve dependencies in the intranet only all configured repositories (also those in transitive dependencies and weird pom.xml's) should use your internal repository. Not only central.

Categories