2

I have an application packaged in an EAR file and deployed on WildFly 9.0.2 Final. it needs to read some system properties defined by WildFly.

The problem is that the classes in the EAR fail to read the WildFly system properties. For example - the following code gets a NullPointerException:

String DEPLOY_DIR  = System.getProperty("jboss.server.base.dir") + File.separator + "deployments"
File deployDir = new File(DEPLOY_DIR);

And this is the error:

java.lang.NullPointerException
            at java.io.File.<init>(File.java:277)

The error occurs because the following returns null:

System.getProperty("jboss.server.base.dir")

Note that when WildFly goes up, its related system properties are shown correctly in its log:

jboss.server.base.dir = C:\javaSoft\workspaces\WildFly_Migration\App\configuration\wildfly-9.0.2.Final\standalone
jboss.server.config.dir = C:\javaSoft\workspaces\WildFly_Migration\App\configuration\wildfly-9.0.2.Final\standalone\configuration
jboss.server.data.dir = C:\javaSoft\workspaces\WildFly_Migration\App\configuration\wildfly-9.0.2.Final\standalone\data
jboss.server.deploy.dir = C:\javaSoft\workspaces\WildFly_Migration\App\configuration\wildfly-9.0.2.Final\standalone\data\content
jboss.server.log.dir = C:\javaSoft\workspaces\WildFly_Migration\App\configuration\wildfly-9.0.2.Final\standalone\log

My question - Is there any reason why the EAR can’t read any of the system properties?

TT.
  • 15,774
  • 6
  • 47
  • 88
Elad Eldor
  • 803
  • 1
  • 12
  • 22
  • Where is your code that reads system props. and at what time does it get executed? is it maybe part of static initializer? – Tomaz Cerar Jan 13 '16 at 18:17
  • 1
    are you sure this code is being executed? if your property is `null`, `DEPLOY_DIR` shoud be something like `null\deployments` – user140547 Jan 14 '16 at 08:55

1 Answers1

1

I start by saying that in a large system, it is hard to diagnose those problems.

In a JVM, System Properties are shared and you should always see the same values, as Wildfly9 documentation confirms while warning you about the risks of Property Replacement

System properties etc are resolved in the security context of the application server itself, not the deployment that contains the file.

So the answer should be no: EAR can read all of the system properties, since you are not receiving a SecurityException (which excludes the fact that you are running inside a security context and it is blocking you).

Anyways, there may be some situation you should check, like:

  1. Your piece of code is running after an other piece of code which removes the value. You can workaround those problem using the environment variable $JBOSS_HOME.
  2. Your DEPLOY_DIR is a static constant (in this case it could be evaluated before Wildfly sets jboss.server.base.dir). You can workaround this problem using "jboss.home.dir" key, which is created by standalone.sh directly.
  3. Your code is running inside a static { ... } initialization block. If this is the case, using "new File" inside it is a bad practice, but if not, you could workaround it as case 2.
Ozwizard
  • 99
  • 1
  • 5