I have a Dynamic Web Project + Maven deployed on WebSphere 8.5 with java 1.6 and I'm using the following library in the pom.xml:
<dependency>
<groupId>com.googlecode.json-simple</groupId>
<artifactId>json-simple</artifactId>
<version>1.1.1</version>
<scope>provided</scope>
</dependency>
I get the environment's url and I'm trying to write it on a .json file. Here is the code:
InetAddress ip;
try {
ip = InetAddress.getLocalHost();
ip.getHostAddress();
JSONObject obj = new JSONObject();
obj.put("name", "https:" + File.separatorChar + File.separatorChar + ip.getHostAddress() + ":443"
+ File.separatorChar + "authorizer" + File.separatorChar);
obj.put("debugging", "true");
FileWriter file = new FileWriter(ctx.getServletContext().getRealPath("/") + "/assets/conf.json");
file.write(obj.toJSONString());
file.flush();
file.close();
} catch (UnknownHostException e) {
e.printStackTrace();
}
Well it works, but I get this on conf.json:
{"name":"https:\/\/126.0.0.0:443\/authorizer\/","debugging":"true"}
As you see, it is not formatted but when I have tested it on Windows just worked fine. The thing is when I deployed on WebSphere I got the url wrong and the problem It's on the way of the forward slash. How can I write the url correctly?
I have tried already with File.separator
, or simply writing "/"
or "\\"
but neither worked.