cmake_minimum_required(VERSION 2.8) find_package(Java REQUIRED) include(UseJava) enable_testing() project(HelloWorldJava NONE) add_jar(HelloWorldJava HelloWorld/HelloWorldJava.java) get_target_property(_jarFile HelloWorldJava JAR_FILE) get_target_property(_classDir HelloWorldJava CLASSDIR) message(STATUS "Jar file ${_jarFile}") message(STATUS "Class compiled to ${_classDir}") add_test( NAME TestHelloWorldJava COMMAND ${Java_JAVA_EXECUTABLE} -cp ${_jarFile} HelloWorld/HelloWorldJava)