`
yjhexy
  • 浏览: 327601 次
  • 性别: Icon_minigender_1
  • 来自: 火星
社区版块
存档分类
最新评论

官方maven绝对OK

阅读更多

1,  下载maven 官方网站:http://maven.apache.org


 

2,5分钟速成:

英文版: http://maven.apache.org/guides/getting-started/maven-in-five-minutes.html

中文版:http://yjhexy.iteye.com/admin/blogs/443453


 

3,详细信息:http://maven.apache.org/guides/getting-started/index.html


 

4,  查找依赖:http://mvnrepository.com/

 

maven eclipse:eclipse的时候可以加上参数:-DdownloadSources=true

来下载包括可运行JAR包,源代码和JAVA文档。


 

如果是eclipse的wtp插件开发的话:mvn -Dwtpversion=2.0 eclipse:eclipse -DdownloadSources=true -DdownloadJavadocs=true


 

有的时候发现搜索出来的内容如下图:


发现会有JDK13,和JDK15的区别,这个时候如果不指定JDK版本的话将导致引用依赖失败:


所以POM文件会类似以下定义

<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.yajun</groupId>
	<artifactId>jsonDemo</artifactId>
	<packaging>jar</packaging>
	<version>1.0-SNAPSHOT</version>
	<name>jsonDemo</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>net.sf.json-lib</groupId>
			<artifactId>json-lib</artifactId>
			<version>2.1</version>
			<scope>compile</scope>
			<!-- 加上下面这个标签表示用的哪个JDK版本的 -->
			<classifier>jdk15</classifier>
		</dependency>
	</dependencies>
</project>

 

5,mvn install的时候需要一起打包sources,需要添加:

 

<plugin>
<inherited>true</inherited>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<executions>
<execution>
<id>attach-sources</id>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>

 

运行:

Run "mvn -DperformRelease=true clean install"

 

后面如果再导入 eclipse 之前需要把eclipse生成的target 先删掉才可以。

 

5,最后我常用的命令:

用maven自动生成构建: mvn archetype:generate

用我指定的构建:mvn archetype:create -DgroupId=com.yajun.babyStore -DartifactId=babyStore.web -DarchetypeArtifactId=maven-archetype-webapp

打包我的应用:mvn package -DskipTests=true

 

6,编译的时候需要制定JDK1.5 来编译,则需要在build中加上如下plugin

  <plugins>
      <plugin>
        <groupId>org.apache.maven .plugins</groupId>
        <artifactId>maven -compiler-plugin</artifactId>
        <version>2.0</version>
        <configuration>
          <source>1.5</source>
          <target>1.5</target>
        </configuration>
      </plugin>
    </plugins>

 

mvn install:install-file -DgroupId=org.bamboo.springx -DartifactId=springx -Dversion=1.2.2 -Dpackaging=jar -Dclassifier=sources -Dfile=/path/to/file 

 


  • 大小: 201 KB
分享到:
评论
1 楼 曾经de迷茫 2010-12-17  
不错的新手速成!

相关推荐

Global site tag (gtag.js) - Google Analytics