Tomcat7 + Maven插件:Tomcat不会以我的战争开始

时间:2016-07-04 11:34:13

标签: java maven tomcat

我在maven tomcat插件中使用java 8tomcat 7以及maven 3.3.9

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.tomcat.maven</groupId>
            <artifactId>tomcat7-maven-plugin</artifactId>
            <version>2.2</version>
            <configuration>
                <port>8085</port>
            </configuration>
        </plugin>
    </plugins>
</build>

有一段时间一切正常,tomcat7:run-war有效。

现在我没有明显的理由得到这个错误:

[INFO] --- tomcat7-maven-plugin:2.2:run-war (default-cli) @ tomcat-example ---
[INFO] Running war on http://localhost:8085/tomcat-example
[INFO] Using existing Tomcat server configuration at /Users/shikloshi/java_workspace/webapp-examples/tomcat-example/target/tomcat
[INFO] create webapp with contextPath: /tomcat-example
Jul 04, 2016 2:30:45 PM org.apache.coyote.AbstractProtocol init
INFO: Initializing ProtocolHandler ["http-bio-8085"]
Jul 04, 2016 2:30:45 PM org.apache.catalina.core.StandardService startInternal
INFO: Starting service Tomcat
Jul 04, 2016 2:30:45 PM org.apache.catalina.core.StandardEngine startInternal
INFO: Starting Servlet Engine: Apache Tomcat/7.0.47
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1.693s
[INFO] Finished at: Mon Jul 04 14:30:45 IDT 2016
[INFO] Final Memory: 17M/307M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.tomcat.maven:tomcat7-maven-plugin:2.2:run-war (default-cli) on project tomcat-example: Could not start Tomcat: Failed to start component [StandardServer[-1]]: Failed to start component [StandardService[Tomcat]]: Failed to start component [StandardEngine[Tomcat]]: Failed to start component [Realm[MemoryRealm]]: Memory database file /Users/shikloshi/java_workspace/webapp-examples/tomcat-example/target/tomcat/conf/tomcat-users.xml cannot be read -> [Help 1]

这是错误:

Tomcat: Failed to start component [StandardServer[-1]]: Failed to start component [StandardService[Tomcat]]: Failed to start component [StandardEngine[Tomcat]]: Failed to start component [Realm[MemoryRealm]]: Memory database file /Users/shikloshi/java_workspace/webapp-examples/tomcat-example/target/tomcat/conf/tomcat-users.xml cannot be read -> [Help 1]

谁负责在我的目标目录中编写tomcat配置,为什么不写?

3 个答案:

答案 0 :(得分:8)

执行mvn clean以清理目标目录。

然后再试一次,tomcat-maven-plugin将重新创建tomcat文件夹(包括文件tomcat-users.xml)。

答案 1 :(得分:1)

只需从应用程序中删除目标文件夹,然后再次运行您的应用。它对我有用。

答案 2 :(得分:-1)

您可以尝试在以下位置为tomcat用户创建文件:

/Users/shikloshi/java_workspace/webapp-examples/tomcat-example/target/tomcat/conf/

然后将其添加到其中:

<?xml version="1.0" encoding="UTF-8"?>
<tomcat-users>
 <role rolename="tomcat"/>
 <role rolename="admin"/>
 <role rolename="manager"/>
 <user  username="admin" password="admin" roles="tomcat,admin,manager"/>
</tomcat-users>