Java 无法在Eclipse中通过Maven启动tomcat
在Eclipse中,通过运行web应用程序时,我遇到以下异常。在eclipse中,我右键单击项目,运行方式->运行配置..->目标-tomcat7:跑步 不确定为什么我不能运行我的web应用程序。谷歌搜索并尝试了许多选项,但无法纠正。这个问题的解决办法是什么 在tomcat配置中,我添加了以下内容Java 无法在Eclipse中通过Maven启动tomcat,java,eclipse,maven,tomcat,web-applications,Java,Eclipse,Maven,Tomcat,Web Applications,在Eclipse中,通过运行web应用程序时,我遇到以下异常。在eclipse中,我右键单击项目,运行方式->运行配置..->目标-tomcat7:跑步 不确定为什么我不能运行我的web应用程序。谷歌搜索并尝试了许多选项,但无法纠正。这个问题的解决办法是什么 在tomcat配置中,我添加了以下内容 <role rolename="manager"/> <role rolename="manager-gui"/> <role rolename="admin"/&g
<role rolename="manager"/>
<role rolename="manager-gui"/>
<role rolename="admin"/>
<user username="admin" password="admin" roles="admin,manager,manager-gui"/>
这是我的POM.xml
<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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.expense</groupId>
<artifactId>ExpenseProject</artifactId>
<packaging>war</packaging>
<version>0.0.1-SNAPSHOT</version>
<name>Expense Project</name>
<url>http://maven.apache.org</url>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<version>2.2</version>
<configuration>
<mode>war</mode>
<url>http://localhost:8080/manager/html</url>
<server>TomcatServer</server>
<path>/ExpenseProject</path>
</configuration>
</plugin>
<!-- Maven Tomcat Plugin <plugin> <groupId>org.codehaus.mojo</groupId>
<artifactId>tomcat-maven-plugin</artifactId> <configuration> <url>http://localhost:8080/manager/html</url>
<server>Apache_Tomcat_7_x86</server> <username>admin</username> <password>password</password>
<path>/HelloWorld</path> </configuration> </plugin> -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.3</version>
<configuration>
<packagingExcludes>WEB-INF/web.xml</packagingExcludes>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>3.2.0.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>3.2.0.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>3.2.0.RELEASE</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.1.0</version>
</dependency>
</dependencies>
</project>
4.0.0
网络费用
这是我的web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
id="WebApp_ID" version="3.0">
<display-name>My House Expense</display-name>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
<welcome-file>default.html</welcome-file>
<welcome-file>default.htm</welcome-file>
<welcome-file>default.jsp</welcome-file>
</welcome-file-list>
<servlet>
<servlet-name>HelloWeb</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>HelloWeb</servlet-name>
<url-pattern>*.do</url-pattern>
</servlet-mapping>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/HelloWeb-servlet.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
</web-app>
我的房费
index.html
index.htm
index.jsp
default.html
default.htm
default.jsp
你好
org.springframework.web.servlet.DispatcherServlet
你好
*.做
上下文配置位置
/WEB-INF/HelloWeb-servlet.xml
org.springframework.web.context.ContextLoaderListener
您不应在应用程序中明确包含以下依赖项:
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.1.0</version>
</dependency>
javax.servlet
,解释了所有不同的Maven依赖范围。那么,Maven不能编译您的项目了?在运行tomcat之前。尝试编译itI在运行它之前编译过。它被成功编译。类强制转换异常发生…它对我来说很有效,但我只是好奇作用域到底是做什么的?我添加了一个链接到关于作用域的原始答案,它很短,值得一读。
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
id="WebApp_ID" version="3.0">
<display-name>My House Expense</display-name>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
<welcome-file>default.html</welcome-file>
<welcome-file>default.htm</welcome-file>
<welcome-file>default.jsp</welcome-file>
</welcome-file-list>
<servlet>
<servlet-name>HelloWeb</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>HelloWeb</servlet-name>
<url-pattern>*.do</url-pattern>
</servlet-mapping>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/HelloWeb-servlet.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
</web-app>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.1.0</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.1.0</version>
<scope>provided</scope>
</dependency>