I am trying to create instance of class javax.servlet.ServletException with following code
public class MyTroubleViewer {
public static void main(String[] args) {
javax.servlet.ServletException servletException = new javax.servlet.ServletException("Hello");
System.out.println(servletException.getMessage());
}
}
But I get exception on creating:
Exception in thread "main" java.lang.ClassFormatError: Absent Code attribute in method that is not native or abstract in class file javax/servlet/ServletException
...
Maven helps me with dependecies:
<dependency>
<groupId>javax</groupId>
<artifactId>javaee-api</artifactId>
<version>6.0</version>
<type>jar</type>
<scope>compile</scope>
</dependency>
What am I doing wrong?
As mentioned by @user353852, your current dependency contains only the Java EE 6 APIs and does not contain any method bodies. So you can’t run code against it. To run your code outside a container, you need to get a “concrete” dependency (from GlassFish repository):
Note that such dependencies shouldn’t be declared with a
compilescope, you don’t want to bundle it (it should beprovidedor maybetest, but notcompileorruntime).In theory, no. But in practice, I would recommend to use the implementation JARs from the server you are going to use (or from the Java EE Reference Implementation). Since you are using Java EE 6, this actually means JARS from GlassFish v3 in both cases .
For the Bean Validation API, you’ll need the following (Hibernate Validator being the RI):
Nothing official but this nice answer from BalusC will help.