POM.XML文件
<?xml version=”1.0″ encoding=”UTF-8″?>
<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.sdo</groupId>
<artifactId>tradinghub</artifactId>
<packaging>war</packaging>
<name>tradinghub</name><version>1.0-SNAPSHOT</version>
===这里是配置==
<properties>
<java-version>1.6</java-version>
<org.springframework-version>3.0.3.BUILD-SNAPSHOT</org.springframework-version>
<org.springframework.roo-version>1.0.2.RELEASE</org.springframework.roo-version>
<org.aspectj-version>1.6.8</org.aspectj-version>
<org.slf4j-version>1.5.10</org.slf4j-version>
</properties>===重要!!项目依赖的包全在这里====
<dependencies>
<!– Spring –>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>${org.springframework-version}</version>
<exclusions>
<!– Exclude Commons Logging in favor of SLF4j –>
<exclusion>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>${org.springframework-version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-orm</artifactId>
<version>${org.springframework-version}</version>
</dependency>
<!– Roo dependencies –>
<dependency>
<groupId>org.springframework.roo</groupId>
<artifactId>org.springframework.roo.annotations</artifactId>
<version>${org.springframework.roo-version}</version>
<scope>provided</scope>
</dependency>
<!– JSR 303 with Hibernate Validator –>
<dependency>
<groupId>javax.validation</groupId>
<artifactId>validation-api</artifactId>
<version>1.0.0.GA</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-validator</artifactId>
<version>4.0.2.GA</version>
</dependency>
<!– AspectJ –>
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjrt</artifactId>
<version>${org.aspectj-version}</version>
</dependency>
<!– URL Rewrite –>
<dependency>
<groupId>org.tuckey</groupId>
<artifactId>urlrewritefilter</artifactId>
<version>3.1.0</version>
</dependency><!– Logging –>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>${org.slf4j-version}</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>jcl-over-slf4j</artifactId>
<version>${org.slf4j-version}</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>${org.slf4j-version}</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.15</version>
<exclusions>
<exclusion>
<groupId>javax.mail</groupId>
<artifactId>mail</artifactId>
</exclusion>
<exclusion>
<groupId>javax.jms</groupId>
<artifactId>jms</artifactId>
</exclusion>
<exclusion>
<groupId>com.sun.jdmk</groupId>
<artifactId>jmxtools</artifactId>
</exclusion>
<exclusion>
<groupId>com.sun.jmx</groupId>
<artifactId>jmxri</artifactId>
</exclusion>
</exclusions>
<scope>runtime</scope>
</dependency><!– @Inject –>
<dependency>
<groupId>javax.inject</groupId>
<artifactId>javax.inject</artifactId>
<version>1</version>
</dependency><!– Servlet –>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>2.5</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.servlet.jsp</groupId>
<artifactId>jsp-api</artifactId>
<version>2.1</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
<version>1.2</version>
</dependency><!– Test –>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.7</version>
<scope>test</scope>
</dependency><dependency>
<groupId>org.apache.ibatis</groupId>
<artifactId>com.springsource.com.ibatis</artifactId>
<version>2.3.4.726</version>
</dependency><dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.2</version>
</dependency><dependency>
<groupId>org.apache.commons</groupId>
<artifactId>com.springsource.org.apache.commons.dbcp</artifactId>
<version>1.2.2.osgi</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>com.springsource.org.apache.commons.logging</artifactId>
<version>1.1.1</version>
</dependency><dependency>
<groupId>dwr</groupId>
<artifactId>dwr</artifactId>
<version>3.0</version>
</dependency></dependencies>
====这里不知道干撒用的,URL连接都不能用,但也写在这儿===
<repositories>
<!– For testing against latest Spring snapshots –>
<repository>
<id>org.springframework.maven.snapshot</id>
<name>Spring Maven Snapshot Repository</name>
<url>http://maven.springframework.org/snapshot</url>
<releases>
<enabled>false</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
<!– For developing against latest Spring milestones –>
<repository>
<id>org.springframework.maven.milestone</id>
<name>Spring Maven Milestone Repository</name>
<url>http://maven.springframework.org/milestone</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
</repositories>==重要!! MAVEN所有的动作都依赖这里,下面一个一个讲===
<build>
这个不用说了:)
<resources>
<resource>
<directory>src/main/java</directory>
<includes>
<include>**/*.xml</include>
</includes>
</resource>
</resources>==PLUGINS,PLUGINS!!编译打包、部署全靠他们了==
<plugins>
默认的 编译用的
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>${java-version}</source>
<target>${java-version}</target>
</configuration>
</plugin>默认的 打WAR 包的
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<configuration>
<warName>tradinghub</warName>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>install</id>
<phase>install</phase>
<goals>
<goal>sources</goal>
</goals>
</execution>
</executions>
</plugin>
===这里浪费了我好多的时间,想用他的一个JBOSS部署,让打包后的WAR文件直接投到JBOSS的部署目录中去
这个和上面的WAR的功能是一样的。。只是这个不是默认的,无法执行到,我找了半天也没有找到在哪里可以改。。也可能根本 就不能改!
用法:
CMD下:
mvn jboss:hard-deploy 意思是让打好的WAR包直接COPY到指定的目录中,他依赖PACKAGE这个动作,后面有总结的用法。。。
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>jboss-maven-plugin</artifactId>
<version>1.4.1</version>
<configuration>
<jbossHome>E:/jboss-4</jbossHome>
<serverName>default</serverName>
<fileName>
${project.build.directory}/tradinghub.war
</fileName>
</configuration>
</plugin>
不知道干撒用的,不关心
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>aspectj-maven-plugin</artifactId>
<!–
Have to use version 1.2 since version 1.3 does not appear to work
with ITDs
–>
<version>1.2</version>
<dependencies>
<!–
You must use Maven 2.0.9 or above or these are ignored (see
MNG-2972)
–>
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjrt</artifactId>
<version>${org.aspectj-version}</version>
</dependency>
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjtools</artifactId>
<version>${org.aspectj-version}</version>
</dependency>
</dependencies>
<executions>
<execution>
<goals>
<goal>compile</goal>
<goal>test-compile</goal>
</goals>
</execution>
</executions>
<configuration>
<outxml>true</outxml>
<source>${java-version}</source>
<target>${java-version}</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<junitArtifactName>junit:junit</junitArtifactName>
<excludes>
<exclude>**/*_Roo_*</exclude>
</excludes>
</configuration>
</plugin>
</plugins>
</build>
</project>
主要就是这个文件了,下面简单说下用法
配置文件搞好后,运行它有两个办法:
1.在ECLIPSE中
用maven build会有很多的框要你填,头晕,只要填写GOALS就可以了,举例:
clean package jboss:hard-deploy
撒意思?这个三个GOAL,每个中间用空格隔开。
clean 是把以前BUILD的清干净
package 是打包的意思,这个GOAL会完成编译打WAR包的动作
JBOSS:HARD-deploy的意思是把打包好的文件COPY的指定的JBOSS目录中去。。
2.在CMD中
mvn clean package jboss:hard-deploy
这就可以了。
这个小东西NND搞了好几天,当然还有很多的小细节就不一一细说了,其实是个很简单的东西,感觉还没有ant好用,只是多了个LIB包集中管理而已,语法太TM晦涩了,特别是命令行参数,看了就晕。。希望这些对新同学们有用。
关于MAVEN的LIB包,简单举个例子
<dependency>
<groupId>mysql</groupId> 这个就是放包的外层文件夹
<artifactId>mysql-connector-java</artifactId>这个是JAR文件名
<version>5.1.2</version>这个是JAR文件版本
</dependency>
文件名和文件版本最头晕,其实也是超简单,为撒就不能给我们说明白了,我看了半天,其实就是把一个文件分成两半就行了,中间用“-”隔开的。
比如上面这个的JAR文件就是:mysql-connector-java-5.1.2.jar 必须的:)
想要自己加个包时就这么搞就行了。名字你胡乱写都 可以,只要记住两半规则和文件夹层次
就这么一东西,哎。。怎么就没人把它这样简单的说说明白呢!!
发布者:全栈程序员-用户IM,转载请注明出处:https://javaforall.cn/100362.html原文链接:https://javaforall.cn
【正版授权,激活自己账号】: Jetbrains全家桶Ide使用,1年售后保障,每天仅需1毛
【官方授权 正版激活】: 官方授权 正版激活 支持Jetbrains家族下所有IDE 使用个人JB账号...