Java: Determining the Java version used to compile a class, ‘class file has the wrong version’

If a Java class file is compiled with a higher supported version than is currently being run, you will get the ‘bad class file’, ‘class file has the wrong version XX.0, should be XX.0’ error message.

The good news is that this is a relatively simple issue to address.  For example, if the .class file was compiled as a Java 1.8 class file on a Jenkins continuous integration node, but the JRE on the desktop where you want to run it only has Java 1.7, then you will get this message when you attempt to run it.

Continue reading “Java: Determining the Java version used to compile a class, ‘class file has the wrong version’”

Java: Using Maven from the console for running classes, unit tests, checking dependencies

In this short article, I’ll provide some Maven commands that I’ve found helpful.

 

Run single class from src/main/java

mvn exec:java -Dexec.mainClass=this.is.MyClass -Dexec.args="myarg1 'my second arg' myarg3"

Run unit test from src/test/java, all methods decorated with @Test

mvn test -Dtest=this.is.MyTestClass

Run unit test from src/test/java, only methods decorated with @Test and that start with ‘testDatabase’

mvn test -Dtest=this.is.MyTestClass#testDatabase*

Continue reading “Java: Using Maven from the console for running classes, unit tests, checking dependencies”