mavn学习笔记(未整理)

path 
mvn -version
http://localhost:8081/nexus




NEXUS_HOME=C:\nexus-2.1.1-bundle\nexus-2.1.1
%NEXUS_HOME%\bin\jsw\windows-x86-64




把C:\apache-maven-3.1.1\conf\settings.xml拷贝到D:/Maven  两边都设置


<localRepository>D:/maven/repository</localRepository>




<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.nbchina.bean</groupId>
  <artifactId>nbchina-bean</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <packaging>jar</packaging>


  <name>nbchina-bean</name>
  <url>http://maven.apache.org</url>


  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  </properties>


  <dependencies>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>4.10</version>
      <scope>test</scope>
    </dependency>
  </dependencies>
</project>




查询坐标:
www.sonatype.org/central
mvnrepository.com  搜索hibernate


Core Hibernate O/RM functionality 
The core O/RM functionality as provided by Hibernate
org.hibernate hibernate-core


3.6.10.Final




maven


<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>3.6.10.Final</version>
</dependency>
            




<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.nbchina.bean</groupId>
  <artifactId>nbchina-bean</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <packaging>jar</packaging>


  <name>nbchina-bean</name>
  <url>http://maven.apache.org</url>


  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  </properties>
      //若自带的中央仓库下载有问题,可以在此配置一个中央仓库覆盖,更改地址。




  <repositories>
    <repository>
      <id>central</id>
      <name>Central Repository</name>
      <url>https://nexus.sourcesense.com/nexus/content/repositories/public/</url>
      <layout>default</layout>
      <snapshots>
        <enabled>false</enabled>
      </snapshots>
    </repository>
  </repositories>




  <dependencies>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>4.10</version>
      <scope>test</scope>
    </dependency>
  </dependencies>
</project>






clean test     测试
clean install  打包






新建项目


依赖范围




scope:未写默认compile编译范围
test---不能传递到依赖的包。只在测试范围内有效,编译、打包不会使用。
compile范围:在编译、打包时都有效。
1、依赖会被传递
A-->C  B-->A ==> B-->C 这种依赖是基于compile这个范围传递


provided: 例如:依赖servlet-api,打成war包会跟tomcat自带的包冲突。所以用provided,编译、测试时有用,打包发布不包含。


runtime范围:在运行的时候依赖、在编译的时候不依赖。


    <dependency>
    <groupId>com.nbchina.log</groupId>
    <artifactId>nbchina-log</artifactId>
    <version>0.0.1-SNAPSHOT</version>
<exclusions>
<exclusion>
    <groupId>log4j</groupId>
    <artifactId>log4j</artifactId>
</exclusion>
</exclusions>
    </dependency>


排除继承的log4j,可以精确的控制jar的版本






 <dependencyManagement>
  <dependencies>
 
<dependency>
<groupId>com.nbchina.base</groupId>
<artifactId>nbchina-bean</artifactId>
<version>${bean.version}</version>
</dependency>  
 
  <dependency>
  <groupId>junit</groupId>
  <artifactId>junit</artifactId>
  <version>${junit.version}</version>
  <scope>test</scope>
  </dependency>
  </dependencies>
  </dependencyManagement>


对依赖继承,需要通过dependencyManagement来管理。
如果不管理子类,会全部继承。会导致默写模块存在不需要的依赖




  <parent>
 <groupId>com.nbchina.base</groupId>
 <artifactId>nbchina-parent</artifactId>
 <version>0.0.1-SNAPSHOT</version>
 <relativePath>../nbchina-parent/pom.xml</relativePath>
  </parent>


在需要继承的pom.xml中加入父pom.xml


父pom.xml加入被继承的模块。
  <modules>
  <module>../nbchina-bean</module>
  <module>../nbchina-log</module>
...
  </modules>




本地仓库  中央仓库
打开C:\nexus-2.1.1-bundle\nexus-2.1.1\bin\jsw\conf\wrapper.conf 修改jdk路径
wrapper.java.command=C:\Program Files\Java\jrockit-jdk1.6.0_45-R28.2.7-4.1.0\bin\java


http://localhost:8081/nexus  


login  admin admin123


