基于MAVEN的WEB 工程配置

1.下载 maven

 

http://maven.apache.org/download.cgi



 

 

2.解压缩,如解压缩目录为:

 

F:\yanlei\javatool\maven\apache-maven-3.2.1

 

3.配置本地仓库

打开apache-maven-3.2.1 下conf/settings.xml

找到注释行:<localRepository>/path/to/local/repo</localRepository>在正面添加一行:

<localRepository>F:\yanlei\maven_repository</localRepository>

 

指定本地仓库地址

 

4.配置代理

打开apache-maven-3.2.1 下conf/settings.xml 在<proxies>元素下添加:

<proxy>
<id>myPorxy</id>
<active>true</active>
<protocol>http</protocol>
<username>yanlei</username>
<password>xxxx</password>
<host>proxy.aaa.com</host>
<port>80</port>
<nonProxyHosts>local.net|some.host.com</nonProxyHosts>
</proxy>

 

配置国内Maven仓库镜像(国内镜像下载会快一点):

打开apache-maven-3.2.1 下conf/settings.xml 在<mirrors>元素下添加:

<mirror>  

      <id>CN</id>  

      <name>OSChina Central</name>                                                                                                                         

      <url>http://maven.oschina.net/content/groups/public/</url>  

      <mirrorOf>central</mirrorOf>  

    </mirror>  

 

5.配置环境变量

环境变量名:M2_HOME=F:\yanlei\javatool\maven\apache-maven-3.2.1

path中添加:%M2_HOME%\bin

 

 

6.测试mvn 正常配置

执行命令:mvn -v

 

 

输出:

Apache Maven 3.2.1 (ea8b2b07643dbb1b84b6d16e1f08391b666bc1e9; 2014-02-15T01:37:5

2+08:00)

Maven home: F:\yanlei\javatool\maven\apache-maven-3.2.1

Java version: 1.6.0_04, vendor: Sun Microsystems Inc.

Java home: F:\yanlei\app\jdk1.6\jre

Default locale: zh_CN, platform encoding: GBK

OS name: "windows xp", version: "5.1", arch: "x86", family: "windows"

 

 

7.执行  mvn help:system 命令

该命令会打印出系统相关系信息及下载help插件

 

8.eclipse 上安装m2eclipse插件

如果是用代理上网,为Eclipse 配置代理(Active Provider 选择 manual):

 



 

