2016-06-13 22 views
1

私はJavaの専門家ではありませんが、CMU Sphinx 4ライブラリを使用してポッドキャストを書き換えるコンポーネントを構築しようとしています。 Eclipse MarsとGradleを使って、実行可能なfat jarとしてプロジェクトを構築しています。私のbuild.gradleはこのように見えます。GradleはClassPathの移植不可能な絶対パスを生成します

/* 
* This build file was auto generated by running the Gradle 'init' task 
* by 'peter' at '03/06/16 18:34' with Gradle 2.6 
* 
* This generated file contains a sample Java project to get you started. 
* For more details take a look at the Java Quickstart chapter in the Gradle 
* user guide available at https://docs.gradle.org/2.6/userguide/tutorial_java_projects.html 
*/ 

// Apply the java plugin to add support for Java 
apply plugin: 'java' 



// In this section you declare where to find the dependencies of your project 
repositories { 
    // Use 'jcenter' for resolving your dependencies. 
    // You can declare any Maven/Ivy/file repository here. 
    jcenter() 
    mavenLocal() 
    maven { url "https://oss.sonatype.org/content/repositories/snapshots" } 
} 

// In this section you declare the dependencies for your production and test code 
dependencies { 
    // The production code uses the SLF4J logging API at compile time 
    compile 'org.slf4j:slf4j-api:1.7.12' 
    compile group: 'edu.cmu.sphinx', name: 'sphinx4-core', version:'5prealpha-SNAPSHOT' 
    compile group: 'edu.cmu.sphinx', name: 'sphinx4-data', version:'5prealpha-SNAPSHOT' 

    // Declare the dependency for your favourite test framework you want to use in your tests. 
    // TestNG is also supported by the Gradle Test task. Just change the 
    // testCompile dependency to testCompile 'org.testng:testng:6.8.1' and add 
    // 'test.useTestNG()' to your build script. 
    //testCompile 'junit:junit:4.12' 
} 

jar { 

    manifest { 
     attributes (
     'Class-Path': configurations.compile.collect { it.isDirectory() ? it : zipTree(it) }, 
     'Main-Class': 'org.conlang.sources.transcriber.Transcriber') 
    } 
    from configurations.compile.collect { entry -> zipTree(entry) } 
} 

ここにはマニフェストがあります。 Javaはマニフェストのパスを見つけることができないので、

Manifest-Version: 1.0 
Class-Path: [ZIP '/home/peter/.gradle/caches/modules-2/files-2.1/org.s 
lf4j/slf4j-api/1.7.12/8e20852d05222dc286bf1c71d78d0531e177c317/slf4j- 
api-1.7.12.jar', ZIP '/home/peter/.gradle/caches/modules-2/files-2.1/ 
edu.cmu.sphinx/sphinx4-core/5prealpha-SNAPSHOT/523f86d4932fc124a6d497 
6adbcbc4976f1ece28/sphinx4-core-5prealpha-SNAPSHOT.jar', ZIP '/home/p 
eter/.gradle/caches/modules-2/files-2.1/edu.cmu.sphinx/sphinx4-data/5 
prealpha-SNAPSHOT/545a2d84cfe804d18cd9926a35331546fe09f2c2/sphinx4-da 
ta-5prealpha-SNAPSHOT.jar', ZIP '/home/peter/.gradle/caches/modules-2 
/files-2.1/org.apache.commons/commons-math3/3.2/ec2544ab27e110d2d431b 
dad7d538ed509b21e62/commons-math3-3.2.jar'] 
Main-Class: org.conlang.sources.transcriber.Transcriber 

私はコピーして、自分のマシン上の別のディレクトリに貼り付ける

は、jarファイルは、実行されません、それは確かに別のマシン上で実行されません。使用可能なClassPathを取得するには、build.gradleで何を変更する必要がありますか?

+0

の複製です。[依存関係を持つjarファイルを作成するためのグラデーションの使用](http://stackoverflow.com/questions/4871656/using-gradle-to-build-a-jar-with-dependencies) ) –

答えて

0

あなたは、単にあなたがconfigurations.compile.collectとすべての依存関係を展開している場合は、クラスパスを指定する必要はありません

jar { 
    manifest { 
     attributes (
      'Main-Class': 'org.conlang.sources.transcriber.Transcriber') 
    } 
    from configurations.compile.collect { entry -> zipTree(entry) } 
} 

を使用することができます。これは、Using Gradle to build a jar with dependencies

0

パッケージを移植可能な状態に保つために依存関係ジャーをどのように配布していますか?

このit.isDirectory() ? it : zipTree(it)は、依存関係ジャーの絶対パスを生成します。依存関係を含む配布可能なパッケージを作成しようとしている場合、jarプラグインはおそらく最良の方法ではありませんが、代わりにapplication pluginを試してみてください。

+0

jarセクションのmanifestの直下にあるcomponents.compile.collect {entry - > zipTree(entry)}の行は、依存関係をjarファイルに追加します。このビットは正しく動作しています。 –

+0

あなたの問題は 'jar.manifest.attributes.class-path'の行で、絶対パスがどこから来るかです。マニフェストセクションで 'it'の代わりに' it.name'を使ってみることができます。 – RaGe

+0

私はこれを試してみましたが、relativePath(it)とrelativePath(it.name)も試しましたが、何も動作していないようです。毎回同じ結果が出ます。 –

関連する問題