Spring Boot Hello World Example – Mustache

A Spring Boot web application example, using embedded Tomcat + Mustache template engine, and package as an executable JAR file. Technologies used : Spring Boot 1.5.2.RELEASE Spring 4.3.7.RELEASE jmustache 1.13 Thymeleaf 2.1.5.RELEASE Tomcat Embed 8.5.11 Maven 3 Java 8 Note Spring Boot uses jmustache to integrate Mustache as template engine. 1. Project Directory 2. Project …

Read more

Spring Boot – Configure maxSwallowSize in embedded Tomcat

In Spring Boot, you can’t configure the embedded Tomcat maxSwallowSize via the common application properties, there is no option like server.tomcat.*.maxSwallowSize Solution To fix it, you need to declare a TomcatEmbeddedServletContainerFactory bean and configure the maxSwallowSize like this : //… import org.apache.coyote.http11.AbstractHttp11Protocol; import org.springframework.boot.context.embedded.tomcat.TomcatConnectorCustomizer; import org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainerFactory; private int maxUploadSizeInMb = 10 * 1024 * 1024; …

Read more

Spring file upload and connection reset issue

A Spring servlet initializer to configure the file upload limit, 5mb per file and 10mb per request. MyWebInitializer.java public class MyWebInitializer extends AbstractAnnotationConfigDispatcherServletInitializer { private int maxUploadSizeInMb = 5 * 1024 * 1024; // 5 MB //… @Override protected void customizeRegistration(ServletRegistration.Dynamic registration) { // upload temp file will put here File uploadDirectory = new File(System.getProperty("java.io.tmpdir")); …

Read more

Spring Boot – Deploy WAR file to Tomcat

In this article, we will show you how to create a Spring Boot traditional WAR file and deploy to a Tomcat servlet container. In Spring Boot, to create a WAR for deployment, we need 3 steps: Extends SpringBootServletInitializer Marked the embedded servlet container as provided. Update packaging to war Tested with Spring Boot 2.1.2.RELEASE Tomcat …

Read more

How to change the default port in Spring Boot

Default, Spring Boot web application starts embedded web server (Tomcat, Jetty, etc.) in port 8080. And we can configure or change the port using the server.port property. Table of contents 1. application.properties 2. application.yml 3. Command Line 4. Environment Variable 5. WebServerFactoryCustomizer 6. Download Source Code 7. References P.S Tested with Spring Boot 1, 2, …

Read more

Spring Boot Hello World Example – JSP

A Spring Boot web application example, using embedded Tomcat + JSP template, and package as an executable WAR file. Technologies used : Spring Boot 1.4.2.RELEASE Spring 4.3.4.RELEASE Tomcat Embed 8.5.6 Maven 3 Java 8 1. Project Directory Create the following folders manually : 2. Project Dependencies Maven example. Read comments for self-explanatory. pom.xml <?xml version="1.0" …

Read more

Tomcat 7 + Java 8 : Invalid byte tag in constant pool: 15

Just upgraded to Java 8, and the Tomcat 7 keeps prompting the following exceptions: Jul 20, 2015 4:06:36 PM org.apache.catalina.startup.ContextConfig processAnnotationsJar SEVERE: Unable to process Jar entry [jdk/nashorn/internal/objects/NativeURIError.class] from Jar [jar:file:/Library/Java/JavaVirtualMachines/jdk1.8.0_45.jdk/Contents/Home/jre/lib/ext/nashorn.jar!/] for annotations org.apache.tomcat.util.bcel.classfile.ClassFormatException: Invalid byte tag in constant pool: 15 at org.apache.tomcat.util.bcel.classfile.Constant.readConstant(Constant.java:131) at org.apache.tomcat.util.bcel.classfile.ConstantPool.<init>(ConstantPool.java:60) at org.apache.tomcat.util.bcel.classfile.ClassParser.readConstantPool(ClassParser.java:209) at org.apache.tomcat.util.bcel.classfile.ClassParser.parse(ClassParser.java:119) at org.apache.catalina.startup.ContextConfig.processAnnotationsStream(ContextConfig.java:2066) at org.apache.catalina.startup.ContextConfig.processAnnotationsJar(ContextConfig.java:1942) at org.apache.catalina.startup.ContextConfig.processAnnotationsUrl(ContextConfig.java:1908) …

Read more

Where is Eclipse deploy web application – Tomcat

By default Eclipse deploys web application to a internal plugin folder called wtpwebapps, which is located in the following directory : {Your_Workspace}/.metadata/.plugins/org.eclipse.wst.server.core/tmp{number}/wtpwebapps #Example 1 – Windows C:\Users\mkyong\workspace\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\wtpwebapps #Example 2 – Mac OSX /Users/mkyong/Documents/workspace/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps How it works In Server view, double clicks on the “Tomcat Server”, the deployment work is defined in the Server Locations To …

Read more

Nginx + Apache Tomcat configuration example

This tutorial shows you how to configure Nginx as a reverse proxy to redirect the traffics from port 80 to Apache Tomcat on port 8080. Here is the environment in my Linode server : Debian 7.5 Nginx 1.2.1 Tomcat 7.0.28 P.S Both Nginx and Tomcat are installed via apt-get install. 1. Tomcat Configuration Edit server.xml, …

Read more

How to change Tomcat manager default path ?

By default, Tomcat’s manager webapp is able to access via yourapp:8080/manager. It is a good practice to change the default /manager to something else, to avoid potential brute force attack. Environment Tomcat 7 (apt-get install) Debian 7.5 1. Solution This article show you how to change / rename the default manager webapp path from “/manager” …

Read more

How to change Tomcat to use JDK 7

The current environment is using Tomcat 7 + JDK 6. How to configure Tomcat to use JDK 7? Environment Tomcat 7 (apt-get install) Debian 7.5 JDK 6 and JDK 7 P.S Tomcat 7 is installed via apt-get Note You may interest at this tutorial – Apache Tomcat 8 + JDK 8 on Debian 1. Solution …

Read more

jConsole – JMX remote access on Tomcat

In this tutorial, we will show you how to use jConsole to remote access a Tomcat instance, for JVM monitoring stuff. Tools and environment used : Ubuntu 13 + Tomcat 7 + 192.168.1.142 Windows 8 + jConsole + 192.168.1.200 1. Tomcat + JMX To connect with jConsole, Tomcat need to enable the JMX options. To …

Read more

Eclipse + Tomcat – java.lang.OutOfMemoryError: Java heap space

In Eclipse IDE, run a Java web application with Tomcat server plugin, but the console prompts Exception in thread "x" java.lang.OutOfMemoryError: Java heap space 1. Solution – Increase Heap Size in Tomcat By default, Tomcat allocated a small amount of heap size. To solve it, you need to increase the Tomcat’s heap size manually. 1.1 …

Read more

Eclipse IDE – Tomcat version 6.0 only supports J2EE 1.2, 1.3, 1.4, and Java EE 5 Web modules

Problem Import a Java web project in Eclipse, build with Maven, once create a Tomcat server instance, unable to add the Java web project, and showing Tomcat version 6.0 only supports J2EE 1.2, 1.3, 1.4, and Java EE 5 Web modules Tools used : Eclipse Juno 4.2 Tomcat 6.0.35 JDK 1.6 Solution In project, “.settings” …

Read more

How to deploy Maven based war file to Tomcat

In this tutorial, we will show you how to use Maven-Tomcat plugin to package and deploy a WAR file to Tomcat, both in Tomcat 6 and 7. Libraries used : Maven 3 Tomcat 6.0.37 Tomcat 7.0.53 Tomcat 7 Deploy URL = http://localhost:8080/manager/text Command = mvn tomcat7:deploy Tomcat 6 Deploy URL = http://localhost:8080/manager/ Command = mvn …

Read more

Container Authentication with JAX-WS – (Tomcat version)

In this article, we show you how to implement container authentication with JAX-WS, under Tomcat 6.0. In this way, the authentication is declarative rather than programmatic like this – application authentication in JAX-WS. And Tomcat implement the container authentication via security realm. At the end of this article, the deployed web service will authenticate user …

Read more

Tomcat : java.io.IOException: Keystore was tampered with, or password was incorrect

Problem Configured Tomcat’s SSL, while starting Tomcat server, it hits following exception : 14 Disember 2010 4:18:31 PM org.apache.tomcat.util.net.jsse.JSSESocketFactory getStore SEVERE: Failed to load keystore type JKS with path c:\keystore due to Keystore was tampered with, or password was incorrect java.io.IOException: Keystore was tampered with, or password was incorrect at sun.security.provider.JavaKeyStore.engineLoad(JavaKeyStore.java:771) at sun.security.provider.JavaKeyStore$JKS.engineLoad(JavaKeyStore.java:38) at java.security.KeyStore.load(KeyStore.java:1185) …

Read more

How to configure Tomcat to support SSL or https

A guide to show you how to configure Tomcat 6.0 to support SSL or https connection. 1. Generate Keystore First, uses “keytool” command to create a self-signed certificate. During the keystore creation process, you need to assign a password and fill in the certificate’s detail. $Tomcat\bin>keytool -genkey -alias mkyong -keyalg RSA -keystore c:\mkyongkeystore Enter keystore …

Read more

How to configure MySQL DataSource in Tomcat 6

Here’s a guide to show you how to configure MySQL datasource in Tomcat 6. 1. Get MySQL JDBC Driver Get JDBC driver here – http://www.mysql.com/products/connector/ , for example, mysql-connector-java-5.1.9.jar, and copy it to $TOMCAT\lib folder. 2. Create META-INF/context.xml Add a file META-INF/context.xml into the root of your web application folder, which defines database connection detail …

Read more

Deploy JAX-WS web services on Tomcat

Here’s a guide to show you how to deploy JAX-WS web services on Tomcat servlet container. See following summary steps of a web service deployment. Create a web service (of course). Create a sun-jaxws.xml, defines web service implementation class. Create a standard web.xml, defines WSServletContextListener, WSServlet and structure of a web project. Build tool to …

Read more

JSF 2.0 + Tomcat : It appears the JSP version of the container is older than 2.1…

Problem While deploying JSF 2.0 web application to Tomcat 6.0.26, hits the “JSP version of the container is older than 2.1” exception and failed to start the Tomcat server. But the JSP api v2.1 is included in the project class path, why the Tomcat is still saying that JSP version is older than 2.1? <dependency> …

Read more

Tomcat deploy Maven project web.xml to a wrong folder in Eclipse

Problem During the Eclipse debugging session, the “web.xml” will always deploy to a wrong folder. It’s always cause by manual migrated or converted a Java web project to Maven’s project. See the Eclipse’s workspace folder structure, Tomcat in Eclipse is deploy “web.xml” to a wrong folder, and causing the entire web application fail to run. …

Read more

Tomcat Error – prunsrv.c Failed creating java (jvm.dll)

I had encountered following error message while starting my Tomcat server. [2009-01-16 11:22:19] [1343 prunsrv.c] [debug] Procrun log initialized [2009-01-16 11:22:19] [info] Procrun (2.0.4.0) started [2009-01-16 11:22:19] [info] Running Service… [2009-01-16 11:22:19] [1166 prunsrv.c] [debug] Inside ServiceMain… [2009-01-16 11:22:19] [info] Starting service… … [error] The specified module could not be found. [2009-01-16 11:22:19] [994 prunsrv.c] …

Read more

How to get the Tomcat home directory in Java

Q : Is there a function in Java to retrieve the Tomcat (Catalina) home directory? A : Yes, Tomcat home directory or Catalina directory is stored at the Java System Property environment. If the Java web application is deployed into Tomcat web server, we can get the Tomcat directory with the following command System.getProperty("catalina.base");

How to change Tomcat default port ?

Tomcat by default runs on port number 8080, However there is high chance get a port conflict with others program. Sometime we just need to change the Tomcat port number. Steps of changing the Tomcat Port 1) Locate server.xml in {Tomcat installation folder}\ conf \ 2) Find following similar statement <!– Define a non-SSL HTTP/1.1 …

