• 基于maven的JavaWeb项目构建部署


    需要准备的安装文件:

    1 JDk

    http://www.oracle.com/technetwork/java/javase/downloads/index-jsp-138363.html

    jdk-8u45-windows-x64.exe  有64位和32位的

    2 Apache Tomcat

    http://tomcat.apache.org/,下载需要的版本,有64位和32位的,应与JDK对应;32位的tomcat是不能启动64位的JDK的。

    apache-tomcat-7.0.62-windows-x64.zip

    3 Apache Maven

    http://maven.apache.org/download.cgi,也依赖JDK

    apache-maven-3.3.3-bin.zip

    安装:

    1 JDK的安装

    双击exe文件安装到D盘

    设置环境变量:

    ClassPath  .;%JAVA_HOME%libdt.jar;%JAVA_HOME%lib ools.jar;

    JAVA_HOME D:Program FilesJavajdk1.8.0_45

    Path  .;%JAVA_HOME%in;

    2 Apache Tomcat的安装

    只需要解压即可,默认占用8080端口,如果已占用,可以更改端口

    将tomcat注册成服务

    注册卸载服务:http://blog.csdn.net/nddjava/article/details/6426911

    命令行启动服务:http://www.cnblogs.com/wlei/archive/2011/12/24/2300389.html

    3 Apache Maven的安装

    只需要解压即可,设置环境变量

    Path  D:Program Filesapache-maven-3.3.3in

    可以在命令行输入mvn -version验证是否配置成功

    将源代码编译打包

    在命令行模式cd命令进入源代码目录

    输入命令mvn clean package,关于命令的用法关系到maven的生命周期,可参考:http://juvenshun.iteye.com/blog/213959

    构建成功后,会在项目的target目录下生成war包

    以上是最理想的状态,实际上在构建时可能会碰到很多问题。有时候项目有依赖,可能是中央仓库(可使用Nexus作为中央仓库)、远程仓库的依赖,maven构建是依据pom.xml这个文件进行的,如果下不到这个依赖的组件,构建就会出错,因此在实际应用中,maven是需要进行配置的。

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

    <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>F:CImaven3.0.3_repository</localRepository>

        <servers>

         <server>
              <id>dev</id>
              <username>admin</username>
              <password>admin123</password>
           </server>  
           <server>
                <id>deploymentRepo</id>
                     <username>deployment</username>
                 <password>111111</password>
                </server>

          </servers>

      <mirrors>

         <mirror>
                 <id>central</id>
                 <mirrorOf>*</mirrorOf>
                           <name>mdp remote artifactory</name>
                           <url>http://10.0.111.153:8081/nexus/content/groups/public/</url>
                 </mirror>
          </mirrors>

     <profiles>

       <profile>
             <id>dev</id>
                <repositories>
                   <repository>
                       <id>nexus</id>
                       <url>http://10.0.111.153:8081/nexus/content/groups/public/</url>
                       <releases>
                          <enabled>true</enabled>
                       </releases>
                       <snapshots>
                          <enabled>true</enabled>
                       </snapshots>
                    </repository>
                </repositories>            
                <pluginRepositories>
                    <pluginRepository>
                        <id>nexus</id>
                        <url>http://10.0.111.153:8081/nexus/content/groups/public/</url>
                        <releases>
                            <enabled>true</enabled>
                        </releases>
                        <snapshots>
                            <enabled>true</enabled>
                        </snapshots>
                    </pluginRepository>
                </pluginRepositories>
            </profile>
      </profiles>

     <activeProfiles>
            <activeProfile>dev</activeProfile>
        </activeProfiles>
    </settings>

    将war包部署进Tomcat

    放在Tomcat安装目录的webapps子目录下,重启Tomcat即可

  • 相关阅读:
    【实用】网站常用单词的中英文对照表
    [译][转]jQuery 1.4 发布:15个新特性实例精讲
    popupWindow 简单实现
    程序员修炼之道 读书笔记
    Burp Suite详细使用教程Intruder模块详解
    漏洞挖掘练习环境(linux方向)
    linux系统操作常见问题(ubuntu和opensuse)
    驱动的加载顺序
    磁盘驱动相关知识
    VS 驱动工程创建软件(EeasySyS)
  • 原文地址:https://www.cnblogs.com/hnini/p/4953055.html
Copyright © 2020-2023  润新知