Nexus搭建maven私服、maven常见问题汇总

2021/03/04

Nexus搭建maven私服

参考资料

  • 官网地址:https://www.sonatype.com/thanks/repo-oss?submissionGuid=e225567e-4323-4049-870c-478afc2a7bfe
  • 下载地址:
  • 文档地址:

一、Nexus简介

仓库管理器有两个服务目的:首先它的角色是一个高度可配置的介于你的组织与公开Maven仓库之间的代理,其次它为你的组织提供了一个可部署你组织内部生成的构件的地方。

二、Nexus使用:

setting中或者pom中指定私服仓库

1.setting.xml指定私服仓库:

<mirror>
    <id>nexus-aliyun</id>
    <mirrorOf>central</mirrorOf>
    <name>Nexus aliyun</name>
    <url>http://maven.aliyun.com/nexus/content/groups/public</url>
</mirror>
```exception-io-serialization.
pom.xml:

2.pom指定私服仓库

<repositories> 
    <repository>
    <id>1</id>
    <url>http://ip:port/nexus/content/groups/public</url>
    </repository>
</repositories>

三、Windows环境Nexus部署

1.配置环境变量:
%NEXUS_HOME%\nexus-3.3.1-01\bin

2.DOS下执行:
nexus /run

3.浏览器中访问地址:
http://127.0.0.1:8081 或 http://localhost:8081

 (1) 端口修改:%NEXUS_HOME%\nexus-3.3.1-01\etc下"nexus-default.properties"文件,此处我修改了host为127.0.0.1,使得以127.0.0.1可以访问
 (2) 数据存储目录修改:"%NEXUS_HOME%\nexus-3.3.1-01\bin"下"nexus.vmoptions"文件

4.登录:
默认用户名:admin ,密码:admin123

5.仓库管理

  • 仓库类型:
    • proxy:是远程仓库的代理。比如说在nexus中配置了一个central repository的proxy,当用户向这个proxy请求一个artifact,这个proxy就会先在本地查找,如果找不到的话,就会从远程仓库下载,然后返回给用户,相当于起到一个中转的作用;
    • Hosted:是宿主仓库,用户可以把自己的一些构件,deploy到hosted中,也可以手工上传构件到hosted里。比如说Oracle的驱动程序,ojdbc6.jar,在central repository是获取不到的,就需要手工上传到hosted里;
    • Group:是仓库组,在maven里没有这个概念,是nexus特有的。目的是将上述多个仓库聚合,对用户暴露统一的地址,这样用户就不需要在pom中配置多个地址,只要统一配置group的地址就可以了右边那个 Repository Path 可以点击进去,看到仓库中artifact列表, 不过要注意浏览器缓存。
    • virtual:也是中央仓库镜像,支持M1老版本
  • 私服仓库配置 : 可根据具体的使用环境,设置不同属性的仓库。
    • 以Hosted本地仓库为例(便于项目的发布): 用户登录后进入maven-public仓库,在配置详情页可以看到仓库的URL, 访问该URL会提示
  • Maven3 与 Maven2 不同: s

6.全局配置、用户配置

  • 用户配置优于全局配置
  • 全局配置路径:%MAVEN_HOME%\conf\setting.xml
  • 用户默认配置路径:${user.home}\.m2\setting.xml
  • 复制全局配置文件至用户配置文件目录,用于Eclipse中进一步设置

四、Linux环境Nexus部署

nexus3.14.0版本linux环境安装、启动、搭建私库

maven常见问题汇总

1.查找某个包是怎么依赖进来的

terminal执行命令:
mvn dependency:tree -Dverbose -Dincludes=org.aspectj:aspectjweaver

2.多module项目package报错:Failed to execute goal on project …: Could not resolve dependencies for project … 需要先对parent pom 进行install操作

  • https://liayun.blog.csdn.net/article/details/103727641
  • https://blog.csdn.net/two_people/article/details/77883208

3.XXX–1.0-SNAPSHOT.jar中没有主清单属性

https://blog.csdn.net/weixin_49736959/article/details/108969870
如果您使用的是Springboot框架,那么只需要在pom.xml中添加如下配置,会自动检测主类。
<build>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
        </plugin>
    </plugins>
</build>

4.Maven实战— dependencies与dependencyManagement的区别:
https://www.cnblogs.com/feibazhf/p/7886617.html

5.org.apache.maven.archiver.MavenArchiver.getManifest(org.apache.maven.project.Maven…

1.help -> Install New Software -> add ->https://otto.takari.io/content/sites/m2e.extras/m2eclipse-mavenarchiver/0.17.2/N/LATEST  
2.一直next confirm 安装更新 提示重启eclipse 然后再右键项目maven update project  

6.包冲突

<dependency>
  <groupId>com.xxx.AAP</groupId>
  <artifactId>msg-client</artifactId>
  <version>1.0.0-SNAPSHOT</version>
  <exclusions>
  	<exclusion>
  		<artifactId>spring-context</artifactId>
  		<groupId>org.springframework</groupId>
  	</exclusion>
  </exclusions>
</dependency>

7.Build path is incomplete. Cannot find class file for com..Configuration .xml /xt/src/spring line 5 Spring AOP Problem

在maven仓库中把报错jar文件全部删掉,然后更新maven工程,选中project-->maven-->update project,让maven重新down下依赖,然后就可以了,
估计是由于在maven down依赖的时候出现中断,然后jar包里面的类不全导致的

8.严重: Error configuring application listener of class org.springframework.web.context.ContextLoaderListener 解决方案:

其实是你的jar文件没有同步发布到自己项目的lib目录中(如果你是用Maven进行构建的话) 可以试试 下面的办法 项目点击右键 点击 Properties 选择Deployment Assembly 再点击右边的Add按钮 选择Java Build Path Entries后点击Next按钮 然后选择你的Maven Dependencies 确定即可

9.Missing artifact org.apache.mina:mina-core:bundle:2.0.9 解决办法:在 pom.xml 中添加 如下插件

<plugin> 
    <groupId>org.apache.felix</groupId> 
    <artifactId>maven-bundle-plugin</artifactId> 
    <extensions>true</extensions> 
</plugin>

10.-Dmaven.multiModuleProjectDirectory system propery is not set. Check $M2_HOME environment variable and mvn script match.

1.添加M2_HOME的环境变量  
2.Preference->Java->Installed JREs->Edit 选择一个jdk,添加   -Dmaven.multiModuleProjectDirectory=$M2_HOME

11.was cached in the local repository, resolution will not be reattempted until the update inteval……… https://blog.51cto.com/qiangsh/1743074

问题原因 :Maven默认会使用本地缓存的库来编译工程,对于上次下载失败的库,maven会在~/.m2/repository/<group>/<artifact>/<version>/目录下创建xxx.lastUpdated文件,一旦这个文件存在,那么在直到下一次nexus更新之前都不会更新这个依赖库。
解决办法:  
    方法一:
    删除v~/.m2/repository/<group>/<artifact>/<version>/目录下的*.lastUpdated文件,然后再次运行mvn compile编译工程。
    方法二:
    修改~/.m2/settings.xml 或/opt/maven/conf/settings.xml文件,将其中的仓库添加  <updatePolicy>always</updatePolicy>来强制每次都更新依赖库。
    <repositories>
            <repository>
                    <id>central</id>
                    <url>http://central</url>
                    <releases>
                            <enabled>true</enabled>
                            <updatePolicy>always</updatePolicy>
                    </releases>
                    <snapshots>
                            <enabled>true</enabled>
                            <updatePolicy>always</updatePolicy>
                    </snapshots>
            </repository>
    </repositories>
Jenkins构建时报错:
    通过jenkins编译时报此错,我的maven安装目录/opt/maven ,解决方法如下:
    发现obj-test-client-1.1.1.jar下载到本地时失败,从提示可知是本地仓库的缓存(cached)造成,于是我删除目录/opt/maven/repo/<group>/obj-test-client/1.1.1后Jenkins重新构建(或在项目目录  mvn 重新编译)即可编译成功!  
    注意你要确定远程仓库中存在此jar(obj-test-client-1.1.1.jar)包  

12.missing artifact ,但是本地jar包存在

本地仓库找到依赖jar文件夹删掉,重新import

13.web.xml is missing and is set to true http://stackoverflow.com/questions/31835033/web-xml-is-missing-and-failonmissingwebxml-is-set-to-true

This is a maven error. It says that it is expecting a web.xml file in your project because it is a web application, as indicated by  <packaging>war</packaging>. However, for recent web applications a web.xml file is totally optional. Maven needs to catch up to this convention. Add this to your maven  pom.xml  to let maven catch up and you don't need to add a useless  web.xml  to your project:
    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-war-plugin</artifactId>
                <version>2.6</version>
                <configuration>
                    <failOnMissingWebXml>false</failOnMissingWebXml>
                </configuration>
            </plugin>
        </plugins>
    </build>
    This is a better solution than adding an empty  web.xml  because this way your final product stays clean, your are just changing your build parameters.
    For more current versions of maven you can also use the shorter version:
    <properties>
        <failOnMissingWebXml>false</failOnMissingWebXml>
    </properties>

14.cannot change version web module 2.5

1.window->showView->Navigator
2.在Navigator下打开项目.settings目录下org.eclipse.wst.common.component,如图:(将1.5改成1.6)
3.打开org.eclipse.wst.common.project.facet.core.xml,把   <installed facet="jst.web" version="3.0"/>改成   <installed facet="jst.web" version="2.5"/>,如图:

Post Directory

扫码关注公众号:暂无公众号
发送 290992
即可立即永久解锁本站全部文章