maven启动tomcat访问报404(url中没有项目名)

时间:2022-06-14 16:36:02

[INFO] Running war on http://localhost:8080/js_001(红色部分是项目名,要是没有的话是不能访问项目资源的)

但是我仍然不知道为什么有些maven项目却有项目名。不知为什么?

但是通过观察日志输出:记住(clean tomcat7:run -X)带上后面的-X

[DEBUG]   (f) packaging = war
[DEBUG]   (f) path = /js_001
[DEBUG]   (f) pluginArtifacts = [org.apache.tomcat.maven:tomcat7-maven-plugin:maven-plugin:2.2:, org.apache.tomcat.embed:tomcat-embed-core:jar:7.0.47:compile, org.apache.tomcat:tomcat-util:jar:7.0.47:compile, org.apache.tomcat:tomcat-coyote:jar:7.0.47:compile, org.apache.tomcat:tomcat-api:jar:7.0.47:compile, org.apache.tomcat:tomcat-jdbc:jar:7.0.47:compile, org.apache.tomcat:tomcat-dbcp:jar:7.0.47:compile, org.apache.tomcat:tomcat-servlet-api:jar:7.0.47:compile, org.apache.tomcat:tomcat-jsp-api:jar:7.0.47:compile, org.apache.tomcat:tomcat-jasper:jar:7.0.47:compile, org.apache.tomcat:tomcat-jasper-el:jar:7.0.47:compile, org.apache.tomcat:tomcat-el-api:jar:7.0.47:compile, org.apache.tomcat:tomcat-catalina:jar:7.0.47:compile, org.apache.tomcat:tomcat-tribes:jar:7.0.47:compile, org.apache.tomcat:tomcat-catalina-ha:jar:7.0.47:compile, org.apache.tomcat:tomcat-annotations-api:jar:7.0.47:compile, org.apache.tomcat:tomcat-juli:jar:7.0.47:compile, org.apache.tomcat.embed:tomcat-embed-logging-juli:jar:7.0.47:compile, org.apache.tomcat.embed:tomcat-embed-logging-log4j:jar:7.0.47:compile, org.eclipse.jdt.core.compiler:ecj:jar:4.2.2:compile, org.apache.tomcat.maven:common-tomcat-maven-plugin:jar:2.2:compile, backport-util-concurrent:backport-util-concurrent:jar:3.1:compile, com.google.guava:guava:jar:10.0.1:compile, com.google.code.findbugs:jsr305:jar:1.3.9:compile, org.apache.httpcomponents:httpclient:jar:4.3.1:compile, org.apache.httpcomponents:httpcore:jar:4.3:compile, commons-logging:commons-logging:jar:1.1.3:compile, org.codehaus.plexus:plexus-component-annotations:jar:1.5.5:compile, commons-codec:commons-codec:jar:1.6:compile, org.apache.tomcat.maven:tomcat7-war-runner:jar:2.2:compile, commons-cli:commons-cli:jar:1.2:compile, org.apache.maven:maven-archiver:jar:2.4.2:compile, org.codehaus.plexus:plexus-interpolation:jar:1.13:compile, commons-io:commons-io:jar:2.2:compile, commons-lang:commons-lang:jar:2.6:compile, org.apache.commons:commons-compress:jar:1.4.1:compile, org.tukaani:xz:jar:1.0:compile, org.codehaus.plexus:plexus-archiver:jar:2.1.1:compile, junit:junit:jar:4.10:compile, org.hamcrest:hamcrest-core:jar:1.1:compile, org.codehaus.plexus:plexus-io:jar:2.0.3:compile, org.codehaus.plexus:plexus-utils:jar:3.0.15:compile, org.apache.maven.shared:maven-filtering:jar:1.0:compile, org.apache.maven.reporting:maven-reporting-api:jar:2.2.1:compile, org.apache.maven.doxia:doxia-sink-api:jar:1.1:compile, org.apache.maven.doxia:doxia-logging-api:jar:1.1:compile, org.codehaus.plexus:plexus-interactivity-api:jar:1.0-alpha-4:compile, org.sonatype.plexus:plexus-sec-dispatcher:jar:1.3:compile, org.sonatype.plexus:plexus-cipher:jar:1.4:compile, org.sonatype.plexus:plexus-build-api:jar:0.0.4:compile, org.slf4j:jcl-over-slf4j:jar:1.7.5:compile, org.slf4j:slf4j-api:jar:1.7.5:compile]
[DEBUG]   (f) port = 8080
[DEBUG]   (f) protocol = HTTP/1.1
[DEBUG]   (f) session = org.apache.maven.execution.MavenSession@1133ec6e
[DEBUG]   (f) skip = false
[DEBUG]   (f) staticContextPath = /
[DEBUG]   (f) uriEncoding = UTF-8
[DEBUG]   (f) useBodyEncodingForURI = false
[DEBUG]   (f) useNaming = true
[DEBUG]   (f) useSeparateTomcatClassLoader = false
[DEBUG]   (f) useTestClasspath = false
[DEBUG]   (f) warSourceDirectory = F:\workspace\java_workspace_01\js_001\src\main\webapp
[DEBUG]   (f) project = MavenProject: priv.lirenhe.js:js_001:0.0.1-SNAPSHOT @ F:\workspace\java_workspace_01\js_001\pom.xml
[DEBUG]   (f) settings = org.apache.maven.execution.SettingsAdapter@41aaedaa
[DEBUG] -- end configuration --
[INFO] Running war on http://localhost:8080/js_001
[INFO] Creating Tomcat server configuration at F:\workspace\java_workspace_01\js_001\target\tomcat
[INFO] create webapp with contextPath: /js_001

红色部分的path和contextPath原本都是没有的,后来我在pom.xml中tomcat配置如

maven启动tomcat访问报404(url中没有项目名)

就行了。