maven的使用

来源:互联网 发布:2013版excel数据在哪里 编辑:程序博客网 时间:2024/05/21 09:45

maven编译时使用的字符集设定

   因为在java代码中,有可能包含中文,日文等注释,如果不设定相应的encoding方式,编译过程中会出现问题。

 为了避免编译出错,可在父POM.xml文件中定义如下内容。

<build>    <pluginManagement><plugins>    <plugin>        <groupId>org.apache.maven.plugins</groupId><artifactId>maven-compiler-plugin</artifactId><configuration>    <encoding>utf-8</encoding>    <source>1.6</source>    <target>1.6</target></configuration>    </plugin></plugins>    </pluginManagement></build>

发布组件到远程仓库管理器(Nexus)
1)配置setting.xml的server情报
<servers><server>        <id>releases</id>        <username>admin</username>        <password>xxxxxxxxx</password>    </server>    <server>        <id>snapshots</id>        <username>admin</username>        <password>xxxxxxxxx</password>    </server>  </servers>

2)配置pom.xml文件的SCM信息
<distributionManagement>        <repository>            <id>releases</id>            <name>Nexus Managed Releases Repository</name>            <url>http://192.168.0.55:8081/nexus/content/repositories/releases</url>            <layout>default</layout>        </repository>        <snapshotRepository>            <id>snapshots</id>            <name>Nexus Managed Snapshots Repository</name>            <url>http://192.168.0.55:8081/nexus/content/repositories/snapshots</url>            <uniqueVersion>true</uniqueVersion>            <layout>default</layout>        </snapshotRepository>    </distributionManagement>

3)在Nexus中配置release和snapshortsRepository。
4)在maven项目中运行mvn deploy就能发布到远程仓库中去了。

mybatis源码导出,通过eclipse导入maven项目可以checkout出Mybatis的源码进行分析,学习。
http://mybatis.googlecode.com/svn/sub-projects/mybatis-parent/trunk/
http://mybatis.googlecode.com/svn/trunk/

maven生成ear的方法
maven打包生成ear文件的方式<plugin><artifactId>maven-ear-plugin</artifactId><version>2.3.2</version><configuration><finalName>Advisor</finalName><version>5</version><generatedDescriptorLocation>${basedir}/src/main/application/META-INF</generatedDescriptorLocation><modules>    <webModule><groupId>cn.tradewin.advisor</groupId><artifactId>AdvisorWeb</artifactId><uri>AdvisorWeb.war</uri><bundleFileName>AdvisorWeb.war</bundleFileName><contextRoot>/advisor</contextRoot>            </webModule></modules><defaultLibBundleDir>/lib</defaultLibBundleDir></configuration></plugin>

maven打包方式
<plugin>            <groupId>org.apache.maven.plugins</groupId>            <artifactId>maven-dependency-plugin</artifactId>            <executions>                <execution>                    <id>copy-dependencies</id>                    <phase>prepare-package</phase>                    <goals>                        <goal>copy-dependencies</goal>                    </goals>                    <configuration>                        <outputDirectory>${project.build.directory}/lib</outputDirectory>                        <overWriteReleases>false</overWriteReleases>                        <overWriteSnapshots>false</overWriteSnapshots>                        <overWriteIfNewer>true</overWriteIfNewer>                    </configuration>                </execution>            </executions>        </plugin>        <plugin>            <groupId>org.apache.maven.plugins</groupId>            <artifactId>maven-jar-plugin</artifactId>            <configuration>                <archive>                    <manifest>                        <addClasspath>true</addClasspath>                        <classpathPrefix>lib/</classpathPrefix>                        <mainClass>theMainClass</mainClass>                    </manifest>                </archive>            </configuration>        </plugin>