hosted:
Releases  内部模块中realease模块的发布仓库
Snapshots 发布内部的Shapshot模块的仓库
3rd party 第三方依赖的仓库,这个数据通常由内部人员自行下载之后发


proxy:是远程仓库的代理。比如说在nexus中配置了一个central repository的proxy,当用户向这个proxy请求一个artifact,这个proxy就会先在本地查找,如果找不到的话,就会从远程仓库下载,然后返回给用户,相当于起到一个中转的作用
Central
Apache Snapshots
Codehaus Snashots


group是仓库组,在maven里没有这个概念,是nexus特有的。目的是将上述多个仓库聚合,对用户暴露统一的地址,这样用户就不需要在pom中配置多个地址,只要统一配置group的地址就可以了


 在父pom.xml中加入仓库组
  <repositories>
<!--     <repository>
      <id>central</id>
      <name>Central Repository</name>
      <url>https://nexus.sourcesense.com/nexus/content/repositories/public/</url>
      <layout>default</layout>
      <snapshots>
        <enabled>false</enabled>
      </snapshots>
    </repository> -->
    
     <repository>
      <id>nexus</id>
      <name>Nexus Repository</name>
      <url>http://192.168.4.115:8081/nexus/content/groups/public/</url>
      <releases>
        <enabled>true</enabled>
      </releases>
      <snapshots>
        <enabled>true</enabled>
      </snapshots>
    </repository>
    
  </repositories>


http://repo1.maven.org/maven2/


central设置索引,打开设置中的远程下载索引。


建立私有仓库
镜像
在d:\maven\settings.xml中设置。
<mirrorOf>*</mirrorOf> 代表为所有工厂做了镜像。访问这些工厂,直接去镜像去找。


<mirrors>
<mirror>
            <mirrorOf>*</mirrorOf>
   <name>Human Readable Name for this Mirror.</name>
   <url>http://192.168.4.115:8081/nexus/content/groups/public/</url>
        </mirror>
</mirrors>


在d:\maven\settings.xml中设置。统一设置。


<profiles>
    <profile>
 <id>central-repos</id>
      <repositories>
        <repository>
          <id>central</id>
          <name>Central</name>
          <url>http://www.central</url>  //必须有,在有镜像的情况下,可以随便设置。
       <releases>
            <enabled>true</enabled>
          </releases>
          <snapshots>
            <enabled>true</enabled>
          </snapshots>
        </repository>
      </repositories>
</profile>




activeProfiles激活统一设置的.必须激活。否则上面设置无效
  <activeProfiles>
    <activeProfile>central-repos</activeProfile>
  </activeProfiles>


项目的发布
Releases 设置中 Deployment Policy 设置Allow Redeploy. 允许发布。


在父pom.xml
<distributionManagement>

 <repository>
         <id>nbchina-release</id>
         <name>Nbchina Project Release</name>
         <url>http://192.168.4.115:8081/nexus/content/repositories/releases/</url>
 </repository>
 
 <snapshotRepository>
         <id>nbchina-snapshots</id>
         <name>Nbchina Project SNAPSHOTS</name>
         <url>http://192.168.4.115:8081/nexus/content/repositories/snapshots/</url>
 </snapshotRepository>


</distributionManagement>
设置访问权限


在nexus 中的security-user中设置deployment用户,需要修改d:maven\settings.xml
加入
其中id从父pom.xml的 <distributionManagement><repository><id>nbchina-release</id>拷贝


  <servers>


    <server>
      <id>nbchina-snapshots</id>
      <username>deployment</username>
      <password>deployment123</password>
    </server>


    <server>
      <id>nbchina-release</id>
      <username>deployment</username>
      <password>deployment123</password>
    </server>
执行clean deploy


创建工厂,一般创建四个,类型 hosted.
1、
add hosted
id: MyUserReposRelease
name:My User Pro Release
发布:允许


2、add Proxy Repository
MyUserReposSnapshots
name:My User Pro Snapshots
Repository Policy:Snapshots
发布:允许


创建权限


security-privileges-add1
name:MyUserProRelease
描述:用户管理项目的release工厂的权限。
repository:选择刚创建的第一个release工厂
repository Target:选择All(Maven2)


security-privileges-add2
name:MyUserProSnapshots
描述:用户管理项目的Snapshots工厂的权限。
repository:选择刚创建的第一个release工厂
repository Target:选择All(Maven2)


