user2967626
user2967626

Reputation: 25

How to access worklight.properties in java file under server/java/mypackage

Im using worklight 6.0 and I know how to use worklight.properties file in adapter xml But,How to access worklight.properties in java file under server/java/mypackage

Upvotes: 1

Views: 791

Answers (3)

Anton
Anton

Reputation: 3166

public static String getWorklightProperty(String propertyName){
    return WorklightConfiguration.getInstance().getString("propertyName");
}

Upvotes: 2

Zohar Tenne
Zohar Tenne

Reputation: 21

You can use the ClassLoader's getResourceAsStream method in order to access the worklight.prperties file. Here is a code example that retrieves the project build number:

public String getPublicBuildVersion() {
    try{
        Properties p = new Properties();
        p.load(getClass().getClassLoader().getResourceAsStream("conf/worklight.properties"));
        return p.getProperty("project.build.version");
    } catch(Exception e) {
        return "Exp: " + e.getMessage();
    }
}

There is a limitation when ucsing this method. When I tried that it worked, but after I updated the application, this code threw an exception during the getResourceAsStream call. The only way I found to make the code work again is to restart the server.

Upvotes: 2

Srik
Srik

Reputation: 7965

One way would be to read the property you are interested using WL.Server.configuration API and then passing these values to your Java code. The Infocenter has information on how this can be achieved

Upvotes: 1

Related Questions