maven 项目导入eclipse

第一步:mvn archetype:generate 创建一个MAVEN项目

第二步:进入到刚刚创建的项目中 cd到含有pom.xml文件的目录下mvn eclipse:eclipse -Dwtpversion=1.0

此命令的含义是-Dwtpversion=1.0,这个说明了eclipse认出它就是web项目,而不是简单的java项目,大家 应该知道web项目在eclipse可以做一些其他的事情吧

第三步:从eclipse中一般导入这个项目,记住不是maven项目导入


pom.xml里面加入与项目有关的JAR包
加上这个插件,已便执行mvn depoly命令

<reporting>
<plugins>
<plugin>
<artifactId>maven-deploy-plugin</artifactId>
<version>2.5</version>
<configuration>
<updateReleaseInfo>true</updateReleaseInfo>
</configuration>
</plugin>
</plugins>
</reporting>


下面的代码是pom.xml的完整代码
<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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.mars</groupId>
<artifactId>maven_test</artifactId>
<packaging>war</packaging>
<version>1.0</version>
<name>maven_test Maven Webapp</name>
<url>http://maven.apache.org</url>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-aop</artifactId>
<version>3.0.5.RELEASE</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.0.1</version>
</dependency>
</dependencies>
<build>
<finalName>maven_test</finalName>
</build>
<properties>
<nexus.location>127.0.0.1:8081</nexus.location>
</properties>

<!-- 更常见的用例是:团队在开发一个项目的各个模块,为了让自己开发的模块能够快速让其他人使用,你会想要将
snapshot版本的构件部署到Maven仓库中,其他人只需要在POM添加一个对于你开发模块的依赖,就能随时拿到最新的snapshot。
-->
<distributionManagement>
<repository>
<id>nexus-releases</id>
<name>Nexus Release Repository</name>
<url>http://127.0.0.1:8081/nexus/content/repositories/releases/</url>
</repository>
<snapshotRepository>
<id>nexus-snapshots</id>
<name>Nexus Snapshot Repository</name>
<url>http://127.0.0.1:8081/nexus/content/repositories/snapshots/</url>
</snapshotRepository>
</distributionManagement>

<reporting>
<plugins>
<plugin>
<artifactId>maven-deploy-plugin</artifactId>
<version>2.5</version>
<configuration>
<updateReleaseInfo>true</updateReleaseInfo>
</configuration>
</plugin>
</plugins>
</reporting>

</project>



下面的代码是settings.xml
<?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">


<pluginGroups>

</pluginGroups>

<proxies>

</proxies>

<server>
<id>nexus-releases</id>
<username>admin</username>
<password>admin123</password>
</server>
<server>
<id>nexus-snapshots</id>
<username>admin</username>
<password>admin123</password>
</server>
</servers>
<mirrors>
</mirrors>

<profiles>
<!-- 配置Maven使用Nexus
默认情况下,Maven依赖于中央仓库,这是为了能让Maven开箱即用,但仅仅这么做明显是错误的,
这会造成大量的时间及带宽的浪费。既然文章的前面已经介绍了如何安装和配置Nexus,现在我们
就要配置Maven来使用本地的Nexus,以节省时间和带宽资源。
我们可以将Repository配置到POM中,但一般来说这不是很好的做法,原因很简单,你需要为所
有的Maven项目重复该配置。因此,这里我将Repository的配置放到$user_home/.m2/settings.xml中:
由于我们不能直接在settings.xml中插入<repositories>元素,这里我们编写了一个profile,
并添加了一个profile并使用<activeProfile>元素自动将这个profile激活。这里的local-nexus仓库指向了刚才我们配置
的Nexus中“Public Repositories”仓库组,也就是说,所有该仓库组包含的仓库都能供我们使用。此外,
我们通过<releases>和<snapshots>元素激活了Maven对于仓库所有类型构件下载的支持,当然你也可以调节该配置,
比如说禁止Maven从Nexus下载snapshot构件。
使用该配置,Maven就会从你的Nexus服务器下载构件了,速度和从Central下载可不是一个数量级的。
-->
<profile>
<id>dev</id>
<repositories>
<repository>
<id>local-nexus</id>
<url>http://127.0.0.1:8081/nexus/content/groups/public/</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>
</profile>
</profiles>
<activeProfiles>
<activeProfile>dev</activeProfile>
</activeProfiles>
</settings>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值