Read more

Tomcat – java.lang.OutOfMemoryError: PermGen space

Often time, Tomcat may hits the following java.lang.OutOfMemoryError: PermGen space error. java.lang.OutOfMemoryError: PermGen space at java.lang.ClassLoader.defineClass1(Native Method) at java.lang.ClassLoader.defineClass(ClassLoader.java:620) at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:124) It’s usually happened after the Tomcat restarts a few times. 1. Solution By default, Tomcat is assigned a very little PermGen memory for the running process. To fix it, increase the PermGen memory settings …

Read more

How to install Tomcat on Ubuntu

This tutorial shows you how to install Tomcat on Ubuntu, with help of the buith-in apt-get command. 1. apt-get install 1.1 Find an available Tomcat package to install $ sudo apt-cache search tomcat //… tomcat7 – Servlet and JSP engine tomcat7-admin – Servlet and JSP engine — admin web applications tomcat7-common – Servlet and JSP …

Read more

Tomcat – java.security.AccessControlException: access denied (java.lang.RuntimePermission accessDeclaredMembers)

Problem As i said in previously post, Tomcat 5.5.25 made a lot of modification in policy file, which may enhance security on web application but it also causing a lot of problem, see another error message : SEVERE: Context initialization failed java.security.AccessControlException: access denied (java.lang.RuntimePermission accessDeclaredMembers) at java.security.AccessControlContext.checkPermission(AccessControlContext.java:323) Solution Policy file issue, vi 04webapps.policy, this …

