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)


相关推荐

  • 两个求和符号如何用计算机,计算:两个求和符号∑∑怎么办「建议收藏」

    两个求和符号如何用计算机,计算:两个求和符号∑∑怎么办「建议收藏」先将其中一个未知数当常量,另一个未知数从1至n依次递加后各项式子相加。然后再将另一个未知数从1至n依次递加后各项式子相加便是结果。∑是一个求和符号,汉语名称为西格玛(大写Σ,小写σ)。第十八个希腊字母。在希腊语中,如果一个单字的最末一个字母是小写sigma,要把该字母写成ς,在现代的希腊数字代表6。大写Σ用于数学上的总和符号,比如:∑Pi,其中i=1,2,…,T,即为求P1+P2+…

    2022年10月11日
  • Linux 网络配置方法 nmtui 配置

    1、nmtui   tui字符界面图形模式配置  输入命令nmtui即可2、进入配置界面3、选择网络接口 eno16777736 回车4、进行相关网络配置  掩码直接在IP地址后面添加 不然默认32位的       键盘操作  比如 Adress 后面的 SHOW  光标到SHOW 回车 即可出现IP地址配置     最后的自…

  • 如何在 mac 全屏显示网页,且无地址栏、书签栏、任何栏遮挡

    如何在 mac 全屏显示网页,且无地址栏、书签栏、任何栏遮挡

  • c花体复制_花式字体大全可复制 花式字体转换器「建议收藏」

    c花体复制_花式字体大全可复制 花式字体转换器「建议收藏」求可复制花体字?1、windows系统的字体文件都放在这个文件夹下:C:\WINDOWS\Fonts,首先打开此文件夹。2、虽然在此文件夹下右键单击字体文件的菜单中无复制粘贴功能,但是却能使用“复制”快捷键,导出字体文件的方法也就是选中所要导出的字体文件,“Ctrl”“C”(复制快捷键),然后再粘贴到目标文件夹就好了。有好心人发一下英文字母h的花式字体吗,谢谢了,要可以复制的,小写的?这与字体有…

  • 配置更安全的服务器Windows 2003 Server

    配置更安全的服务器Windows 2003 Server

  • 罗技k580切换设备_罗技键盘怎么连接电脑

    罗技k580切换设备_罗技键盘怎么连接电脑插接收器是默认长按F11的,蓝牙是默认长按F12电脑:MacbookPro、联想台式机目的:Mac连蓝牙,联想连接收器步骤:首先进驱动下载地址下载罗技驱动插上接收器进入驱动软件,长按键盘F11,将键盘与联想成功连接,此时联想绑定的为F11长按F12,打开Mac蓝牙,Mac跳出提示(用K580输入6个数字加enter键,然后点击连接),可与Mac成功连接,此时Mac绑定的是F12两台电脑成功连接后,按F11可切换到联想电脑,按F12可切换到Mac…

    2022年10月15日

发表回复

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

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