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


Download and install maven3.0.2

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

add the following into ~/.bashrc or ~/.bash_profile file export MAVEN_HOME=/home/chenshu/work/apache-maven-3.0.2 export 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/respository For 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_password mvn org.glassfish.maven.plugin:maven-glassfish-plugin:start-domain mvn org.glassfish.maven.plugin:maven-glassfish-plugin:redeploy mvn -e org.glassfish.maven.plugin:maven-glassfish-plugin:start-domain mvn -e org.glassfish.maven.plugin:maven-glassfish-plugin:deploy note,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.

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


Download and install maven3.0.2

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

add the following into ~/.bashrc or ~/.bash_profile file export MAVEN_HOME=/home/chenshu/work/apache-maven-3.0.2 export 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/respository For 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_password mvn org.glassfish.maven.plugin:maven-glassfish-plugin:start-domain mvn org.glassfish.maven.plugin:maven-glassfish-plugin:redeploy mvn -e org.glassfish.maven.plugin:maven-glassfish-plugin:start-domain mvn -e org.glassfish.maven.plugin:maven-glassfish-plugin:deploy note,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.