[CMake] CMake and a simple java example

Kristian kristianonline28 at gmail.com
Mon Dec 7 16:52:39 EST 2015


Dear All,

I am learning CMake, and one of my personal lessons is combine Java
and CMake. I made a small example (HelloWorld.java):

==========

public class HelloWorld
{
   public static void main(String[] args)
   {
      System.out.println("Hey :)");
   }
}

==========

And a CMakeLists.txt file:

==========

cmake_minimum_required(VERSION 2.8)
project(HelloWorld)

find_package(Java REQUIRED)
include(UseJava)

set(JAR_NAME HelloWorld)
set(JAVA_SOURCE_DIRECTORY )
set(JAVA_SOURCE_FILES ${JAVA_SOURCE_DIRECTORY}/HelloWorld.java)
add_jar(${JAR_NAME} ${JAVA_SOURCE_FILES})

==========

Then I go into that directory where the CMakeLists.txt is and start the command

==========
cmake --target=HelloWorld --build .
==========

Output is:

==========

-- The C compiler identification is GNU 4.8.4
-- The CXX compiler identification is GNU 4.8.4
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Found Java: /usr/bin/java (found version "1.8.0.66")
-- Jar file /home/some/Downloads/HelloWorld/HelloWorld.jar
-- Class compiled to /home/some/Downloads/HelloWorld/CMakeFiles/HelloWorld.dir
-- Configuring done
-- Generating done
-- Build files have been written to: /home/some/Downloads/HelloWorld

==========

But when I start the command "make", then I get the following output:

==========

Scanning dependencies of target HelloWorld
make[2]: *** No rule to make target `/HelloWorld.java', needed by
`CMakeFiles/HelloWorld.dir/java_compiled_HelloWorld'.  Stop.
make[1]: *** [CMakeFiles/HelloWorld.dir/all] Error 2
make: *** [all] Error 2

==========

Can you tell me, what I am doing wrong?


More information about the CMake mailing list