然后 help->install new software 添加插件更新地址:(见http://www.eclipse.org/m2e/download/)

 

 

http://download.eclipse.org/technology/m2e/releases

 

 



 

安装成功后需要重启eclipse.

 

 

9.配置maven 安装目录




 

 

10. 建 立maven工程

file->new ->other

 



 

 
 next->选择maven-archetype-webapp

 



 

 

录入groupId,artifactId,package 

 



 

点击finish完成。

 

 

11.配置源程序目录

工程建完之后,如图:



 

工程有错误:

 

工程右键properties 选择java build path:

 

 

比对工程文件目录,发现src/main下没有java 目录,src下没有 test/java目录,在文件系统中新建 src/main/java ,src/test/java ,刷新工程,2个报错就没有了:



 

 



 

 

新建源目录:src/test/resource



 

 



 

 建完之后,工程如图:


 

 
 修改web.xml 使用变为 servlet 2.5 或 servlet 3.0 

<?xml version="1.0" encoding="UTF-8"?>

<web-app 

xmlns="http://java.sun.com/xml/ns/javaee" 

xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 

xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" 

id="WebApp_ID" 

version="2.5">

  <display-name>app-cas</display-name>

  <welcome-file-list>

    <welcome-file>index.html</welcome-file>

    <welcome-file>index.htm</welcome-file>

    <welcome-file>index.jsp</welcome-file>

    <welcome-file>default.html</welcome-file>

    <welcome-file>default.htm</welcome-file>

    <welcome-file>default.jsp</welcome-file>

  </welcome-file-list>

</web-app>

 

 

13.添加 jetty-maven-plugin 插件运行maven web 工程

 

  到http://mvnrepository.com 网站上查询该 maven 坐标

 

 

 

打开pom.xml 在build元素下添加: etty-maven-plugin插件

 

pom.xml:

 

 

<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.yanlei.app</groupId>

  <artifactId>app-cas</artifactId>

  <packaging>war</packaging>

  <version>0.0.1-SNAPSHOT</version>

  <name>app-cas Maven Webapp</name>

  <url>http://maven.apache.org</url>

  <dependencies>

    <dependency>

      <groupId>junit</groupId>

      <artifactId>junit</artifactId>

      <version>3.8.1</version>

      <scope>test</scope>

    </dependency>

  </dependencies>

  <build>

    <finalName>app-cas</finalName>

     <plugins>

    <plugin>

    <groupId>org.mortbay.jetty</groupId>

<artifactId>jetty-maven-plugin</artifactId>

<version>8.1.15.v20140411</version>

<configuration>

<scanIntervalSeconds>10</scanIntervalSeconds>

<webAppConfig>

<contextPath>/app-test</contextPath>

</webAppConfig>

</configuration>

    </plugin>

    </plugins>

  </build>

</project>

 

 

 

14.运行工程

   工程 右键  ->run as ->maven build:

 

   打开窗口,在goals 中录入:jetty:run ,

 




 
 点击run

 

控制台输出:

[INFO] <<< jetty-maven-plugin:8.1.15.v20140411:run (default-cli) @ app-cas <<<

[INFO]

[INFO] --- jetty-maven-plugin:8.1.15.v20140411:run (default-cli) @ app-cas ---

[INFO] Configuring Jetty for project: app-cas Maven Webapp

[INFO] webAppSourceDirectory not set. Defaulting to F:\yanlei\app\kepler_worksapce\app-cas\src\main\webapp

[INFO] Reload Mechanic: automatic

[INFO] Classes = F:\yanlei\app\kepler_worksapce\app-cas\target\classes

[INFO] Context path = /app-test

[INFO] Tmp directory = F:\yanlei\app\kepler_worksapce\app-cas\target\tmp

[INFO] Web defaults = org/eclipse/jetty/webapp/webdefault.xml

[INFO] Web overrides = none

[INFO] web.xml file = file:/F:/yanlei/app/kepler_worksapce/app-cas/src/main/webapp/WEB-INF/web.xml

[INFO] Webapp directory = F:\yanlei\app\kepler_worksapce\app-cas\src\main\webapp

2014-06-18 16:51:46.750:INFO:oejs.Server:jetty-8.1.15.v20140411

2014-06-18 16:51:47.218:INFO:oejpw.PlusConfiguration:No Transaction manager found - if your webapp requires one, please configure one.

2014-06-18 16:51:50.984:WARN:oejsh.RequestLogHandler:!RequestLog

[INFO] Started Jetty Server

2014-06-18 16:51:52.125:INFO:oejs.AbstractConnector:Started SelectChannelConnector@0.0.0.0:8080

[INFO] Starting scanner at interval of 10 seconds.

 

 

启动成功。

 

前台访问:



 

 

15. 打war

 

工程--》右键-->run as -->maven install

 

控制台输出:

[INFO] --- maven-install-plugin:2.4:install (default-install) @ app-cas ---

[INFO] Installing F:\yanlei\app\kepler_worksapce\app-cas\target\app-cas.war to F:\yanlei\maven_repository\com\yanlei\app\app-cas\0.0.1-SNAPSHOT\app-cas-0.0.1-SNAPSHOT.war

[INFO] Installing F:\yanlei\app\kepler_worksapce\app-cas\pom.xml to F:\yanlei\maven_repository\com\yanlei\app\app-cas\0.0.1-SNAPSHOT\app-cas-0.0.1-SNAPSHOT.pom

[INFO] ------------------------------------------------------------------------

[INFO] BUILD SUCCESS

[INFO] ------------------------------------------------------------------------

[INFO] Total time: 9.812 s

[INFO] Finished at: 2014-06-18T16:56:39+08:00

[INFO] Final Memory: 4M/8M

 

 

生成war包成功。 可以布署到WEB服务器上了。 

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值