我有一个非常简单的cmake java项目
(1)CMakeLists.txt:
cmake_minimum_required (VERSION 2.8)
find_package(Java)
include(UseJava)
enable_testing()
project (HelloWorld)
set(CMAKE_JAVA_COMPILE_FLAGS "-source" "1.8" "-target" "1.8")
set(CMAKE_JAVA_MANIFEST MANIFEST.MF)
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}")
(2) HelloWorld.Java
public class HelloWorld {
public static void main(String[] args) {
System.out.println("Hello, World!");
}
}
(3)MANIFEST.MF
Manifest-Version: 1.0
Extension-Name: My
Implementation-Version: 1.1
Main-Class: HelloWorld
(4)cmake。 && make
-- Jar file /root/mynet/mytest/build/useCmake/forJava/HelloWorld.jar
-- Class compiled to /root/mynet/mytest/build/useCmake/forJava/CMakeFiles/HelloWorld.dir
-- Configuring done
-- Generating done
-- Build files have been written to: /root/mynet/mytest/build/useCmake/forJava
/usr/bin/cmake -H/root/mynet/mytest/build/useCmake/forJava -B/root/mynet/mytest/build/useCmake/forJava --check-build-system CMakeFiles/Makefile.cmake 0
/usr/bin/cmake -E cmake_progress_start /root/mynet/mytest/build/useCmake/forJava/CMakeFiles /root/mynet/mytest/build/useCmake/forJava/CMakeFiles/progress.marks
make -f CMakeFiles/Makefile2 all
make[1]: Entering directory '/root/mynet/mytest/build/useCmake/forJava'
make -f CMakeFiles/HelloWorld.dir/build.make CMakeFiles/HelloWorld.dir/depend
make[2]: Entering directory '/root/mynet/mytest/build/useCmake/forJava'
cd /root/mynet/mytest/build/useCmake/forJava && /usr/bin/cmake -E cmake_depends "Unix Makefiles" /root/mynet/mytest/build/useCmake/forJava /root/mynet/mytest/build/useCmake/forJava /root/mynet/mytest/build/useCmake/forJava /root/mynet/mytest/build/useCmake/forJava /root/mynet/mytest/build/useCmake/forJava/CMakeFiles/HelloWorld.dir/DependInfo.cmake --color=
make[2]: Leaving directory '/root/mynet/mytest/build/useCmake/forJava'
make -f CMakeFiles/HelloWorld.dir/build.make CMakeFiles/HelloWorld.dir/build
make[2]: Entering directory '/root/mynet/mytest/build/useCmake/forJava'
make[2]: Nothing to be done for 'CMakeFiles/HelloWorld.dir/build'.
make[2]: Leaving directory '/root/mynet/mytest/build/useCmake/forJava'
[100%] Built target HelloWorld
make[1]: Leaving directory '/root/mynet/mytest/build/useCmake/forJava'
/usr/bin/cmake -E cmake_progress_start /root/mynet/mytest/build/useCmake/forJava/CMakeFiles 0
好的,事情看起来不错,但是
java -jar HelloWorld.jar
no main manifest attribute, in HelloWorld.jar
我在罐子里检查了META-INF / MANIFEST.MF,这不是我自己的清单:
jar tvf HelloWorld.jar
0 Tue Feb 19 03:56:08 GMT 2019 META-INF/
69 Tue Feb 19 03:56:08 GMT 2019 META-INF/MANIFEST.MF
427 Tue Feb 19 03:49:20 GMT 2019 HelloWorld.class
它只包含2行:
Manifest-Version: 1.0
Created-By: 1.8.0_191 (Oracle Corporation)
所以我的清单文件似乎没有生效。怎么解决?非常感谢
要为jar定义自定义清单,可以使用manifest命名参数设置它:
add_jar(example MANIFEST /path/to/manifest)
但请注意,我从未听说有人使用cmake来构建Java代码。
看看maven,ivy或gradle - 他们得到了积极的支持和发展。