Reputation: 15673
Here the code:
package de.swt1321.servlet;
import java.io.OutputStream;
import javax.servlet.http.annotation.Servlet;
import javax.servlet.http.annotation.GET;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
@Servlet(urlMappings={"/ServletTest"})
public class ServletTest {
private static final java.nio.charset.Charset UTF8 = java.nio.charset.Charset.forName("UTF8");
@GET
public void handleGet(HttpServletRequest req,
HttpServletResponse res)
{
byte[] HTML = "<html><head><title>Hello World!</title></head><body><h1>IT WORKED!</h1></body></html>".getBytes(UTF8);
res.setStatus(HttpServletResponse.SC_OK);
res.setHeader("content-type","text/html;charset=utf8");
res.setIntHeader("content-length",HTML.length);
OutputStream os = res.getOutputStream();
os.write(HTML);
os.flush();
}
}
I'd expect this to work according to this
, unfortunately I've so far been unable to find a jar that contains the javax.servlet.http.annotation
package. I looked in "javax:javaee-api:jar:6.0" from http://download.java.net/maven/2 as well as in the servlet-api-3.0.jar
shipped with Jetty 9, but so far without luck. I'm kind of out of ideas here, what am I missing?
So far I'm building/attempting to build with this Buildr buildfile:
# Version number for this release
VERSION_NUMBER = "1.0.0"
# Group identifier for your projects
GROUP = "swt1321"
COPYRIGHT = ""
# Specify Maven 2.0 remote repositories here, like this:
repositories.remote << "http://repo1.maven.org/maven2"
# This really bugs me, this isn't only supposed to build on my own PC after all!
# But as I said, the one at the download.java.net repo didn't work
JAVA_EE_PATH = "/home/hannes/Lib/Java/jetty-distribution-9.0.0.M3/lib/servlet-api-3.0.jar"
java_ee = artifact("de.swt1321:java_ee:jar:1.0").from(file JAVA_EE_PATH)
project_layout = Layout.new
project_layout[:source,:main,:java] = 'src'
project_layout[:source,:test,:java] = 'test'
desc "The Servlettest project"
define "ServletTest", :layout => project_layout do
project.version = VERSION_NUMBER
project.group = GROUP
manifest["Implementation-Vendor"] = COPYRIGHT
compile.with java_ee
package :war
end
Upvotes: 0
Views: 812
Reputation: 9954
I'd suggest to give a glance to a more updated example of the web servlet api
Nonetheless, if you are still looking for the libraries used by the 2008 example, I'd suggest you these ones according to Jarvana
Maven:
<dependency>
<groupId>org.mortbay.jetty</groupId>
<artifactId>servlet-annotation-spec</artifactId>
<version>3.0.pre0</version>
</dependency>
BONUS: your GET annotation seems to belong to another package
Upvotes: 0
Reputation: 1057
this package is the sub package of servlet-api.jar and you can find this jar file in the container's lib folder. For tomcat it is [tomcat installation directory]->lib->servlet-api.jar
Upvotes: 3