我試圖讓我的Tomcat服務器提供文件。我做了一個非常簡單的例子,告訴你什麼是錯的,即使它很簡單,它也不起作用。Tomcat未從maven-war-plugin提供文件
我的項目是由這樣的:
test
|->assets
| |->testB.txt
|->src
| |->main
| | |->webapp
| | | |->WEB-INF
| | | | |->web.xml
| | | |->testA.txt
|-> pom.xml
的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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>test</groupId>
<artifactId>test</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>war</packaging>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<build>
<plugins>
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>2.3</version>
<configuration>
<webResources>
<resource>
<directory>assets/</directory>
</resource>
</webResources>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat6-maven-plugin</artifactId>
<version>2.2</version>
<configuration>
<path>/</path>
</configuration>
</plugin>
</plugins>
</build>
</project>
的web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
</web-app>
如果我執行mvn package tomcat6:run
,我可以訪問testA.txt
但我無法訪問testB.txt
,就算了,當我有一個看一個的「的.war」產生的,我看到:
|->testA.txt
|->testB.txt
|->META-INF
|->WEB-INF
| |->web.xml
| |->classes
我想不通爲什麼我要一個訪問,但我能看不到其他的(404錯誤)...
感謝您的解釋。我沒有意識到這一點。現在它工作得很好。 – Utundu