Chinaunix首页 | 论坛 | 博客
  • 博客访问: 703752
  • 博文数量: 147
  • 博客积分: 6010
  • 博客等级: 准将
  • 技术积分: 1725
  • 用 户 组: 普通用户
  • 注册时间: 2008-08-22 10:36
文章分类

全部博文(147)

文章存档

2011年(1)

2010年(1)

2009年(35)

2008年(110)

我的朋友

分类: Java

2009-06-17 11:54:18

安装:
Windows 2000/XP
Unzip the distribution archive, i.e. apache-maven-2.0.10-bin.zip to the directory you wish to install Maven 2.0.10. These instructions assume you chose C:\Program Files\Apache Software Foundation. The subdirectory apache-maven-2.0.10 will be created from the archive.
Add the M2_HOME environment variable by opening up the system properties (WinKey + Pause), selecting the "Advanced" tab, and the "Environment Variables" button, then adding the M2_HOME variable in the user variables with the value C:\Program Files\Apache Software Foundation\apache-maven-2.0.10. Be sure to omit any quotation marks around the path even if it contains spaces. Note: For Maven < 2.0.9, also be sure that the M2_HOME doesn't have a '\' as last character.
In the same dialog, add the M2 environment variable in the user variables with the value %M2_HOME%\bin.
Optional: In the same dialog, add the MAVEN_OPTS environment variable in the user variables to specify JVM properties, e.g. the value -Xms256m -Xmx512m. This environment variable can be used to supply extra options to Maven.
In the same dialog, update/create the Path environment variable in the user variables and prepend the value %M2% to add Maven available in the command line.
In the same dialog, make sure that JAVA_HOME exists in your user variables or in the system variables and it is set to the location of your JDK, e.g. C:\Program Files\Java\jdk1.5.0_02 and that %JAVA_HOME%\bin is in your Path environment variable.
Open a new command prompt (Winkey + R then type cmd) and run mvn --version to verify that it is correctly installed.
1.查看版本信息:
 shell> mvn -version
如果是校园网,首先要配置代理:M2_HOME/conf/settings.xml中(使用私服的时候,也是在settings里面配置代理,nexus中的Server也有可能配置代理 试试看)
 2.用maven建立简单的java项目框架:
 shell> mvn archetype:create -DgroupId=cn.edu.sdau.neat -DartifactId=mvnproject
 3.用maven建立简单的web-app项目:
 shell> mvn archetype:create -DgroupId=cn.edu.sdau.neat -DartifactId=web-app -DarchetypeArtifactId=maven-archetype-webapp
 4.将mvn建立的项目转为Eclipse项目:
 首次在Eclipse中使用maven2库,先要:
 shell> mvn -Declipse.workspace=/path/to/your/eclipse/workspace eclipse:add-maven-repo
 shell> mvn eclipse:eclipse
打开eclipse导入该项目,并建立src/main/java源程序文件夹
5.在pom.xml中配置下载jar包
  例如:servlet包:
 
      javax.servlet
      servlet-api
      2.5
   

下载jutty插件:

   first-web
  
       
          org.apache.maven.plugins
          maven-compiler-plugin
         
            1.5
            1.5
         

       

       
          org.mortbay.jetty
          maven-jetty-plugin
       
       
  


  然后在:mvn eclipse:eclipse这样在新下载的jar包在eclipse才能生效
 6.用mvn编译项目:
 shell> mvn compile
 7.用mvn测试项目:
 shell> mvn test
 8.用mvn打包项目
 shell> mvn package
9.启动jetty:
 mvn jetty:run
 
 
在eclipse中启动jetty和进行debug测试步骤:
1.选择菜单Run->External Tools->External Tools ...在左边选择Program,再点New:
配置Location为mvn完整命令行(C:\Program Files\Apache Software Foundation\apache-maven-2.0.10\bin\mvn.bat)。
2.选择Working Directory为本项目(${workspace_loc:/first-web})。
3.Arguments填写:jetty:run
4.再点选Enviroment页:加入MAVEN_OPTS变量,值为:
-Xdebug -Xnoagent -Djava.compiler=NONE -Xrunjdwp:transport=dt_socket,address=4000,server=y,suspend=y
其中,如果suspend=n 表示不调试,直接运行。
然后,点APPLY,再关闭本对话框。
5.点选run->debug configuration
选中左树中的Remote Java Application,再点New。
选择你的项目,关键是要填和之前设置外部工具时相同的端口号。
6.首先要把JETTY运行起来(有点象TOMCAT里的运行APPSERVER),从Run->External Tools中选择之前配置的外部工具运行,这时LOG里会显示:
listening at port 4000字样,
7.Run->Debug configuration
选择我们刚建的运行配置,这时程序就RUN起来了,可以通过WEB进行访问,设置断点调试了。
 
 
 
