8

I'd like to know how I can pass parameters to JVM before it is started. For example,

I think I need to modify JVM timezone parameter.

I use eclipse with windows 7.

bmargulies
  • 97,814
  • 39
  • 186
  • 310
iceberg
  • 1,951
  • 1
  • 22
  • 26

2 Answers2

11

In Eclipse go to

Run As -> Run Configurations -> Arguments -> VM Arguments

and set required JMV argument, eg

-Duser.timezone=PST

you can get all timezone IDs available in JVM by running this test

for(String id : TimeZone.getAvailableIDs()) {
    System.out.println(id);
}

output

Etc/GMT+12
Etc/GMT+11
Pacific/Midway
Pacific/Niue
Pacific/Pago_Pago
Pacific/Samoa
....
Evgeniy Dorofeev
  • 133,369
  • 30
  • 199
  • 275
  • thanks for your advice. And another problem is that when I run this code: `System.out.println(TimeZone.getDefault());` output is sun.util.calendar.ZoneInfo[id="America/Caracas",offset=-16200000,dstSavings=0,useDaylight=false,transitions=5,lastRule=null] How to change this another way? – iceberg Feb 01 '13 at 11:52
  • 1
    Use one of the TimeZone methods eg TimeZone.getDefault().getDisplayName() – Evgeniy Dorofeev Feb 01 '13 at 11:57
4

JVM parameters are specified in command line with -D

java -Dfile.encoding=utf-8 -jar myApp.jar

In your case use -Duser.timezone

How to set a JVM TimeZone Properly

Community
  • 1
  • 1
Nikolay Kuznetsov
  • 9,467
  • 12
  • 55
  • 101