我gradle
用来将一些java代码打包到一个jar中。我正在使用tools.jar
. 我已经成功gradle
构建它并制作了一个 jar,但是当我使用运行该 jar 时,java -jar <package>.jar
我得到了以下
java.lang.NoClassDefFoundError: com/sun/tools/attach/VirtualMachine
.
因为tools.jar
是你用 a 得到的东西jdk
,而不是 a jre
。有没有办法可以与我的 jar 捆绑tools.jar
在一起package.jar
并让我的 jar 在任何地方工作?
这是我build.gradle
到目前为止。
buildscript {
repositories {
maven {
url 'https://plugins.gradle.org/m2/'
}
}
}
description = "A java program"
apply plugin: 'java'
sourceCompatibility = 1.8
repositories {
mavenCentral()
flatDir {
dirs System.properties['java.home'] + '/../lib'
}
}
jar {
archiveName = "jProg.jar"
manifest {
attributes(
'Dependencies': 'com.sun.tools'
)
}
}
dependencies {
compile group: 'com.sun', name: 'tools'
}