创建角色
security
role-add
id:MyUserRole
name:UserRole
addPrivilege:过滤My。 把8个全选。




创建用户


add
id:nbchina
firstname:lu
lastname:jiaming
email:nbchina@sohu.com
status:active
password:123456
role-add:刚才创建的MyUserRole




创建发布的工厂 








插件使用


maven.apache.org/plugins/maven-source-plugin/


//源代码打包。生成nbchina-bean-0.0.1-SNAPSHOT-sources.jar
单独在bean中的pom.xml使用
<build>
 <plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-source-plugin</artifactId>
  <version>2.1.2</version>
  </plugin>
</build>




在父pom.xml中使用


<build>
 <pluginManagement>
  <plugins>
   <plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-source-plugin</artifactId>
  <version>2.1.2</version>
   </plugin>
  </plugins>
  </pluginManagement>
</build>


在继承的pom.xml中


<build>
 <plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-source-plugin</artifactId>
  </plugin>
</build>


使用


直接加入目标。


<build>
 <pluginManagement>
  <plugins>
   <plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-source-plugin</artifactId>
  <version>2.1.2</version>


<executions>
<execution>
<phase>package</phase>
<goals><goal>jar-no-fork</goal></goals>
</execution>
</executions>
   </plugin>
  </plugins>
  </pluginManagement>
</build>


在生命周期package之后运行插件,目标是jar-no-fork








http://maven.apache.org/plugins/index.html
help插件使用


help:describe - Dplugin=compiler




sql插件


  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <mysql.version>5.1.27</mysql.version>
    <mysql.driver>com.mysql.jdbc.Driver</mysql.driver>
    <mysql.url>jdbc:mysql://localhost:3306/mysql</mysql.url>
<mysql.user>root</mysql.user>
<mysql.password>123456</mysql.password>
  </properties>


<build>
 <pluginManagement>
  <plugins>
   <plugin>
  <groupId>org.codehaus.mojo</groupId>
  <artifactId>sql-maven-plugin</artifactId>
  <version>1.5</version>


  <dependencies>
 
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>${mysql.version}</version>
</dependency>  
  </dependencies>
<configuration>
    <driver>${mysql.driver}</driver>
    <url>${mysql.url}</url>
<user>${mysql.user}</user>
<password>${mysql.password}</password>
<sqlCommand>
create database IF NOT EXISTS maven
</sqlCommand>
</configuration>


<executions>
<execution>
<phase>package</phase>
<goals><goal>execute</goal></goals>
</execution>
</executions>
   </plugin>
  </plugins>
  </pluginManagement>
</build>


bean pom.xml使用


<build>
 <plugin>
  <groupId>org.codehaus.mojo</groupId>
  <artifactId>sql-maven-plugin</artifactId>
  </plugin>
</build>


clean package






rar插件




web发布


<dependency>
<groupId>servletapi</groupId>
<artifactId>servletapi</artifactId>
<version>2.5</version>
                        <scope>provided</scope>
</dependency>  


<dependency>
<groupId>javax.servlet.jsp</groupId>
<artifactId>jsp-api</artifactId>
<version>2.2</version>
<scope>provided</scope>   //会跟容器自带的冲突。
</dependency>  


//使用war插件,改变打包名称
<>


</distributionManagement>
<build>
 <finalName>nbchina-web</finalName>
  <plugins>
   <plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-war-plugin</artifactId>
  <version>2.2</version>


<configuration>
    <warName>test</warName>
<></>
</configuration>


   </plugin>
  </plugins>
  </pluginManagement>
</build>




直接发布到jetty。7.5.2


cargo插件支持tomcat。但比较复杂。


web的pom.xml




   <plugin>
  <groupId>org.mortbay.jetty</groupId>
  <artifactId>jetty-maven-plugin</artifactId>
  <version>7.5.2</version>


<configuration>
    <scanIntervalSeconds>10</scanIntervalSeconds>
<webApp>
<contextPath>/kk</contextPath>
</webApp>
<connectors>
<connector implementation="org.eclipse.jetty.server.nio.SelectChannelConnector">
<port>8888</port>
<maxIdleTime>60000</maxIdleTime>
</connector>
</connectors>
</configuration>


   </plugin>




