How to install and use CDI on Tomcat?

Tomcat as being a barebones JSP/Servlet container doesn’t support CDI out the box. How exactly did you install CDI? Did you really drop jakartaee-api.jar or javaee-api.jar in /WEB-INF/lib just to get your code to compile? Oh please no, this is not the right way. The JEE API JAR contains solely the API classes, not the … Read more

java.io.WriteAbortedException: writing aborted; java.io.NotSerializableException

Just implement Serializable If you’re getting a NotSerializableException like follows, java.io.NotSerializableException: bean.ProjectAreaBean then it simply means that the class as identified by the fully qualified name in the exception message (which is bean.ProjectAreaBean in your case) does not implement the Serializable interface while it is been expected by the code behind. Fixing it is relatively … Read more

To prevent a memory leak, the JDBC Driver has been forcibly unregistered

Since version 6.0.24, Tomcat ships with a memory leak detection feature, which in turn can lead to this kind of warning messages when there’s a JDBC 4.0 compatible driver in the webapp’s /WEB-INF/lib which auto-registers itself during webapp’s startup using the ServiceLoader API, but which did not auto-deregister itself during webapp’s shutdown. This message is … Read more

How to set the context path of a web application in Tomcat 7.0

What you can do is the following; Add a file called ROOT.xml in <catalina_home>/conf/Catalina/localhost/ This ROOT.xml will override the default settings for the root context of the tomcat installation for that engine and host (Catalina and localhost). Enter the following to the ROOT.xml file; <Context docBase=”<yourApp>” path=”” reloadable=”true” /> Here, <yourApp> is the name of, … Read more

How to get UTF-8 working in Java webapps?

Answering myself as the FAQ of this site encourages it. This works for me: Mostly characters äåö are not a problematic as the default character set used by browsers and tomcat/java for webapps is latin1 ie. ISO-8859-1 which “understands” those characters. To get UTF-8 working under Java+Tomcat+Linux/Windows+Mysql requires the following: Configuring Tomcat’s server.xml It’s necessary … Read more

How to properly install and configure JSF libraries via Maven?

When you’re facing a “weird” exception suggesting that classes/methods/files/components/tags are absent or different while they are seemingly explicitly included in the web application such as the ones below, java.lang.ClassFormatError: Absent Code attribute in method that is not native or abstract in class file javax/faces/webapp/FacesServlet java.util.MissingResourceException: Can’t find javax.faces.LogStrings bundle com.sun.faces.vendor.WebContainerInjectionProvider cannot be cast to com.sun.faces.spi.InjectionProvider … Read more

Simplest way to serve static data from outside the application server in a Java web application

I’ve seen some suggestions like having the image directory being a symbolic link pointing to a directory outside the web container, but will this approach work both on Windows and *nix environments? If you adhere the *nix filesystem path rules (i.e. you use exclusively forward slashes as in /path/to/files), then it will work on Windows … Read more

The infamous java.sql.SQLException: No suitable driver found

The infamous java.sql.SQLException: No suitable driver found This exception can have basically two causes: #1. JDBC driver is not loaded You need to ensure that the JDBC driver is placed in server’s own /lib folder. Or, when you’re actually not using a server-managed connection pool data source, but are manually fiddling around with DriverManager#getConnection() in … Read more

Recommended way to save uploaded files in a servlet application

Store it anywhere in an accessible location except of the IDE’s project folder aka the server’s deploy folder, for reasons mentioned in the answer to Uploaded image only available after refreshing the page: Changes in the IDE’s project folder does not immediately get reflected in the server’s work folder. There’s kind of a background job … Read more