我们如果从网上下载jar包:
可以在google上:maven hibernate repository即可,将依赖配置添加到pom.xml文件中。
maven会先根据setting.xml中的配置到本地的类库下面找jar包 如果找不到在从网上找.
 
 
 
 
一般公司会建立自己的私服:步骤如下(下载war版本,放在tomcat下面运行,因为调试自己的web项目需要jetty,最好把tomcat的端口改为8081):
 访问下载Nexus。  
1.配置nexus
   首先登录,默认地址,默认用户名密码为admin/admin123.
    nexus默认是关闭远程索引下载功能的。开启的方式:
    点击Views/Repositories下的Repositories,将这三个仓库Apache Snapshots,Codehaus Snapshots,Maven Central的
    Download Remote Indexes修改为true。然后在这三个仓库上分别右键,选择Re-index,这样Nexus就会去下载远程的索引文件。
2.管理仓库
以管理员用户登陆然后点击左边导航菜单Administration下面的Repositories。Nexus提供了三种不同的仓库。
(1)代理仓库
  一个代理仓库是对远程仓库的一个代理。默认情况下,Nexus自带了如下配置的代理仓库:
Apache Snapshots
  这个仓库包含了来自于Apache软件基金会的快照版本。
Codehaus Snapshots
  这个仓库包含了来自于Codehaus的快照版本。
Central Maven Repository
  这是中央Maven仓库(发布版本)。
(2)宿主仓库
  一个宿主仓库是由Nexus托管的仓库。Maven自带了如下配置的宿主仓库。
3rd Party
  这个宿主仓库应该用来存储在公共Maven仓库中找不到的第三方依赖。这种依赖的样例有:你组织使用的,商业的,私有的类库如Oracle JDBC驱动。
Releases
  这个宿主仓库是你组织公布内部发布版本的地方。
Snapshots
  这个宿主仓库是你组织发布内部快照版本的地方。
(3)虚拟仓库
  一个虚拟仓库作为Maven 1的适配器存在。Nexus自带了一个central-m1虚拟仓库
3. 管理组
  组是Nexus一个强大的特性,它允许你在一个单独的URL中组合多个仓库。Nexus自带了两个组:public和public-snapshots。public组中组合了三个宿主仓库:3rd Party, Releases, 和Snapshots,还有中央Maven仓库。而public-snapshots组中组合了Apache Snapshots和Codehaus Snapshots仓库。
4. 配置maven
  要让maven使用Nexus作为仓库,要修改~/.m2/settings.xml.
Xml代码
  
     
     nexus  
       
         
           nexus  
           local private nexus  
          
      
  
    
  
  
  
     
     nexus-snapshots  
       
         
           nexus-snapshots  
           local private nexus snapshots  
          
      
  
    
  
  
  
 
  
  
   
    nexus  
    nexus-snapshots  
 
 
 
(在nexus中安装自己的jar包,可以不配这个,通过网页来安装jar包)
5.部署构件至Nexus
   要部署构件至Nexus,在distributionManagement中提供仓库URL,然后运行mvn deploy。Maven会通过一个简单的HTTP PUT将项目POM和构件推入至你的Nexus安装。需要配置你项目POM中distributionManagement部分的repository。
Xml代码
  
    
    releases  
    Internal Releases  
   
 
  
    
    Snapshots  
    Internal Snapshots  
   
 
  
 
 
  这样还没完,这时如果部署会报错,还要在~/.m2/settings.xml中添加如下的服务器登录信息:
Xml代码
  
  releases  
  admin  
  admin123  
  
  
  Snapshots  
  admin  
  admin123  
 
(可以通过网页进行部署)
  部署第三方构件:
  构件可能是私有数据库的JDBC驱动如Oracle,或者你依赖于另一个JAR,它既不开源也无法免费获得。在这样的情况下,你就需要手动拿来这些构件然后发布到你自己的仓库中。Nexus提供宿主的"third-party"仓库,就是为了这个目的。
  使用以下命令发布该文件至Nexus:
Java代码
mvn deploy:deploy-file -DgroupId=com.oracle -DartifactId=ojdbc14   
-Dversion=10.2.0.3.0 -Dpackaging=jar -Dfile=ojdbc.jar    
-Durl=
-DrepositoryId=thirdparty  
 
那么我们这样就可以配置自己的类库了,把一些用到的jar文件安装到nexus中去,查找的顺序:根据pom.xml中使用的jar文件,先从.m2/responsbily下面找,如果找不到在从自己的服务器的Host仓库中找,如果没有,因为有远程的proxy镜像,所以再从远程拷贝下来。
阅读(3878) | 评论(0) | 转发(0) |
0

上一篇:linux下配置ftp服务器

下一篇:java视频总结

给主人留下些什么吧!~~