jetty:run




拷贝一个web.xml的头。


<servlet>
<servlet-name>TestServlet</servlet-name>
<servlet-class>com.nbchina.servlet.TestServlet</servlet-class>


</servlet>
<servlet-mapping>
<servlet-name>TestServlet</servlet-name>
<url-pattern>/test.do</url-pattern>
</servlet-mapping>




parent
core->model,beans.xml
persistent
service
web
Spring Hibernate




Group Id:com.nbchina.student
Artifact Id:student-parent
Package:com.nbchina.student








测试


在test目录下,只有包含Test的文件会被自动测试

通过配置surefire插件,实现测试的管理

   <plugins>
<!--   <plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.6</source>
<target>1.6</target>
在编译时直接不编译测试类,如果测试类有错此时就不会报错
<skip>true</skip>
</configuration>
</plugin> -->
  <plugin>
  <groupId>org.apache.maven.plugins</groupId>
       <artifactId>maven-surefire-plugin</artifactId>
       <version>2.12</version>
       <configuration>
       <!-- 排除 -->
        <excludes>
        <exclude>**/Test*</exclude>
        </excludes>
       <!-- 默认会执行:**/Test*,**/*Test,**/*TestCase,但是当使用include之后就不会在包含默认的测试类型,只会包含include中的测试类型 -->
       
       <includes>
        <include>**/Hello*</include>
       </includes>
       <skip>true</skip>
       </configuration>
  </plugin>
 
  </plugins>
  </build>



动态命令行测试 

mvn test -Dtest=HelloWorld

mvn test -Dtest=Test*


mvn clean package  -DskipTests打包跳过测试




测试覆盖率


mvn cobertura:cobertura


1.maven-surefire-plugin简介

Maven本身并不是一个单元测试框架,它只是在构建执行到特定生命周期阶段的时候,通过插件来执行JUnit或者TestNG的测试用例。这个插件就是maven-surefire-plugin,也可以称为测试运行器(Test Runner),它能兼容JUnit 3、JUnit 4以及TestNG。

在默认情况下,maven-surefire-plugin的test目标会自动执行测试源码路径(默认为src/test/java/)下所有符合一组命名模式的测试类。这组模式为:

  • **/Test*.java:任何子目录下所有命名以Test开关的Java类。
  • **/*Test.java:任何子目录下所有命名以Test结尾的Java类。
  • **/*TestCase.java:任何子目录下所有命名以TestCase结尾的Java类。

2.跳过测试

要想跳过测试,在命令行加入参数skipTests就可以了。如:
[plain]  view plain copy print ?
  1. mvn package -DskipTests  

也可以在pom配置中提供该属性。
[html]  view plain copy print ?
  1. <plugin>  
  2.     <groupId>org.apache.maven.plugins</groupId>  
  3.     <artifactId>maven-surefire-plugin</artifactId>  
  4.     <version>2.5</version>  
  5.     <configuration>  
  6.         <skipTests>true</skipTests>  
  7.     </configuration>  
  8. </plugin>  

有时候可能不仅仅需要跳过测试运行,还要跳过测试代码的编译:
[plain]  view plain copy print ?
  1. mvn package -Dmaven.test.skip=true  

也可以在pom中配置maven.test.skip:
[html]  view plain copy print ?
  1. <plugin>  
  2.     <groupId>org.apache.maven.plugin</groupId>  
  3.     <artifactId>maven-compiler-plugin</artifactId>  
  4.     <version>2.1</version>  
  5.     <configuration>  
  6.         <skip>true</skip>  
  7.     </configuration>  
  8. </plugin>  
  9. <plugin>  
  10.     <groupId>org.apache.maven.plugins</groupId>  
  11.     <artifactId>maven-surefire-plugin</artifactId>  
  12.     <version>2.5</version>  
  13.     <configuration>  
  14.         <skip>true</skip>  
  15.     </configuration>  
  16. </plugin>  

3.动态指定要运行的测试用例

maven-surefire-plugin提供了一个test参数让Maven用户能够在命令行指定要运行的测试用例。如:
[plain]  view plain copy print ?
  1. mvn test -Dtest=RandomGeneratorTest  

