[英]Add mysql connector to a maven / nexus build in eclipse
我正在尝试连接到java中的mysql数据库,因此我必须将mysql-connector-java:jar
到我的eclipse项目中。 与maven的集成虽然不起作用。
这是我在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>
这是我尝试mvn clean install
时遇到的错误
Failure to find mysql:mysql-connector-java:jar:5.0.5 in
http://xxxx:8083/nexus/content/groups/public
如何强制nexus将工件从我的公共存储库下载到nexus? 我必须手动添加吗?
您需要告诉maven使用您的maven存储库。 为此,请修改$ HOME / .m2 / settings.xml,如下所示:
<?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>
nexus配置文件配置为使用a bogus URL
http://central
从中央存储库下载。
此URL由同一settings.xml
文件中的镜像设置覆盖,以指向single Nexus group
的URL。 然后,nexus组在activeProfiles元素中列为活动配置文件。
假设您的存储库中心具有存储库路径http://xxxx:8083/nexus/content/repositories/central
并且还将远程存储位置指向http://repo1.maven.org/maven2/
您可以更改http://central
到http://xxxx:8083/nexus/content/repositories/central
或http://repo1.maven.org/maven2/
。
在你的pom.xml中,使用下面的依赖来获取mysql-connector。
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.33</version>
</dependency>
另请参阅: Nexus maven存储库管理器入门
希望这有帮助。
您是否有可能为mysql-connector-java包含两个不同的版本? 我曾经有过这样的错误,事实证明我偶然包含了另一个版本,所以没有访问这个特定版本(这是一个传递依赖,由于特殊原因我不能排除)。 我在所有其他依赖项的开头移动了依赖项(在你的情况下它可能最终),并且它有效。 从理论上讲,具有相同依赖关系的两个版本不应该抛出错误。
以下是MySQL连接器http://mvnrepository.com/artifact/mysql/mysql-connector-java的可用版本,单击任何版本,它将给出您的依赖关系。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.