4

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

  1. 信息: 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 文件。

手动将war文件部署到tomcat和使用maven插件是一样的吗?

命令 mvn tomcat6:deploy 的 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>
4

3 回答 3

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

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

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

于 2012-04-19T23:35:34.650 回答
0

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

于 2012-07-27T18:36:33.707 回答
0

问题已在 Chris White 的帮助下得到解决,这是必不可少的。似乎 Tomcat 保留了一些旧版本的 webapp,它由旧版本的 Spring 组件组成。关闭 Tomcat 并手动删除打包和未打包的 webapp 文件后,我可以通过 maven 插件再次部署。

于 2012-04-20T03:35:44.420 回答