我从互联网上得到了一个非常简单的cmake java项目,如下所示:
public class HelloWorld {
public static void main(String[] args) {
System.out.println("Hello, World!");
}
}
然后CMakeLists.txt文件:
cmake_minimum_required (VERSION 2.8)
find_package(Java REQUIRED)
include(UseJava)
enable_testing()
project (HelloWorld)
set(CMAKE_JAVA_COMPILE_FLAGS "-source" "1.8" "-target" "1.8")
add_jar(HelloWorld HelloWorld.java)
get_target_property(_jarFile HelloWorld JAR_FILE)
get_target_property(_classDir HelloWorld CLASSDIR)
message(STATUS "Jar file ${_jarFile}")
message(STATUS "Class compiled to ${_classDir}")
add_test(NAME TestHelloWorld COMMAND ${Java_JAVA_EXECUTABLE} -cp ${_jarFile} HelloWorld)
cmake . && make -j8
有HelloWorld.jar文件,运行时出错:
java -jar HelloWorld.jar HelloWorld
no main manifest attribute, in HelloWorld.jar
是的,里面没有主类定义:
$ cat META-INF/MANIFEST.MF
Manifest-Version: 1.0
Created-By: 1.8.0_191 (Oracle Corporation)
我只想知道如何使用cmake将内容添加到MANIFEST.MF中,您能帮我解释一下吗?