Maven3安装以及基本使用

分享一下我老师大神的人工智能教程!零基础,通俗易懂!http://blog.csdn.net/jiangjunshow

也欢迎大家转载本篇文章。分享知识,造福人民,实现我们中华民族伟大复兴!

               

我自己的英文笔记的一部分,没多少英文,所以就懒得翻译了。

Download and install maven3.0.2

wget -c http://apache.etoak.com//maven/binaries/apache-maven-3.0.2-bin.tar.gztar -zxvf apache-maven-3.0.2-bin.tar.gz

add the following into ~/.bashrc or ~/.bash_profile fileexport MAVEN_HOME=/home/chenshu/work/apache-maven-3.0.2export PATH=$PATH:$MAVEN_HOME/bin

crate a Java application project

mvn archetype:generate -DgroupId=com.example -DartifactId=FileToDB -DarchetypeArtifactId=maven-archetype-quickstart -DinteractiveMode=false

execute a plugin directly

you must specify a valid lifecycle phase, or a goal in the format plugin:goal or pluginGroupId:pluginArtifactId:pluginVersion:goal

Show dependency tree

Run the following command under your maven2 project,it will show all dependency files of your project jar file.
mvn dependency:tree

For example:
~/work/svnclient/Exactor/AccountAPIs/BulkUpload/portage $ mvn dependency:tree
[INFO] Scanning for projects...
[INFO] Searching repository for plugin with prefix: 'dependency'.
[INFO] ————————————————————————
[INFO] Building portage
[INFO]    task-segment: [dependency:tree]
[INFO] ————————————————————————
[INFO] [dependency:tree {execution: default-cli}]
[INFO] com.exactor.bulkupload:portage:jar:1.0-SNAPSHOT
[INFO] +- log4j:log4j:jar:1.2.16:compile
[INFO] +- org.mybatis:mybatis:jar:3.0.1:compile
[INFO] +- mysql:mysql-connector-java:jar:5.1.6:compile
[INFO] +- commons-io:commons-io:jar:1.4:compile
[INFO] /- junit:junit:jar:3.8.1:test
[INFO] ————————————————————————
[INFO] BUILD SUCCESSFUL
[INFO] ————————————————————————
[INFO] Total time: 2 seconds
[INFO] Finished at: Tue Aug 31 20:34:45 CST 2010
[INFO] Final Memory: 16M/301M

Copy dependency

For example:
        <plugin>
          <groupId>org.apache.maven.plugins</groupId>
          <artifactId>maven-dependency-plugin</artifactId>
          <executions>
            <execution>
              <id>copy-dependencies</id>
              <phase>package</phase>
              <goals>
  <goal>copy-dependencies</goal>
              </goals>
            </execution>
          </executions>
 </plugin>

Then run this command:
mvn dependency:copy-dependencies

all dependencies will be copied to task/dependency folder.

Executable jar


<plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-jar-plugin</artifactId>
                    <configuration>
                        <archive>
                            <manifest>
                                <addClasspath>true</addClasspath>
                                <classpathPrefix>lib/</classpathPrefix>
                                <mainClass>com.exactor.bulkupload.App</mainClass>
                            </manifest>
                        </archive>
                    </configuration>
                </plugin>
mvn jaxws:wsimport

Respository path

~/.m2/respositoryFor example,JSF2 jar file locates in my computer:/home/chenshu/.m2/repository/com/sun/faces/jsf-api/2.0.3-b03/jsf-api-2.0.3-b03.jar

 

manage glassfish server

<plugin>

<groupId>org.glassfish.maven.plugin</groupId><artifactId>maven-glassfish-plugin</artifactId><version>2.1</version><configuration><glassfishDirectory>/usr/local/glassfish-3.0.1</glassfishDirectory><user>admin</user><passwordFile>/home/chenshu/glassfishi_password</passwordFile><debug>true</debug><terse>true</terse><echo>true</echo><domainDirectory>/usr/local/glassfish-3.0.1/glassfish/domains</domainDirectory><domain><name>domain1</name></domain><components><component><name>${project.artifactId}</name><artifact>target/${project.build.finalName}.war</artifact></component></components></configuration></plugin>

execute the following command:touch /home/chenshu/glassfish_passwordmvn org.glassfish.maven.plugin:maven-glassfish-plugin:start-domainmvn org.glassfish.maven.plugin:maven-glassfish-plugin:redeploymvn -e org.glassfish.maven.plugin:maven-glassfish-plugin:start-domainmvn -e org.glassfish.maven.plugin:maven-glassfish-plugin:deploynote,don't execute the above commands in eshell of Emacs,shell should be used.

generate SOAP client with jaxws-maven-plugin

<plugin>
   <groupId>org.codehaus.mojo</groupId>
   <artifactId>jaxws-maven-plugin</artifactId>
   <version>1.12</version>
   <executions>
     <execution>
       <goals>
  <goal>wsimport</goal>
       </goals>
     </execution>
   </executions>
   <configuration>
     <verbose>true</verbose>
     <wsdlUrls>
       <wsdlUrl>http://localhost:8080/entity-exemption/request/soap?wsdl</wsdlUrl>
     </wsdlUrls>
     <!—

<sourceDestDir>./src/main/java</sourceDestDir>—>

     <sourceDestDir>${project.build.sourceDirectory}</sourceDestDir>
   </configuration>
 </plugin>

execute this command :mvn jaxws:wsimport

create a archetype from existing project and use it to create a new project

enter your existing project top-level folder,for example,I have a project named website:
cd website
mvn archetype:create-from-project
mvn install

The archetype will be named after your existing project's name.

Now you can crate a new project using this archetype in another folder,for example:
cd /home/chenshu/work
mvn archetype:generate -DarchetypeCatalog=local
If you installed several archetypes before,you need to choose one ,then you have a chance to set the groupId,artifactId,version and package for this new project.Very good!


* add faces-config.xml or other xml files into META-INF folder for JAR project
I just noticed that it seems to be very easy: Using Apache Maven you just need to create a META-INF folder in your src/main/resources. Every file placed in this directory will be copied into the META-INF folder of the jar. To create an out of the box usable JSF-component JAR archive you need to place the tld and a minimal faces-config.xml into /META-INF.

           

给我老师的人工智能教程打call!http://blog.csdn.net/jiangjunshow
这里写图片描述
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值