也可以使用通配符:
[plain]  view plain copy print ?
  1. mvn test -Dtest=Random*Test  

或者也可以使用“,”号指定多个测试类:
[plain]  view plain copy print ?
  1. mvn test -Dtest=Random*Test,AccountCaptchaServiceTest  

如果没有指定测试类,那么会报错并导致构建失败。
[plain]  view plain copy print ?
  1. mvn test -Dtest  

这时候可以添加-DfailIfNoTests=false参数告诉maven-surefire-plugin即使没有任何测试也不要报错。
[plain]  view plain copy print ?
  1. mvn test -Dtest -DfailIfNoTests=false  

由此可见,命令行参数-Dtest -DfailIfNoTests=false是另外一种路过测试的方法

4.包含与排除测试用例

如果由于历史原因,测试类不符合默认的三种命名模式,可以通过pom.xml设置maven-surefire-plugin插件添加命名模式或排除一些命名模式。
[html]  view plain copy print ?
  1. <plugin>  
  2.     <groupId>org.apache.maven.plugins</groupId>  
  3.     <artifactId>maven-surefire-plugin</artifactId>  
  4.     <version>2.5</version>  
  5.     <configuration>  
  6.         <includes>  
  7.             <include>**/*Tests.java</include>  
  8.         </includes>  
  9.         <excludes>  
  10.             <exclude>**/*ServiceTest.java</exclude>  
  11.             <exclude>**/TempDaoTest.java</exclude>  
  12.         </excludes>  
  13.     </configuration>  
  14. </plugin>  

5.生成测试报告

5.1基本测试报告

默认情况下,maven-surefire-plugin会在项目的target/surefire-reports目录下生成两种格式的错误报告。
  • 简单文本格式——内容十分简单,可以看出哪个测试项出错。
  • 与JUnit兼容的XML格式——XML格式已经成为了Java单元测试报告的事实标准,这个文件可以用其他的工具如IDE来查看。

5.2测试覆盖率报告

