简体   繁体   English

如何通过 Ant - Swing 传递 jvm 参数

[英]How can I pass jvm argument via Ant - Swing

I want to pass the JVM argument -Dfile.encoding=UTF-8 to my swing application using Ant script, I'm using eclipse and I'm looking for the minimum Ant script content to do this.我想使用 Ant 脚本将 JVM 参数-Dfile.encoding=UTF-8传递给我的 swing 应用程序,我正在使用 eclipse 并且我正在寻找最小的 Ant 脚本内容来执行此操作。 this is my first use of ant buildfile.这是我第一次使用 ant 构建文件。

If you are using ant's java task to launch app, then see its <jvmarg >.. options. 如果您正在使用ant的java任务来启动应用程序,请查看其<jvmarg >..选项。 You have to set fork to true, so that application runs under a new process with appropriate system properties set. 您必须将fork设置为true,以便应用程序在设置了适当系统属性的新进程下运行。

I assume you want to build a jar file containing your application. 我假设您想构建一个包含应用程序的jar文件。 It is however not possible to specify a run-time system property when doing so. 但是,这样做时无法指定运行时系统属性。 For an overview of JAR structure, see http://docs.oracle.com/javase/7/docs/technotes/guides/jar/jar.html - though it is possible to specify a main class of your application, it is not possible to set any parameters for it. 有关JAR结构的概述,请参见http://docs.oracle.com/javase/7/docs/technotes/guides/jar/jar.html-尽管可以指定应用程序的主类,但不能指定它可以为其设置任何参数。

To set the system property to JVM upon your application start, you can do one of: 要在应用程序启动时将系统属性设置为JVM,可以执行以下操作之一:

Set the property in code, eg in a static initialization code on your main class: 在代码中设置属性,例如在主类上的静态初始化代码中:

static {
 System.setProperty("file.encoding", "UTF-8"); }

Or, pass it as a command line parameter when starting your JAR: 或者,在启动JAR时将其作为命令行参数传递:

java -Dfile.encoding=UTF-8 -jar yourapp.jar 

just in case anyone is using run.xml then add this line to pass argument to jar file, <jvmarg value="-Dfile.encoding=UTF-8"/> inside the Java node.以防万一有人使用 run.xml 然后添加此行以将参数传递给 jar 文件, <jvmarg value="-Dfile.encoding=UTF-8"/>在 Java 节点内。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM