欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

Maven site:deploy 站点部署 博客分类: Java mavensitedeploytomcat 

程序员文章站 2024-03-18 21:24:40
...
    Maven site生成的站点文件,可以直接部署到容器中,以下以Tomcat为例。
    1> tomcat默认支持WebDav协议,支持热部署。
    首先在Tomcat的webapps目录下生成一个site目录,然后在site目录里生成WEB-INF目录,结构如下:
    apache-tomcat-7.0.47
     |--webapps
        |--site
           |--WEB-INF
              |--web.xml
      web.xml内容如下:
<servlet> 
<servlet-name>webdav</servlet-name> 
<servlet-class>org.apache.catalina.servlets.WebdavServlet</servlet-class> 
<init-param> 
    <param-name>debug</param-name> 
    <param-value>0</param-value> 
    </init-param> 
<init-param> 
    <param-name>listings</param-name> 
    <param-value>true</param-value> 
</init-param> 
<init-param> 
    <param-name>readonly</param-name> 
    <param-value>false</param-value> 
</init-param> 
<load-on-startup>1</load-on-startup> 
</servlet> 
 
<servlet-mapping> 
<servlet-name>webdav</servlet-name> 
<url-pattern>/*</url-pattern> 
</servlet-mapping> 

   <!-- Define a Security Constraint on this Application -->
  <!-- NOTE:  None of these roles are present in the default users file -->
  <security-constraint>
    <web-resource-collection>
      <web-resource-name>Site</web-resource-name>
      <url-pattern>/*</url-pattern>
    </web-resource-collection>
    <auth-constraint>
       <role-name>site</role-name>
    </auth-constraint>
  </security-constraint>

  <!-- Define the Login Configuration for this Application -->
  <login-config>
    <auth-method>BASIC</auth-method>
    <realm-name>Maven Site Deploy</realm-name>
  </login-config>

  <!-- Security roles referenced by this web application -->
  <security-role>
    <description>
      The role that is required to access to site pages
    </description>
    <role-name>site</role-name>
  </security-role>
</web-app> 

    <security-role>、<login-config>、<security-constraint>是给发布站点增加访问权限设置,以上设置为只有角色为site的用户才能访问发布站点。
    site角色用户,在tomcat根目录下的conf/tomcat-users.xml增加以下设置:
<role rolename="site" />
<user username="admin" password="xxxxxx" roles="site" />

    2> 在项目的pom.xml中增加以下设置:
    <!--设置site插件读取源文件、输出站点文件的编码格式为UTF-8 -->
    <properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
    </properties>
   
    <reporting>
<plugins>
            <!--测试代码覆盖率报告插件 -->
    <plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>cobertura-maven-plugin</artifactId>
<version>2.6</version>
<configuration>
<aggregate>true</aggregate>
</configuration>
    </plugin>
            <!--javadoc报告插件 -->
    <plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>2.10.1</version>
    </plugin>
            <!--源代码在线查看插件 -->
    <plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jxr-plugin</artifactId>
<version>2.4</version>
<configuration>
    <aggregate>true</aggregate>
</configuration>
    </plugin>
            <!--代码规范检查报告插件 -->
    <plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<version>2.13</version>
        <configuration>
<configLocation>config/maven_checks.xml</configLocation>
<goal>checkstyle-aggregate</goal>
</configuration>
    </plugin>
            <!--版本控制信息报告插件 -->
    <plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-changelog-plugin</artifactId>
<version>2.3</version>
    </plugin>
            <!--findbugs报告插件 -->
    <plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>findbugs-maven-plugin</artifactId>
<version>3.0.0</version>
    </plugin>
</plugins>
    </reporting>

    <!--发布站点URL配置 -->
    <distributionManagement>
<site>
      <id>site</id>
    <url>dav:http://localhost:8080/site</url>
</site>
    </distributionManagement>

    <build>
<plugins>
                <!-- 配置site插件使用中文界面 -->
        <plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-site-plugin</artifactId>
<version>3.4</version>
<configuration>
<locales>zh_CN</locales>
</configuration>
</plugin>
        </plugins
<extensions>
                <!-- 配置site插件deploy时,部署到webdav协议的站点时,需要用到的                  
                     webdav协议识别插件 -->
<extension>
<groupId>org.apache.maven.wagon</groupId>
<artifactId>wagon-webdav-jackrabbit</artifactId>
<version>2.7</version>
</extension>
</extensions>
    </build>

    3> 因为site发布的站点设置了访问控制权限,因此需要在用户的settings.xml文件中设置访问权限:
       <server> 
         <!-- id必须和pom.xml中的发布站点id保持一致 -->
         <id>site</id> 
         <username>admin</username> 
         <password>xxxxxx</password> 
       </server> 

    至此,maven site:deploy 站点部署配置完成。maven确实很方便,也做了很多项目信息的整合,确实好用,虽然入门难了点。
    enjoy maven, enjoy life...