Search code examples
javaswingantjvm-arguments

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. this is my first use of ant buildfile.


Solution

  • I assume you want to build a jar file containing your application. 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.

    To set the system property to JVM upon your application start, you can do one of:

    Set the property in code, e.g. 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:

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