• 部署maven的一些要点、遇到的问题


     
    
    一、       maven环境的搭建
    
    1、 下载并配置maven(可做可不做)
    
    (1)到http://maven.apache.org下载maven的最新版本,并解压到某一目录(假设是d:developapache-maven3.0);
    2)配置系统环境变量:PATH里面加上d:developapache-mavenin
    
    (3)配置JAVA_HOME到jdk目录
    
    (4)在命令行上输入 : mvn -version; 回车,如看到下面信息表示安装成功:
    
    (5)在命令行上输入 : mvn help:system; 回车,会在当前用户目录下(win7是C:Users用户名,xp是c:documents and settings用户名),建立.m2目录。
    
     
    
    2、 Eclipse集成maven
    
    Update site是http://m2eclipse.sonatype.org/sites/m2e,全选安装就好了,重启eclipse.
    
    这样就安装了eclipse集成的maven插件,但建议使用在第一步下载maven,做法如下:进入Preferences——》maven——》Installations,点击“Add”添加maven的解压路径。
    
    3、建立settings.xml文件
    
    以下是我的配置,这里需要建立一个私服,在第四点介绍仓库时会介绍。
    
    <settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
    
              xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    
              xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0
    
                          http://maven.apache.org/xsd/settings-1.0.0.xsd">
      <localRepository>d:
    epository</localRepository>
      <profiles>
        <profile>
               <id>dev</id>
          <repositories>
                <repository>
                         <id>releases</id>
                                 <url>http://localhost:8888/nexus/content/repositories/releases</url>
                                 <releases><enabled>true</enabled></releases>
                               <snapshots><enabled>true</enabled></snapshots>
                         </repository>      
            <repository>
             <id>central</id>
             <name>Central</name>
             <url>http://localhost:8888/nexus-2.0.3/content/repositories/central/</url>
             <releases><enabled>true</enabled></releases>
             <snapshots><enabled>true</enabled></snapshots>
            </repository>
          </repositories>
        </profile>
      </profiles>
     <activeProfiles>
        <activeProfile>dev</activeProfile>
      </activeProfiles>
    </settings>
    
    其中下面标注为红色的,需要修改为自己的一个本地目录,以后所有的jar包都会放在这个下面.
    
    我们将项目所需要用到除源代码之外的东西(如jar包,tomcat,script等都放在上面)通过这个文件,MAVEN会从服务器会拉取jar包到本地,如果服务器上的包有更新,也会自动去更新,这样,当框架有新的版本出现时,不再需要我们手动去重新添加jar包这么麻烦。
    
    
    二、网厅环境的搭建(我配置的是南昌网厅,遇到错误没有成功运行)
    
    1、检出entity、base为java project  ,biz为ejb project ,web为动态网页工程,script为javascript project。都有红叉叉,没事,继续下面的步骤后就好了。
    
    2, 检出完成后对每个工程进行添加maven-enable依赖管理。
    
         选中项目右键“Maven—》Enable Depandency management”,弹出以下界面:
    
    这里需要设置maven的坐标,可以参考第四点的坐标。Group ID使用com.maywide.ibh,artifact Id是构件的id,设置为项目的名称,version不用管。Packaging除了web project用war外,其他选jar。
    
    3、依赖管理。打开项目的pom.xml文件添加依赖项。如biz_nanchang的依赖配置如下:
    
    <dependencies>
    
        <dependency>
    
          <groupId>com.maywide.ibh</groupId>
    
          <artifactId>base</artifactId>
    
          <version>0.0.1-SNAPSHOT</version>
    
        </dependency>
    
        <dependency>
    
          <groupId>com.maywide.ibh</groupId>
    
          <artifactId>entity</artifactId>
    
          <version>0.0.1-SNAPSHOT</version>
    
        </dependency>
    
        <dependency>
    
          <groupId>com.maywide.ibh</groupId>
    
          <artifactId>lib95</artifactId>
    
          <version>1.0</version>
    
        </dependency>
    
        <dependency>
    
          <groupId>com.maywide.ibh</groupId>
    
          <artifactId>lib96</artifactId>
    
          <version>1.0</version>
    
    </dependency>
    
     添加了对base、entity项目的依赖。其中lib95、lib96是privatelib的jar包。我上传到私服时把它命名成这样了。Base、entity项目也需要添加对lib的依赖项,在私服需要一个个jar包上传,所以需要一个个的添加依赖,lib有94个jar吧,慢慢加呗。因为maven的依赖具有传递性的,所以biz_nanchang项目不需要添加对lib的jar包的依赖。同理,web_nanchang项目只需要添加对biz_nanchang的依赖就可以了。
    
             之后选择mvn install编译。
    
    3、把biz_nanchang和web_nanchang项目的jdk改成1.6。进行maven下的操作时经常会把jdk给成1.5的,要检查一下。
    
    4、添加maven的依赖库到Web Deployment Assembly。网上说要这样做的,防止找不到jar包,不过这一步我没体现到它的用处。
    
    5、Web工程右键->Run as->Maven build,这时会跳出一个页面:如图:
    
    在goals输入:tomcat:run-war,
    
     
    
    在VM参数:添加
    
     -Xdebug -Xrunjdwp:transport=dt_socket,address=8000,server=y,suspend=n
    
    点击Apply,之后run就可以执行了。但期间遇到错误2、错误3和错误4。错误4没有解决导致网站无法运行。
    
    三、我掌握的maven的一下知识点。
    
    1、坐标
    
             Maven把项目作为构件,每个构件定义一个坐标,由于区分其他的构件,配置依赖时只需加入这个坐标,maven会先到本地仓库查找该构件,找不到就到远程仓库查找。
    
             坐标如下:
    
             GroupId:定义当前maven项目所属的实际项目。例如网厅项目使用com.maywide.ibh。
    
             ArtifactID:构件的ID,一个project、模块的id。
    
             Version:版本号。
    
             Packaging:打包的方式。默认是jar。Web project需要选择war。
    
    2、maven的依赖在<dependency>标签里设置,需输入构建的坐标。Maven是传递依赖的。
    
    3、仓库
     仓库是存储构件的地方。Maven有本地仓库和远程仓库之分。
    (1)本地仓库
    
        在setting.xml的<localRepository>d:
    epository</localRepository>里面配置本地仓库的位置 ,项目所需的构件会被下载到该目录。如网厅项目,我们可以打开该目录F:maven,可以进入com文件夹—》maywinde文件夹—》ibh文件夹,看到我们的base、entity、biz等项目。
    
    (2)远程仓库
    
     远程仓库分为中央仓库和私服。
    
    中央仓库是全世界共享的一下常见的构件。
    
    私服是一家公司、企业自己建的用于存储构件的的一个maven服务器,还有它也起到代理中央仓库的作用。目前最多人使用的是用nexus搭建maven私服。
    
    私服的仓库分成4类:group(仓库组)、hosted(宿主)、proxy(代理)和虚拟(virtual)。Nexus默认已经有中央仓库的代理了。只需把下面提供的url配置到setting.xml文件了。
    
     我们要使用到的是宿主仓库,用于存放项目的jar包。Maven提供Releases仓库用于存放发布版本的构件;Snapshots存放快照版本的构件;3rd party存放第三方构件。
    
     选择一个仓库,可以进入以下界面上传构件:
    
    四、遇到的问题和解决
    
    错误1: [ERROR] Failed to execute goal on project biz_zhuhai: Could not resolve dependencies for project biz_zhuhai:biz_zhuhai:jar:0.0.1-SNAPSHOT: Failed to collect dependencies for [com.maywide.ibh:lib345:pom:1.0 (compile)]: Failed to read artifact descriptor for com.maywide.ibh:lib345:pom:1.0: Could not transfer artifact com.maywide.ibh:lib345:pom:1.0 from/to releases (http://localhost:8888/nexus/content/repositories/releases): Connection to http://localhost:8888 refused: Connection refused: connect -> [Help 1]
    
    解决:这是配置的url有错误或者是私服没有配好,导致构件下载时出错。如果没有jar包需要在私服里下载,可以不配置私服的,也就是可以把setting.xml的profiles里的东西全部删除的。
    
    
    错误2:[ERROR] Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.10:test (default-test) on project web_nanchang: There are test failures.
    
    [ERROR]
    
    
    解决:这是因为测试代码时遇到错误,它会停止编译。只需要在pom.xml的<project>里添加以下配置,使得测试出错不影响项目的编译。
    
    <build>
    
        <plugins>
    
          <plugin>
    
            <groupId>org.apache.maven.plugins</groupId>
    
            <artifactId>maven-surefire-plugin</artifactId>
    
            <configuration>
    
              <testFailureIgnore>true</testFailureIgnore>
    
            </configuration>
    
          </plugin>
    
        </plugins>
    
     </build>
    
    错误3:
    
    [ERROR] Failed to execute goal org.apache.maven.plugins:maven-war-plugin:2.1.1:war (default-war) on project web_nanchang: Error assembling WAR: webxml attribute is required (or pre-existing WEB-INF/web.xml if executing in update mode) -> [Help 1]
    
    [ERROR]
    
    [ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
    
    [ERROR] Re-run Maven using the -X switch to enable full debug logging.
    
    [ERROR]
    
    [ERROR] For more information about the errors and possible solutions, please read the following articles:
    
        解决:maven的web项目默认的webroot是在srcmainwebapp。如果在此目录下找不到web.xml就抛出以上的异常。解决方法在pom.xml加入以下的配置。红色背景字体改成你网站的根目录。
    
    <build> 
    <finalName>simple-webapp</finalName> 
    <plugins> 
    <plugin> 
    <groupId>org.apache.maven.plugins</groupId> 
    <artifactId>maven-war-plugin</artifactId> 
    <version>2.1.1</version> 
    <configuration> 
    <webResources> 
    <resource> 
    <!-- this is relative to the pom.xml directory --> 
    <directory>WebContent</directory> 
    </resource> 
    </webResources> 
    </configuration> 
    </plugin> 
    </plugins> 
    </build>
    
    错误4: 严重: The web application [/web_nanchang] registered the JBDC driver [org.hsqldb.jdbc.JDBCDriver] but failed to unregister it when the web application was stopped. To prevent a memory leak, the JDBC Driver has been forcibly unregistered.
    
    2012-4-27 10:36:49 org.apache.catalina.loader.WebappClassLoader clearReferencesJdbc
    
    严重: The web application [/web_nanchang] registered the JBDC driver [com.mysql.jdbc.Driver] but failed to unregister it when the web application was stopped. To prevent a memory leak, the JDBC Driver has been forcibly unregistered.
    
    还不知道怎样解决,导致运行不了。
    
    错误5:
    
    这个感觉怪怪的,遇过几次。把java complier改成1.6或者disabled dependency manangent后在enable它,搞着搞着就消失了。
    
     

    版权声明:本文为博主原创文章,未经博主允许不得转载。

  • 相关阅读:
    关于js中"window.location.href"、"location.href"、"parent.location.href"、"top.location.href"的用法
    对于json数据的应用01
    关于session应用(1)session过期时间设置
    关于session应用(2)JAVA中怎么使用session
    Jquery常用技巧(3)
    0101对称二叉树 Marathon
    0112路径之和 & 0113所有路径之和 Marathon
    0106105从中序与后序遍历序列中构造二叉树 Marathon
    0110平衡二叉树 Marathon
    0513找树左下角的值 Marathon
  • 原文地址:https://www.cnblogs.com/weiguo21/p/4824004.html
Copyright © 2020-2023  润新知