I have a tree that looks like this:
In the java folder, I have a package, com.example.project
which has a Main
class and an Application
class that subclasses ResourceConfig
@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);
}
}
In development, I run the Main
class and start a Grizzly server:
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();
}
}
Everything works fine with the Grizzly server. I'm now trying to deploy to tomcat.
I use mvn package
to create a war file. In my pom file, I have:
<build>
...
<plugins>
...
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.4</version>
<configuration>
<failOnMissingWebXml>false</failOnMissingWebXml>
</configuration>
</plugin>
I put the war file in the webapps directory under a tomcat instance and it gets exploded there. My static content is served.
The layout of the directory that comes from the WAR file looks like this:
[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
...
I can not locate any of my REST services. Everything I try is 404.
Directory in tomcat webapps is project
, javax.ws.rs.ApplicationPath
is api
, @Path
is service
. So, I would hope to get a response from /project/api/service
, for instance. But, after trying many combinations, everything is 404.