测试覆盖率是衡量项目代码质量的一个重要的参考指标。Cobertura是一个优秀的开源测试覆盖率统计工具(详见http://cobertura.sourceforge.net/),Maven通过cobertura-maven-plugin与之集成,用户可以使用简单的命令为Maven项目生成测试覆盖率报告。运行下面命令生成报告:
[plain]  view plain copy print ?
  1. mvn cobertura:cobertura  

6.运行TestNG测试

TestNG是Java社区中除了JUnit之外另一个流行的单元测试框架。TestNG在JUnit的基础上增加了很多特性,其站点是 http://testng.org/ .添加TestNG依赖:
[html]  view plain copy print ?
  1. <dependency>  
  2.     <groupId>org.testng</groupId>  
  3.     <artifactId>testng</artifactId>  
  4.     <version>5.9</version>  
  5.     <scope>test</scope>  
  6.     <classifier>jdk15</classifier>  
  7. </dependency>  

下面是JUnit和TestNG的常用类库对应关系
JUnit类TestNG类作用
org.junit.Testorg.testng.annotations.Test标注方法为测试方法
org.junit.Assertorg.testng.Assert检查测试结果
org.junit.Beforeorg.testng.annotations.BeforeMethod标注方法在每个测试方法之前运行
org.junit.Afterorg.testng.annotations.AfterMethod标注方法在每个测试方法之后运行
org.junit.BeforeClassorg.testng.annotations.BeforeClass标注方法在所有测试方法之前运行
org.junit.AfterClassorg.testng.annotations.AfterClass标注方法在所有测试方法之后运行

TestNG允许用户使用一个名为testng.xml的文件来配置想要运行的测试集合。如在类路径上添加testng.xml文件,配置只运行RandomGeneratorTest
[html]  view plain copy print ?
  1. <?xml version="1.0" encoding="UTF-8"?>  
  2. <suite name="Suite1" verbose="1">  
  3.     <test name="Regression1">  
  4.         <classes>  
  5.             <class name="com.juvenxu.mvnbook.account.captcha.RandomGeneratorTest" />  
  6.         </classes>  
  7.     </test>  
  8. </suite>  

同时再配置maven-surefire-plugin使用该testng.xml,如:
[html]  view plain copy print ?
  1. <plugin>  
  2.     <groupId>org.apache.maven.plugins</groupId>  
  3.     <artifactId>maven-surefire-plugin</artifactId>  
  4.     <version>2.5</version>  
  5.     <configuration>  
  6.         <suiteXmlFiles>  
  7.             <suiteXmlFile>testng.xml</suiteXmlFile>  
  8.         </suiteXmlFiles>  
  9.     </configuration>  
  10. </plugin>  

TestNG较JUnit的一大优势在于它支持测试组的概念。如可以在方法级别声明测试组:
[java]  view plain copy print ?
  1. @Test(groups={"util","medium"})  

然后可以在pom中配置运行一个或多个测试组:
[html]  view plain copy print ?
  1. <plugin>  
  2.     <groupId>org.apache.maven.plugins</groupId>  
  3.     <artifactId>maven-surefire-plugin</artifactId>  
  4.     <version>2.5</version>  
  5.     <configuration>  
  6.         <groups>util,medium</groups>  
  7.     </configuration>  
  8. </plugin>  

7.重用测试代码

当命令行运行mvn package的时候,Maven只会打包主代码及资源文件,并不会对测试代码打包。如果测试代码中有需要重用的代码,这时候就需要对测试代码打包了。
这时候需要配置maven-jar-plugin将测试类打包,如:
[html]  view plain copy print ?
  1. <plugin>  
  2.     <groupId>org.apache.maven.plugins</groupId>  
  3.     <artifactId>maven-jar-plugin</artifactId>  
  4.     <version>2.2</version>  
  5.     <executions>  
  6.         <execution>  
  7.             <goals>  
  8.                 <goal>test-jar</goal>  
  9.             </goals>  
  10.         </execution>  
  11.     </executions>  
  12. </plugin>  
maven-jar-plugin有两个目标,分别为jar和test-jar。这两个目标都默认绑定到default生命周期的package阶段运行,只是test-jar并没有在超级POM中配置,因此需要我们另外在pom中配置。

现在如要引用test-jar生成的测试代码包,可以如下配置:
[html]  view plain copy print ?
  1. <dependency>  
  2.     <groupId>com.juvenxu.mvnbook.account</groupId>  
  3.     <artifactId>account-captcha</artifactId>  
  4.     <version>1.0.0-SNAPSHOT</version>  
  5.     <type>test-jar</type>  
  6.     <scope>test</scope>  
  7. </dependency>  


web发布

jetty:run



先要在MyEclipse中对Maven进行设置:
MyEclipse创建Maven工程
MyEclipse创建Maven工程
MyEclipse创建Maven工程
到此Maven对MyEclipse的支持设置完毕。

下面我们在MyEclipse中创建一个Maven标准的Web工程:
New --> Web Project
MyEclipse创建Maven工程
MyEclipse创建Maven工程
MyEclipse创建Maven工程
到此为止一个Maven标准的Web工程创建成功了。

添加Maven的标准目录:
右键单击项目名称-->New-->Source Folder
MyEclipse创建Maven工程
MyEclipse创建Maven工程
MyEclipse创建Maven工程
MyEclipse创建Maven工程
到此为止添加Maven的契约目录完毕。

右键单击项目名称-->Build Path-->Configure Build Path...
MyEclipse创建Maven工程
MyEclipse创建Maven工程
右键单击项目名称-->Maven4MyEclipse-->Update Project Configuration...

到此为止MyEclipse中创建的Maven工程的jdk版本更改完毕。
--------------------------------------------------------------------------------------------------
笔者这边多啰嗦一句,在用MyEclipse创建Maven工程的时候可能会碰到下面的这个问题:
CoreException: Could not calculate build plan: Plugin org.apache.maven.plugins:
maven-compiler-plugin:2.3.2 or one of its dependencies could not be resolved: Failure to transfer org.apache.maven.plugins: maven-compiler-plugin:jar:2.3.2 from http://repo1.maven.org/maven2 was cached in the local repository, resolution will not be 
  reattempted until the update interval of central has elapsed or updates are forced. Original error: Could not 
  transfer artifact org.apache.maven.plugins: maven-compiler-plugin:jar:2.3.2 from/to central (http://
  repo1.maven.org/maven2): No response received after 60000
【解决办法】: MyEclipse创建Maven工程

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值