Add mysql connector to a maven / nexus build in eclipse - java

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.

Related

mvn build keeps checking nexus repos not matter what I put in pom file

I am trying to access some jar files by including dependencies in the pom. The problem is I get error not found in my corporate nexus repo. How do I tell Maven not to look only in http://sl-quality.mycompany.com/nexus/content/groups/public/ for the dependencies? And where earth is the url defined?
Could not resolve dependencies for project com.mycompany.myproj:mycompany-service:jar:1.0-
SNAPSHOT: Could not find artifact io.confluent.ksql:ksqldb-api-client:jar:0.11.0 in nexus
(http://sl-quality.mycompany.com/nexus/content/groups/public/
<?xml version="1.0" encoding="UTF-8"?>
<project 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/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.mycompany.myapp</groupId>
<artifactId>com-mycompany-app</artifactId>
<version>1.0-SNAPSHOT</version>
<properties>
<ksqldb.version>0.11.0</ksqldb.version>
<!-- Maven properties for compilation -->
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
</properties>
<repositories>
<!-- jhipster-needle-maven-repository -->
<repository>
<id>ksqlDB</id>
<name>ksqlDB</name>
<url>https://ksqldb-maven.s3.amazonaws.com/maven/</url>
</repository>
<repository>
<id>confluent</id>
<name>Confluent</name>
<url>https://jenkins-confluent-packages-beta-maven.s3.amazonaws.com/6.1.0-beta200715032424/1/maven/</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>io.confluent.ksql</groupId>
<artifactId>ksqldb-api-client</artifactId>
<version>${ksqldb.version}</version>
</dependency>
</dependencies>
I have no idea why it always goes to nexus as this is no where mentioned in my pom file. I could install in my local repo but not sure what app jar files need to be pulled for it to work as two repos needed to be added.
I would like to know exactly what jar files i can extract to put in my local repo. Thanks
Repository is generally configured in your settings file located in C:/Users/Youruser/.m2/settings.xml on windows
Check the mirror and corresponding repository tags for example - your settings.xml will probably look like this
<mirror>
<id>nexus</id>
<mirrorOf>*</mirrorOf>
<url>http://sl-quality.mycompany.com/nexus/content/groups/public/</url>
</mirror>
Change this url to point to another repo, perhaps an external non corporate one such as http://repo.maven.apache.org/maven2
EDIT:
I think this is what you want
<mirrors>
<mirror>
<id>nexus</id>
<mirrorOf>*,!ksqlDB</mirrorOf>
<url>http://sl-quality.mycompany.com/nexus/content/groups/public/</url>
</mirror>
</mirrors>
<!-- Add repository for your other repo to filter on above -->
<profile>
<id>nexus</id>
<repositories>
<repository>
<id>ksqlDB</id>
<url>https://ksqldb-maven.s3.amazonaws.com/maven/</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</profile>
<!-- add at bottom inside </settings> -->
<activeProfiles>
<activeProfile>nexus</activeProfile>
</activeProfiles>
Add more repos as needed and filter above where necessary. I believe (not tested) that you can apply the same exclusions to mirrors instead of repositories personally I prefer using repository tags and having profiles setup.

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>

Proxy SVN Google Code based maven repository in Sonatype Nexus

I have set up the Sonatype Nexus for repository caching.
com.googlecode.htmleasy is not being resolved by maven. Getting error
Failure to find com.googlecode.htmleasy:htmleasy:jar:0.7 in
http://localhost:8081/nexus/content/groups/public was cached in the
local repository, resolution will not be reattempted until the update
interval of nexus has elapsed or updates are forced -> [Help 1]
htmleasy is one artifact which is sitting inside google code based maven repo.
<repository>
<id>htmleasy</id>
<url>http://htmleasy-maven.googlecode.com/svn/trunk/</url>
</repository>
But What should I do so that when I refer following artifact based on above repo
<dependency>
<groupId>com.googlecode.htmleasy</groupId>
<artifactId>htmleasy</artifactId>
<version>0.7</version>
</dependency>
gets resolved by my maven ?
My maven settings xml looks like 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://localhost:8081/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>
Add a new proxy repository and do not forget to add it to your 'public' repository group.
(If you still get "resolution will no be reattempted" error from maven, try calling maven with '-U'.)

How to add custom repository in pom while I'm using nexus for proxing?

I'm trying to use nexus to proxy central repository which is quite slow.
So. I've configured maven according tutorial.
<settings>
<mirrors>
<mirror>
<!--This sends everything else to /public -->
<id>nexus</id>
<mirrorOf>*</mirrorOf>
<url>http://localhost:8081/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>
</profile>
</profiles>
<activeProfiles>
<activeProfile>nexus</activeProfile>
</activeProfiles>
</settings>
Everything is working fine and fast. But I faced with problem when I've tried to use custom repository specified in pom.xml (this repo is needed only for concrete project)
So. I'm talking about:
<pluginRepositories>
<pluginRepository>
<id>dtrott</id>
<url>http://maven.davidtrott.com/repository</url>
</pluginRepository>
</pluginRepositories>
from: https://github.com/dtrott/maven-protoc-plugin#readme
error message:
Error resolving version for plugin 'com.google.protobuf.tools:maven-protoc-plugin' from the repositories [local (C:\Users\valden\.m2\repository), nexus (http://localhost:8081/nexus/content/groups/public)]: Plugin not found in any plugin repository -> [Help 1]
In maven settings.xml I've changed next line:
<mirrorOf>*</mirrorOf>
to
<mirrorOf>central</mirrorOf>
and it is working now...
One option is to add the custom repository to your Nexus as a proxied repository (type proxy). Then you don't have to put anything extra in your pom.

Archetype Selection Using m2eclipse

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?

Categories