[英]Trying to use tools.jar - gradle
I am using gradle
to package some java code into a jar. 我正在使用gradle
将一些Java代码打包到jar中。 I am using some classes from tools.jar
. 我正在使用来自tools.jar
一些类。 I have had success in gradle
building it and making a jar, but when I run that jar using java -jar <package>.jar
I get the folowing java.lang.NoClassDefFoundError: com/sun/tools/attach/VirtualMachine
. 我在gradle
成功构建了它并制作了一个jar,但是当我使用java -jar <package>.jar
运行该jar时,出现了以下java.lang.NoClassDefFoundError: com/sun/tools/attach/VirtualMachine
。
Since tools.jar
is something you get with a jdk
, not a jre
. 由于tools.jar
是通过jdk
获得的,而不是jre
。 Is there a way I can bundle tools.jar
with my package.jar
and have my jar work anywhere? 有什么方法可以将tools.jar
与package.jar
捆绑在一起,并使我的jar在任何地方都能工作?
Here is my build.gradle
so far. 到目前为止,这是我的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'
}
可能您需要的是“胖罐子”(Gradle将所有依赖项打包到单个罐子中)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.