Goal is simple. adding a MANNIFEST file into final jar archive.
For this I read many documentation but i miss the right information. Finally I come to you to get some help, thanks in advance.
What I do ?
cmake_minimum_required(VERSION 2.8)
find_package(Java REQUIRED)
include(UseJava)
enable_testing()
project(DAI)
set( cwd "${CMAKE_CURRENT_SOURCE_DIR}" )
set( AIName "SkirmishDAI" )
set( SRC_DIR "${cwd}/src" )
set( LIB_DIR "${cwd}/libs" )
set( MAJOR_VERSION 0 )
set( MINOR_VERSION 1 )
set( PATCH_VERSION 0 )
set( VERSION "${MAJOR_VERSION}.${MINOR_VERSION}.${PATCH_VERSION}" )
set( CMAKE_JAVA_INCLUDE_PATH "${LIB_DIR}" )
set( CMAKE_JAVA_COMPILE_FLAGS "-source" "1.7" "-target" "1.7" )
set( DAI_JAR_NAME "${AIName}-${VERSION}.jar" )
set( DAI_JAR_FILE "${CMAKE_JAVA_TARGET_OUTPUT_DIR}/${DAI_JAR_NAME}" )
set( DAI_MANIFEST "${CMAKE_CURRENT_BINARY_DIR}/META-INF/MANIFEST.MF" )
configure_file("manifest.extras.in" "${DAI_MANIFEST}" @ONLY )
FILE( GLOB_RECURSE JAVA_SRC_FILES "${SRC_DIR}/main/java/*.java" )
FILE( GLOB_RECURSE JAVA_TEST_FILES "${SRC_DIR}/test/java/*.java" )
add_jar( ${AIName} ${JAVA_SRC_FILES} ${JAVA_TEST_FILES} VERSION ${VERSION} MANIFEST ${DAI_MANIFEST} )
This will add into the jar file a manifest … but a wrong place.
That mean, when manifest go to ${CMAKE_CURRENT_BINARY_DIR}/META-INF/MANIFEST.MF, I will get the same full path in the jar file intead of META-INF/MANIFEST.MF
jarfile
/
/com/cool/app/Main.class
/mypath/to/bin/dir/META-INF/MANIFEST.MF
while I expect to get
jarfile
/
/com/cool/app/Main.class
/META-INF/MANIFEST.MF
UPDATE: Make run following command:
$ make VERBOSE=1
…
[ 31%] Creating Java archive SkirmishDAI-0.1.0.jar
cd /mnt/data/projects/spring/build/AI/Skirmish/DAI/CMakeFiles/SkirmishDAI.dir && /usr/lib/jvm/java-1.7.0-openjdk-1.7.0.65-2.5.2.5.fc20.x86_64/bin/jar -cf /mnt/data/projects/spring/build/AI/Skirmish/DAI/SkirmishDAI-0.1.0.jar /mnt/data/projects/spring/build/AI/Skirmish/DAI/META-INF/MANIFEST.MF @java_class_filelist
cd /mnt/data/projects/spring/build/AI/Skirmish/DAI/CMakeFiles/SkirmishDAI.dir && /usr/bin/cmake -D_JAVA_TARGET_DIR=/mnt/data/projects/spring/build/AI/Skirmish/DAI -D_JAVA_TARGET_OUTPUT_NAME=SkirmishDAI-0.1.0.jar -D_JAVA_TARGET_OUTPUT_LINK=SkirmishDAI.jar -P /usr/share/cmake/Modules/UseJavaSymlinks.cmake.
…
解决方案
The problem likely stems from a duplicated path in the following lines:
set( DAI_MANIFEST "${CMAKE_CURRENT_BINARY_DIR}/META-INF/MANIFEST.MF" )
configure_file("manifest.extras.in" "${CMAKE_CURRENT_BINARY_DIR}/${DAI_MANIFEST}" @ONLY )
You probably meant:
set( DAI_MANIFEST "${CMAKE_CURRENT_BINARY_DIR}/META-INF/MANIFEST.MF" )
configure_file("manifest.extras.in" "${DAI_MANIFEST}" @ONLY )