Troubleshooting: Maven – Strings in switch are not supported in source 1.5

In this tutorial we will show you how to deal with issues concerning the JDK version of a Maven based Java project. Apache Maven uses by default the JDK-1.5 version. A common problem is to use features supported by later versions.

In this example, we use the following tools on a Windows 7 platform:

  • Apache Maven 3.1.1
  • Maven Source Plugin
  • JDK 1.7

Usually, the JDK version is not specified inside the pom.xml file and thus, Maven uses the default, 1.5 version. However, this version is rather old and does not support new features. For example:


As we can observe from the reported error, a switch statement cannot support a Java String in JDK-1.5. Thus, since our project requires the usage of a switch statement over a String, we must use the latest JDK version. In order to achieve that, we make use of Maven’s Compiler Plugin.

In order to explicitly define our project to be compiled, using the JDK-1.7 version, we add the following snippet to our pom.xml file:


Now, if we rebuild our project, the error will not show up.

This was a tutorial on how to resolve issues regarding the JDK version of a project, using Maven’s Compiler Plugin.

Sotirios-Efstathios Maneas

Sotirios-Efstathios (Stathis) Maneas is a PhD student at the Department of Computer Science at the University of Toronto. His main interests include distributed systems, storage systems, file systems, and operating systems.
Notify of

This site uses Akismet to reduce spam. Learn how your comment data is processed.

1 Comment
Newest Most Voted
Inline Feedbacks
View all comments
3 years ago

where, exactly?

Back to top button