【发布时间】:2014-09-16 18:26:12
【问题描述】:
我有一棵看起来像这样的树:
在 java 文件夹中,我有一个包 com.example.project,它有一个 Main 类和一个子类 ResourceConfig 的 Application 类
@ApplicationPath("api")
public class Application extends ResourceConfig {
public Application() {
packages("com.example.project");
property(MustacheMvcFeature.TEMPLATE_BASE_PATH, "templates");
register(MustacheMvcFeature.class);
register(MyRequestFilter.class);
}
}
在开发中,我运行 Main 类并启动一个 Grizzly 服务器:
public class Main {
public static HttpServer startServer(String BASE_URI) {
final Application app = new Application();
return GrizzlyHttpServerFactory.createHttpServer(URI.create(BASE_URI), app);
}
public static void main(String[] args) throws IOException {
String BASE_URI = "http://localhost:8080/api";
final HttpServer server = startServer(BASE_URI);
server.getServerConfiguration().addHttpHandler(
new StaticHttpHandler("src/main/webapp"), "/");
System.out.println(String.format(
"Jersey app started with WADL available at "
+ "%s/application.wadl\nHit enter to stop it...", BASE_URI)
);
System.in.read();
}
}
Grizzly 服务器一切正常。我现在正在尝试部署到 tomcat。
我使用mvn package 创建一个war 文件。在我的 pom 文件中,我有:
<build>
...
<plugins>
...
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.4</version>
<configuration>
<failOnMissingWebXml>false</failOnMissingWebXml>
</configuration>
</plugin>
我将war文件放在tomcat实例下的webapps目录中,它在那里爆炸。我的静态内容已投放。
来自 WAR 文件的目录布局如下所示:
[vagrant@vagrant-centos6 project]$ tree .
.
├── index.html
| ... <webapp content>
├── META-INF
│ ├── MANIFEST.MF
│ └── maven
│ └── com.example.project
│ └── project
│ ├── pom.properties
│ └── pom.xml
└── WEB-INF
├── classes
│ ├── com
│ │ └── example
│ │ └── project
│ │ ├── Application.class
│ │ ├── Main.class
| | ...
│ ├── filter-dev.properties
│ ├── filter-test.properties
│ ├── hibernate.cfg.xml
│ └── templates
│ └── foo.mustache
└── lib
...
我找不到我的任何 REST 服务。我尝试的一切都是 404。
tomcat webapps中的目录是project,javax.ws.rs.ApplicationPath是api,@Path是service。因此,例如,我希望得到/project/api/service 的回复。但是,尝试了很多组合后,一切都是404。
【问题讨论】:
标签: java maven tomcat jersey jax-rs