MAVEN使用说明

MAVEN使用说明

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账号...

(1)


相关推荐

  • Linux Platform devices 平台设备驱动

    Linux Platform devices 平台设备驱动platform平台设备驱动是基于设备总线驱动模型的,它只不过是将device进一步封装成为platform_device,将device_driver进一步封装成为platform_device_driver,前面已经分析过设备总线驱动模型,关于device与device_driver的注册过程以及它们在sysfs文件系统中的层次关系就不在分析,本文重点分析platform平台

  • poj 3613 Cow Relays

    poj 3613 Cow Relays

  • from pyquery import PyQuery as pq「建议收藏」

    from pyquery import PyQuery as pq「建议收藏」了解更多关注微信公众号“木下学Python”吧~1.爬取知乎-发现-热门话题的问答:importrequestsfrompyqueryimportPyQueryaspqurl=’https://www.zhihu.com/explore’headers={‘user-agent’:’Mozilla/5.0(WindowsNT10.0;WOW64)…

  • cboard企业版源码_CBoard「建议收藏」

    cboard企业版源码_CBoard「建议收藏」CBoardAnopenBIDashboardplatformthatsupportsinteractivemulti-dimensionalreportdesignanddataanalysisServersideframeworkisSpring+MyBatisandfront-endisbasedonAngularJS1andBootstra…

    2022年10月21日
  • 谈谈阿里云服务器

    谈谈阿里云服务器原文发布于2012年09月29日  一年多之前,也就11年5月份的样子,阿里云云服务器产品线终于上线了。但那时候,国内完全没有能称得上云服务器的,很多小公司就是搞个VPS就叫云服务器了。以至于阿里云云服务器刚出来的时候,很多站长也是这么说的。那会儿我国外的虚拟主机也即将到期,而且国外访问速度确实要差不少。所以当时咬咬牙,狠下心来花了1999元买了一台(即现在的标准A,已经涨价了,呵呵,目前

  • npm 更换包源

    npm 更换包源一、前言在每一次的实际开发过程中,我们都会下载相关的依赖包,最官方的是npm,但是该服务器对于国内开发者来说,下载起来是比较慢的,所以我们需要换源。(有梯子或者信任官网的请忽略)二、cnpm:国内对npm的镜像版本/**cnpm官网地址:https://npm.taobao.org/*cnpm的大多命令跟npm的是一致的,比如安装,卸载这些*/npminstall-gcnpm–registry=https://registry.npm.taobao.org

发表回复

您的电子邮箱地址不会被公开。

关注全栈程序员社区公众号