pg_dump freezes on windows service application
dezso was right, the PGPASSWORD environment variable is present when executing Tomcat from a single shell, but not when it's started as a service. The solution is to put the value in the process environment:

 ProcessBuilder builder = new ProcessBuilder(
      "C:/postgres9/bin/pg_dump.exe",
      "-U", "myuser",
      "-h" , "localhost",
      "mydb");

 Map&lt;String, String&gt; env = builder.environment();
 env.put("PGPASSWORD", "supersecret");

 Process p = builder.start();
 storeToFile( p.getInputStream() );


Solution source is here: How to pg_dump from Java