CMake:使用多个jar依赖项生成jar文件(源代码构建之外)

时间:2016-04-25 19:41:42

标签: java cmake

我花了几天时间用CMake(3.5.2)做了以下事情。使用out of source构建,创建依赖于多个外部jar依赖项的jar文件。在我的清单中,我只想指定Main-Class,没有别的。

这就是我在 croco / owl2gdb / CMakeLists.txt 目录中的内容:

  

cmake_minimum_required(VERSION 3.5)

     

find_package(Java REQUIRED)

     

包括(UseJava)

     

项目(owl2gdb)

     

SET(CLASSPATH $ {CMAKE_CURRENT_SOURCE_DIR} /lib/commons-lang3-3.3.2.jar:$ {CMAKE_CURRENT_SOURCE_DIR} /lib/concurrentlinkedhashmap-lru-1.4.2.jar:$ {CMAKE_CURRENT_SOURCE_DIR} /lib/HermiT.jar )

     

列表(APPEND CMAKE_JAVA_INCLUDE_PATH $ {CLASSPATH})

     

SET(SOURCE    $ {} CMAKE_CURRENT_SOURCE_DIR /src/owl2gdb/OWL2GDB.java    $ {} CMAKE_CURRENT_SOURCE_DIR /src/graphdatabase/GraphDatabase.java    $ {} CMAKE_CURRENT_SOURCE_DIR /src/cpp/CPPFileWriter.java    $ {} CMAKE_CURRENT_SOURCE_DIR /src/cpp/CppHeaderFileWriter.java    $ {} CMAKE_CURRENT_SOURCE_DIR /src/cpp/CppSourceFileWriter.java    $ {} CMAKE_CURRENT_SOURCE_DIR /src/cpp/CppTextTemplate.java    $ {} CMAKE_CURRENT_SOURCE_DIR /src/cpp/GraphDatabaseHeaderWriter.java    $ {} CMAKE_CURRENT_SOURCE_DIR /src/cpp/GraphDatabaseSourceWriter.java    $ {} CMAKE_CURRENT_SOURCE_DIR /src/knowledge/MyOntology.java    $ {} CMAKE_CURRENT_SOURCE_DIR /src/knowledge/MyOWLClass.java    $ {} CMAKE_CURRENT_SOURCE_DIR /src/knowledge/MyOWLDataProperty.java    $ {} CMAKE_CURRENT_SOURCE_DIR /src/knowledge/MyOWLObjectProperty.java    $ {} CMAKE_CURRENT_SOURCE_DIR /src/knowledge/MyOWLOntology.java    $ {CMAKE_CURRENT_SOURCE_DIR} /src/tool/Util.java)

     

set(JAVA_JAR_ENTRY_POINT owl2gdb / OWL2GDB)

     

add_jar(owl2gdb $ {SOURCE})

add_custom_command(TARGET owl2gdb
    POST_BUILD
    COMMAND jar u0fm owl2gdb.jar ${CMAKE_CURRENT_SOURCE_DIR}/META-INF/MANIFEST.MF ${SOURCE}
)

在我的根目录中,我这样做:

  

mkdir _build

     

cd _build

     

cmake ..

     

确实在 _build / owl2gdb / owl2gdb.jar 中生成了

owl2gdb.jar 。然后

  

cd owl2gdb

     

java -jar owl2gdb.jar

给了我

  

线程中的异常" main" java.lang.NoClassDefFoundError:com / martiansoftware / jsap / StringParser

基本上,外部jar不包含在我的 owl2gdb.jar 中。我真的不知道从哪里开始。 cmake没有正确使用CMAKE_JAVA_INCLUDE_PATH有问题吗?我的CMakeLists.txt中缺少什么?

jar tf owl2gdb.jar返回:

META-INF/
META-INF/MANIFEST.MF
tool/Util.class
graphdatabase/GraphDatabase$1.class
graphdatabase/GraphDatabase.class
cpp/CPPFileWriter.class
cpp/GraphDatabaseHeaderWriter.class
cpp/CppHeaderFileWriter.class
cpp/CppTextTemplate.class
cpp/CppSourceFileWriter.class
cpp/GraphDatabaseSourceWriter.class
owl2gdb/OWL2GDB.class
knowledge/MyOWLClass.class
knowledge/MyOWLDataProperty.class
knowledge/MyOntology.class
knowledge/MyOWLObjectProperty.class
knowledge/MyOWLOntology.class
usr/local/me/github/croco/owl2gdb/src/owl2gdb/OWL2GDB.java
usr/local/me/github/croco/owl2gdb/src/owl2gdb/src/graphdatabase/GraphDatabase.java
usr/local/me/github/croco/owl2gdb/src/owl2gdb/src/cpp/CPPFileWriter.java
usr/local/me/github/croco/owl2gdb/src/owl2gdb/src/cpp/CppHeaderFileWriter.java
usr/local/me/github/croco/owl2gdb/src/owl2gdb/src/cpp/CppSourceFileWriter.java
usr/local/me/github/croco/owl2gdb/src/owl2gdb/src/cpp/CppTextTemplate.java
usr/local/me/github/croco/owl2gdb/src/owl2gdb/src/cpp/GraphDatabaseHeaderWriter.java
usr/local/me/github/croco/owl2gdb/src/owl2gdb/src/cpp/GraphDatabaseSourceWriter.java
usr/local/me/github/croco/owl2gdb/src/owl2gdb/src/knowledge/MyOntology.java
usr/local/me/github/croco/owl2gdb/src/owl2gdb/src/knowledge/MyOWLClass.java
usr/local/me/github/croco/owl2gdb/src/owl2gdb/src/knowledge/MyOWLDataProperty.java
usr/local/me/github/croco/owl2gdb/src/owl2gdb/src/knowledge/MyOWLObjectProperty.java
usr/local/me/github/croco/owl2gdb/src/owl2gdb/src/knowledge/MyOWLOntology.java
usr/local/me/github/croco/owl2gdb/src/owl2gdb/src/tool/Util.java

这是我在我的清单中唯一拥有的东西:

Main-Class: owl2gdb.OWL2GDB

我真的需要一些建议......请

谢谢

0 个答案:

没有答案