我想创建一个 exe 文件,而不必将所有必需的库放在 exe 旁边。 以前用 ant 我用 one-jar 创建了一个独立的 jar 文件,然后用 launch4j 把它打包成一个 exe 文件。
Gradle 的插件和独立插件都可以很好地工作,几乎不需要配置。
但是我如何设法使用创建的 one-jar 作为 launch4j 的输入?
这是我当前的构建文件:
apply plugin: 'java'
apply plugin: 'launch4j'
apply plugin: 'gradle-one-jar'
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'edu.sc.seis.gradle:launch4j:1.0.6'
classpath 'com.github.rholder:gradle-one-jar:1.0.4'
}
}
launch4j {
mainClassName = "de.my.umkopierer.Umkopierer"
launch4jCmd = "C:/Program Files (x86)/Launch4j/launch4j"
jar = "lib/Umkopierer-1.0.jar"
headerType = "console"
dontWrapJar = false
}
sourceCompatibility = 1.7
version = '1.0'
jar {
manifest {
attributes 'Implementation-Title': 'Umkopierer', 'Implementation-Version': version
}
}
repositories {
mavenCentral()
}
dependencies {
compile group: 'commons-collections', name: 'commons-collections', version: '3.2'
compile 'com.google.guava:guava:18.0'
compile 'com.fasterxml.jackson.core:jackson-core:2.4.4'
compile 'com.fasterxml.jackson.datatype:jackson-datatype-jdk7:2.4.4'
compile 'com.fasterxml.jackson.core:jackson-databind:2.4.4'
testCompile group: 'junit', name: 'junit', version: '4.+'
}
task oneJar(type: OneJar) {
mainClass = "de.stiffi.umkopierer.Umkopierer"
}
最佳答案
我通过使 launch4j 任务“createExe”依赖于 onejar/fatjar(或任何其他 fat jar 创建方法)来解决这个问题。例如:
tasks.createExe.dependsOn('oneJar')
task launch4j(overwrite: true, dependsOn: ['createExe']){
}
此外,我认为您的 gradle 构建文件应该包含一个主类属性,例如
manifest {
attributes 'Main-Class':'com.example.MyMainClass'
}
(如果您使用的是 fatjar gradle 插件,至少是这样)。
关于java - Gradle:如何使用一 jar 输出作为 launch4j 的输入,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27311914/