• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Setting java properties

 
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I was wondering how to set some java properties. I don't want to pass in the key/value pairs in the command line (as "-Dkey=value). Is there a way to set them in the code?

Thanks!!
 
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes; the setProperty() method in the java.lang.System class can set these. Be careful because some properties take effect during JVM startup, and using setProperty() for these will not have the intended effect.
 
Ed Zeval
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Cool, thanks. That worked.

Now... I saw that the System.set/getProperty() methods may throw a SecurityException if I'm running a SecurityManager and I don't have permissions.

What is a SecurityManager and how do I get the necessary permissions in case I don't have them?

Thanks!
 
Rancher
Posts: 5008
38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think you can use policytool that comes with the jre(?)/jdk install to give your program permissions. The permissions would have to be set on every computer that you run your program on.
You'll have to read a tutorial to understand how to use policytool. In some cases I've have to manually edit the .java.policy file to get the correct paths to give my programs permissions. There has been a lot of try this, try that until I've been able to give my programs permissions.
Perhaps you won't have to do this.
 
reply
    Bookmark Topic Watch Topic
  • New Topic