无法使用maven插件将war部署到tomcat

时间:2012-04-19 19:32:57

标签: tomcat maven deployment

如果我手动将我的网络应用程序部署到tomcat 6,一切正常。但是当我尝试使用maven6-tomcat-plugin做同样的事情时,它将不会部署。接下来是一个主机错误,其中没有一个是有意义的(来自catalina.out日志文件):

  1. INFO:validateJarFile(/var/lib/tomcat6/webapps/spring_sec/WEB-INF/lib/servlet-api-2.5.jar) - jar未加载。这是不正确的;我解压了war文件,文件显然存在。

  2. 严重:命名上下文的创建失败:javax.naming.NamingException:上下文是只读的。

  3. 严重:部署Web应用程序存档时出错spring_sec.war java.lang.NoClassDefFoundError:org / springframework / beans / factory / Aware。另一个不真实的陈述;在解压缩war包之后,我找到了包含所需类的WEB-INF / lib / spring-beans-3.1.1.RELEASE.jar文件。

  4. 将war文件手动部署到tomcat并使用maven插件是一回事吗?

    命令mvn tomcat6的maven输出:在mvn clean之后部署:

    [INFO] Scanning for projects...
    [INFO]
    [INFO] ------------------------------------------------------------------------
    [INFO] Building SpringSec 0.1.0-SNAPSHOT
    [INFO] ------------------------------------------------------------------------
    [INFO]
    [INFO] >>> tomcat6-maven-plugin:2.0-beta-1:deploy (default-cli) @ spring_sec >>>
    [INFO]
    [INFO] --- maven-resources-plugin:2.3:resources (default-resources) @ spring_sec ---
    [INFO] Using 'UTF-8' encoding to copy filtered resources.
    [INFO] skip non existing resourceDirectory /media/winchester/spring_sec/src/main/resources
    [INFO]
    [INFO] --- maven-compiler-plugin:2.3.2:compile (default-compile) @ spring_sec ---
    [INFO] Compiling 1 source file to /media/winchester/spring_sec/target/classes
    [INFO]
    [INFO] --- maven-resources-plugin:2.3:testResources (default-testResources) @ spring_sec ---
    [INFO] Using 'UTF-8' encoding to copy filtered resources.
    [INFO] skip non existing resourceDirectory /media/winchester/spring_sec/src/test/resources
    [INFO]
    [INFO] --- maven-compiler-plugin:2.3.2:testCompile (default-testCompile) @ spring_sec ---
    [INFO] Nothing to compile - all classes are up to date
    [INFO]
    [INFO] --- maven-surefire-plugin:2.10:test (default-test) @ spring_sec ---
    [INFO] No tests to run.
    [INFO] Surefire report directory: /media/winchester/spring_sec/target/surefire-reports
    
    -------------------------------------------------------
     T E S T S
    -------------------------------------------------------
    
    Results :
    
    Tests run: 0, Failures: 0, Errors: 0, Skipped: 0
    
    [INFO]
    [INFO] --- maven-war-plugin:2.2:war (default-war) @ spring_sec ---
    [INFO] Packaging webapp
    [INFO] Assembling webapp [spring_sec] in [/media/winchester/spring_sec/target/spring_sec-0.1.0-SNAPSHOT]
    [INFO] Processing war project
    [INFO] Copying webapp resources [/media/winchester/spring_sec/src/main/webapp]
    [INFO] Webapp assembled in [40 msecs]
    [INFO] Building war: /media/winchester/spring_sec/target/spring_sec-0.1.0-SNAPSHOT.war
    [INFO] WEB-INF/web.xml already added, skipping
    [INFO]
    [INFO] <<< tomcat6-maven-plugin:2.0-beta-1:deploy (default-cli) @ spring_sec <<<
    [INFO]
    [INFO] --- tomcat6-maven-plugin:2.0-beta-1:deploy (default-cli) @ spring_sec ---
    [INFO] Deploying war to ***:8080/spring_sec
    Uploading: ***:8080/manager/html/deploy?path=%2Fspring_sec
    3211/3211 KB
    Uploaded: ***:8080/manager/html/deploy?path=%2Fspring_sec (3211 KB at 50171.2 KB/sec)
    [INFO] FAIL - Failed to deploy application at context path /spring_sec
    [INFO] ------------------------------------------------------------------------
    [INFO] BUILD SUCCESS
    [INFO] ------------------------------------------------------------------------
    [INFO] Total time: 4.280s
    [INFO] Finished at: Thu Apr 19 22:07:39 EEST 2012
    [INFO] Final Memory: 15M/144M
    [INFO] ------------------------------------------------------------------------
    

    ** Maven pom:**

    <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
      <modelVersion>4.0.0</modelVersion>
    
      <groupId>com.denarced</groupId>
      <artifactId>spring_sec</artifactId>
      <version>0.1.0-SNAPSHOT</version>
      <packaging>war</packaging>
    
      <name>SpringSec</name>
      <url>http://maven.apache.org</url>
    
      <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
      </properties>
    
      <dependencies>
        <dependency>
          <groupId>junit</groupId>
          <artifactId>junit</artifactId>
          <version>3.8.1</version>
          <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-beans</artifactId>
            <version>3.1.1.RELEASE</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-webmvc</artifactId>
            <version>3.1.1.RELEASE</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-context</artifactId>
            <version>3.1.1.RELEASE</version>
        </dependency> 
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-context-support</artifactId>
            <version>3.1.1.RELEASE</version>
        </dependency>
      </dependencies>
    
      <build>
        <plugins>
          <plugin>
            <artifactId>maven-war-plugin</artifactId>
            <version>2.2</version>
          </plugin>
          <plugin>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>2.3.2</version>
            <configuration>
              <source>1.6</source>
              <target>1.6</target>
            </configuration>
          </plugin>
          <plugin>
            <groupId>org.apache.tomcat.maven</groupId>
            <artifactId>tomcat6-maven-plugin</artifactId>
            <version>2.0-beta-1</version>
            <configuration>
              <server>lapserver</server>
              <url>http://192.168.11.7:8080/manager/html</url>
            </configuration>
          </plugin>
        </plugins>
      </build>
    </project>
    

3 个答案:

答案 0 :(得分:2)

  1. Tomcat不会加载servlet-api.jar,因为它是Tomcat的核心部分(并且已经存在于$ TOMCAT_HOME / lib文件夹中),这个'info'语句只是告诉你Tomcat已被忽略jar文件

  2. 当你说它手动部署时工作正常 - 你的意思是什么?您是手动将war文件放在$ TOMCAT_HOME / webapps文件夹中,还是使用管理器Web应用程序并在部署页面上上传war。你能否确认你能够通过管理器应用程序“手动”部署(这是maven-tomcat6-plugin包装的内容 - 对管理器webapp的PUT,发布你的war文件

  3. 您能否验证解压缩的war文件(在$ TOMCAT_HOME / webapps / spring_sec / WEB-INF / lib中)包含spring-beans-3.1.1.RELEASE.jar

答案 1 :(得分:0)

克里斯怀特的帮助解决了问题,这是必不可少的。看起来Tomcat正在坚持使用一些旧版本的webapp,它是由Spring组件的旧版本组成的。关闭Tomcat并手动删除打包和未打包的webapp文件后,我可以通过maven插件再次部署。

答案 2 :(得分:0)

您也可以使用货物插件。有关详细信息,请参阅http://tshikatshikaaa.blogspot.nl/2012/07/how-to-deploy-war-to-tomcat-7-during.html