Read more

How to check Tomcat version Installed

To find out the Tomcat version, find this file – version.sh for *nix or version.bat for Windows. This version.sh file is normally located in the Tomcat bin folder. For example : mkyong@hcompass:/usr/share/tomcat7/bin$ ./version.sh Using CATALINA_BASE: /usr/share/tomcat7 Using CATALINA_HOME: /usr/share/tomcat7 Using CATALINA_TMPDIR: /usr/share/tomcat7/temp Using JRE_HOME: /usr Using CLASSPATH: /usr/share/tomcat7/bin/bootstrap.jar:/usr/share/tomcat7/bin/tomcat-juli.jar Server version: Apache Tomcat/7.0.28 Server built: Apr …

Read more

Tomcat – java.security.AccessControlException: access denied (logging.properties read)

Problem After upgraded to Tomcat version 5.5.25, it starting to hit a lot of errors in security policy : Caused by: java.security.AccessControlException: access denied (java.io.FilePermission /usr/share/tomcat5.5- webapps/jsp-examples/WEB-INF/classes/logging.properties read) Solution Above error is caused by the Tomcat’s policy file, Tomcat 5.5.25 made a lot of modification on policy file. To fix it, you need to make …

Read more

What is Tomcat default administrator password ?

Is there or what is the default administrator user and password for Tomcat? Tested : Tomcat 8.0.30 Tomcat 7.0.67 Tomcat 6.0.44 Article update history Updated 03/02/2016 : Add support for Tomcat 7 and 8. Updated 08/04/2011 : Update article. 1. Tomcat 7 and Tomcat 8 Tomcat users are defined in the file – $TOMCAT_HOME/conf/tomcat-users.xml, by …

Read more