如何将默认的JVM参数设置为Gradle应用程序插件?

13
我使用gradle应用程序插件生成应用程序文件夹。 installApp任务为我提供了一个启动脚本,但我不知道如何从build.gradle文件中设置jvm参数。 我需要一些jvm参数,例如file.encoding。 我只需修改启动脚本以设置DEFAULT_JVM_OPTS变量即可。
#!/usr/bin/env bash

##############################################################################
##
##  MuzeeS3Deployer start up script for UN*X
##
##############################################################################

# Add default JVM options here. You can also use JAVA_OPTS and MUZEE_S_DEPLOYER_OPTS to pass JVM options to this script.
DEFAULT_JVM_OPTS=" -Dfile.encoding=utf-8 "
如果不设置args,我的控制台就无法正确显示消息:
qty:MuzeeS3Deployer qrtt1$ ./build/install/MuzeeS3Deployer/bin/MuzeeS3Deployer d
2012/10/14 #U###12:02:03 SyncCommand main
ĵ#i: no aws credentials found at /Users/qrtt1/AwsCredentials.properties

当我设置编码时:

qty:MuzeeS3Deployer qrtt1$ ./build/install/MuzeeS3Deployer/bin/MuzeeS3Deployer d
2012/10/14 下午 12:04:19 SyncCommand main
警告: no aws credentials found at /Users/qrtt1/AwsCredentials.properties

我从@Peter那里得到了解决方案。最终,我对脚本进行了一些小的修改:

startScripts {
    doLast {
        unixScript.text = unixScript.text.replace('DEFAULT_JVM_OPTS=""', 'DEFAULT_JVM_OPTS="-Dfile.encoding=utf-8"')
        windowsScript.text = windowsScript.text.replace('DEFAULT_JVM_OPTS=', 'DEFAULT_JVM_OPTS="-Dfile.encoding=utf-8"')
    }
}
2个回答

27

10

目前没有专门支持设置DEFAULT_JVM_OPTS的功能。但是,您可以执行以下操作:

startScripts {
    doLast {
        unixScript.text = unixScript.text.replace('DEFAULT_JVM_OPTS=""', 'DEFAULT_JVM_OPTS="-Dfile.encoding=utf-8"')
    }
}

你可能想对 windowsScript 做类似的事情。


6
不要再使用这个了!这种解决方案已经过时了。 - Tobias Kremer
1
是的,现在你可以在 build.gradle 中添加以下内容: applicationDefaultJvmArgs = ['-Dxxxxx'] - YaP
1
问题在于如果您需要为Windows和Linux输入不同的设置(例如路径),那么Peter的解决方案似乎是最简单的。 - YaP

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接