如何添加默认的JVM参数与Gradle [英] How do I add default JVM arguments with Gradle
问题描述
当使用Gradle构建时,我需要将默认的JVM选项添加到我的jar中。
从我得到的文档中我必须设置:
applicationDefaultJvmArgs = [-Djavafx.embed.singleThread =真正的]
我对Gradle和编写build.gradle文件的开发人员没有太多经验它与大多数网站给出的例子不同。
以下是build.gradle:
apply plugin:'java'
apply plugin:'eclipse'
version ='0.1'
repositories {
mavenCentral ()
dependencies {
testCompile group:'junit',name:'junit',version:'4. +'
compile'placeholder'
任务发布(类型:Jar){
manifest {
attributes(Implementation-Title:placeholder,
Implementation-Version :版本,
'Main-Class':'placeholder.Application')
}
from {configurations.compile.collect { it.isDirectory()?它:zipTree(it)}}
with jar
}
任务包装(类型:包装器){
gradleVersion ='2.2.1'
}
我不知道把参数放在哪里。我尝试将它们放在不同的位置,但我总是得到:
评估根项目'占位符'时发生问题。
>没有这样的属性:applicationDefaultJvmArgs for class:org.gradle.api.tasks.bundling.Jar_Decorated
非常感谢,
Jhonny
从我的头顶我可以想到2个选项:
选项1:做什么@Ethan说,它可能会工作:
package placeholder;
$ b $ //您的导入
public class Application {
static {
System.getProperties()。set(javafx.embed.singleThread, 真正);
//你的代码
public static void main(String ... args){
//你的代码
}
}
选项2:使用应用程序插件+默认jvm值
build.gradle:
$ b
apply apply:'application'
//您的代码
applicationDefaultJvmArgs = [-Djavafx.embed.singleThread = true]
现在您可以通过2种方式运行代码:
从gradle
$ gradle run
code>
来自分配(脚本)。从生成的应用程序插件将提供的脚本中:
$ gradle clean build distZip
然后,gradle将在 $ {your.projectdir} / build
下生成一个zip文件。找到该zip,然后解压缩,并在 / bin
下找到 $ {yourproject} .bat
和 $ {yourproject}
可执行文件。一个用于Linux / mac / unix( $ {yourproject}
)另一个用于windows( $ {yourproject.bat}
)
I need to add default JVM options to my jar, when build with Gradle. From the documentation I got that I have to set:
applicationDefaultJvmArgs = ["-Djavafx.embed.singleThread=true"]
I have not much experience with Gradle and the developer that wrote the build.gradle file wrote it different from what most websites give as examples.
Here is the build.gradle:
apply plugin: 'java'
apply plugin: 'eclipse'
version = '0.1'
repositories {
mavenCentral()
}
dependencies {
testCompile group: 'junit', name: 'junit', version: '4.+'
compile 'placeholder'
}
task release(type: Jar) {
manifest {
attributes("Implementation-Title": "placeholder",
"Implementation-Version": version,
'Main-Class': 'placeholder.Application')
}
from { configurations.compile.collect { it.isDirectory() ? it : zipTree(it) } }
with jar
}
task wrapper(type: Wrapper) {
gradleVersion = '2.2.1'
}
I don't know where to put the arguments. I tried putting them in different locations, but I always get:
A problem occurred evaluating root project 'placeholder'.
> No such property: applicationDefaultJvmArgs for class: org.gradle.api.tasks.bundling.Jar_Decorated
Much Thanks, Jhonny
From the top of my head I can think of 2 options:
Option1: Do what @Ethan said, it'll likely work:
package placeholder;
//your imports
public class Application{
static {
System.getProperties().set("javafx.embed.singleThread", "true");
}
// your code
public static void main(String... args){
//your code
}
}
Option 2: Use the application plugin + default jvm values
build.gradle:
apply plugin: 'application'
//your code
applicationDefaultJvmArgs = ["-Djavafx.embed.singleThread=true"]
Now you can run your code 2 ways:
From gradle
$gradle run
From distribution(script). from the generated script that the application plugin will provide:
$gradle clean build distZip
Then gradle will generate a zip file somewhere under ${your.projectdir}/build
. Find the zip then unzip it and under /bin
you'll find a ${yourproject}.bat
and ${yourproject}
executables. One is for Linux/mac/unix (${yourproject}
) the other one is for windows (${yourproject.bat}
)
这篇关于如何添加默认的JVM参数与Gradle的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!