Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
Clear All
new posts

    server.properties with Java System Properties

    How do I reference Java system properties in the server.properties file?

    I'm passing in values to the JVM using the -D flag, ie: -Ddb.host=localhost

    I'm trying to configure a database connection, here's the relevant block from my server.properties:

    Code:
    sql.defaultDatabase:Mysql
    sql.defaultDatabase.type:mysql
    sql.defaultDatabase.interface.type:dataSource
    sql.defaultDatabase.driver:org.mariadb.jdbc.MariaDbDataSource
    sql.defaultDatabase.driver.serverName:${db.host}
    sql.defaultDatabase.driver.portNumber:3306
    sql.defaultDatabase.driver.databaseName:${db.name}
    sql.defaultDatabase.driver.user:${db.user}
    sql.defaultDatabase.driver.password:${db.password}
    I've verified that the referenced properties are available from System.getProperty(). I know I can use a listener before the SC framework starts and I can add them manually to the Config, but I was curious if something like this is already supported in server.properties directly.

    Right now I get the error:
    Code:
    java.lang.Exception: variable expansion failed for variable: db.host

    #2
    Yes, you can do this as follows:

    Code:
     -Disc_config:db.host=localhost
    Then your ${db.host} reference in server.properties will resolve to 'localhost'

    As of 12.1 (not yet released as of the time of this of this writing), you'll be able do do this:

    Code:
    sql.defaultDatabase.driver.serverName: $SYS{db.host}
    And then, -Ddb.host=localhost will be picked up.

    One note on this: command line properties can observed from the process listing on most operating systems, so be careful with passing sensitive data like passwords in this manners. You can use environment variables:
    Code:
    sql.defaultDatabase.driver.serverName: $ENV{ENV_VAR_NAME}

    Comment


      #3
      Exactly what I was looking for, thank you!

      Comment

      Working...
      X