ITeye博客

maven 发布到tomcat 记录

wenqxin · 2013-07-21 20:54 · java基础 · 项目管理 · 企业架构 · Markdown

忙活了一个周末,终于把appfuse2.2.1通过maven的方式 发布到tomcat 中。特记录一下步骤,虽然最近更新比较慢,但是还是具有参考价值的。

  1. 按照官网的通过mvn 命令下载源码。按照官方下载。

  2. 将下载的源码 from "embedded mode" to full-source mode by running mvn appfuse:full-source from your project's root directory

  3. 这里可以通过 mvn eclipse:eclipse 转换成eclipse 项目。但是这里主要采用maven的发布方式。先不转换成eclipse项目。

  4. 通过eclipse的导入,这里采用从存在的maven 工程导入。

  5. eclipse maven 工程要点:

      • project facet还是要设置成dynamic ;futher configuration 设置修改成src/main/webapp,默认的是dyanmic工程的webContent。
      • 当前项目->properties->deployment assembly 中设置 maven 的依赖库 部署的位置,这里要改为:WEB-INFO/lib
      • build path 中默认的输出为:xxx/target/classes.这里的xxx 为工程名称。
  6. 下面正式开始将工程编译后的源码直接发布到tomcat 中。主要有几下步骤,另外,tomcat7与先前的tomcat 发布方式也是不一样的。要注意。

    • 首先在tomcat的conf 文件夹tomcat-user.xml中,增加用户配置。

    • 如图,关键在于manager-script角色

    • 在工程pom 文件中增加maven tomcat的插件配置

    • 如下,其中url为tomcat管理地址,不同的容器,域名和端口可能不同,注意url的最后必须加上 /text 否则会出错; <path>标签代表工程的名称。     

      <plugin > 

                         <groupId> org.apache.tomcat.maven</groupId > 

                               <artifactId> tomcat7-maven-plugin</artifactId > 

                               <version> 2.0-SNAPSHOT</version > 

                               <configuration>  

                                     <url> http://localhost:8080/manager/text</url > 

                                     <!-- 

                                     <server>tomcat7</server>

                                     -->

                                     <path> /sectioncc</path >

                                           <username> admin</username > 

                                           <password> admin</password >

                               </configuration>  

         </plugin>

    • 启动tomcat 。在运行maven的deploy命令之前,一定要先启动tomcat(直接进入tomcat的bin目录点击startup.bat)或者通过eclipse 的server 视图启动,否则会报:“Cannot invoke Tomcat manager: Connection refused” 错误 。(已验证)

    • 在工程或pom.xml上右键,maven build的goals中输入命令tomcat7:deploy即可发布,或在Run Configurations->Maven build新建一个命令,base directory里选择你的web project 或者通过run as ->maven build ,输入 tomcat7:deploy

    • 在 pom.xml 的configuration节点里面的url最后必须加上 /text ,否则,即使你在运行maven的deploy命令之前已经启动了tomcat,还是会报错:“Cannot invoke Tomcat manager: Server returned HTTP response code: 403 for URL: http://localhost:8080/manager/deploy?path=%2Fframework&war= ”(已验证)


      常见错误:

    • maven build 时出现有appfuse 单元测试的错误,可以先屏蔽掉pom.xml中单元测试的配置。如下图

    • <!--

                    <plugin>

                        <groupId>org.codehaus.mojo</groupId>

                        <artifactId>webtest-maven-plugin</artifactId>

                        <version>1.0.0</version>

                        <executions>

                            <execution>

                                <id>webtest-test</id>

                                <phase>integration-test</phase>

                                <goals>

                                    <goal>test</goal>

                                </goals>

                            </execution>

                            <execution>

                                <id>webtest-verify</id>

                                <phase>verify</phase>

                                <goals>

                                    <goal>verify-result</goal>

                                </goals>

                            </execution>

                            <execution>

                                <id>webtest-report-html</id>

                                <phase>post-integration-test</phase>

                                <goals>

                                    <goal>report</goal>

                                </goals>

                            </execution>

                        </executions>

                        <configuration>

                            <host>${cargo.host}</host>

                            <port>${cargo.port}</port>

                            <sourcedirectory>src/test/resources</sourcedirectory>

                            <sourcefile>web-tests.xml</sourcefile>

                            <target>${webtest.target}</target>

                            <basepath>${project.build.finalName}</basepath>

                            <resultpath>target/webtest/webtest-results</resultpath>

                            <haltonfailure>false</haltonfailure>

                            <haltonerror>false</haltonerror>

                            <loglevel>fatal</loglevel>

                        </configuration>

                    </plugin>

                 -->

 

  • 建议可以删除多余的数据库配置,比如oracle,h2等。
  • 如果出现mysql 方言的bug,将pom.xml中的org.hibernate.dialect.MySQL5InnoDBDialect 修改为:MySQL5Dialect.
  • 发布成功的标志是:

评论(0)

暂无评论。

评论功能维护中,当前仅展示历史评论。