尝试编译Java时,未知CMake命令“add_jar”

时间:2013-10-07 09:56:18

标签: java cmake

据我所知,cmake从版本2.8.6开始支持java。我找到了命令add_jar,但我似乎无法让它工作。我的CMakeLists.txt看起来像这样:

cmake_minimum_required(VERSION 2.8.10)
find_package(Java)

FILE(GLOB source
    "${CMAKE_CURRENT_SOURCE_DIR}/*.java"
)

add_jar(hello ${source})

当我运行cmake时,我得到了这个:

-- The C compiler identification is GNU 4.7.3
-- The CXX compiler identification is GNU 4.7.3
-- 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.7.0.25") 
CMake Error at CMakeLists.txt:8 (add_jar):
  Unknown CMake command "add_jar".


-- Configuring incomplete, errors occurred!

我在这里缺少什么?

1 个答案:

答案 0 :(得分:3)

您还必须包含UseJava模块。

find_package(Java)
include(UseJava)

add_jar(hello ${source})

find_package调用仅确定Java安装在磁盘上的位置,而UseJava模块提供使用Java的函数(如add_jar)。如文档所述,前者是加载后者的先决条件。