[Anthill] Change working directory for build
Andy Levy
andy.levy at gmail.com
Wed Dec 28 09:19:22 CST 2005
On 12/28/05, Varban <vvv at urbancode.com> wrote:
> Hi Andy,
>
> it seems strange that Anthill will not run the ant script from the root of the
> downloaded source. Since Anthill is aware of where the source is downloaded,
> it changes to that directory and then runs the ant script from there. It is
> possible that because the ant process is not started in any console, any
> child process will not see the current directory that ant was ran from but
> insdead will point to the cmd.exe location that was used to execute the ant
> process.
I think that's exactly what's happening.
> I am not sure how your A.java class locates the conf directory but I would try
> and use the ClassLoader.getResourceAsStream and ClassLoader.getResource
> methods to locate the properties files (you will need to add the directories
> that hold them to the classpath). This way you will be completely independent
> from the current working directory and the location of the code.
Right now we have this:
private static final String confDir = "./conf";
private static final String serializedFile = confDir +
"/HPLGproperties.serialized";
File dir = new File(confDir);
Properties prop = new Properties();
String absPath = null;
try {
absPath = new File(".").getCanonicalPath().replace('\\','/');
} catch (Exception e) {
e.printStackTrace();
}
for (int i=0; i < dir.list().length; i++) {
String file = dir.list()[i];
String[] split = file.split("\\.");
if (split.length<2 || ! split[1].equals("properties"))
continue;
//System.out.println("filename='" + split[0] + "'");
try {
FileInputStream fis = new FileInputStream( new File(dir + "/" + file) );
Properties p = new Properties();
p.load(fis);
fis.close();
for (Enumeration e = p.propertyNames(); e.hasMoreElements(); ) {
String el = (String) e.nextElement();
prop.setProperty(split[0] + "." + el,p.getProperty(el));
}
} catch (Exception e) {
e.printStackTrace();
}
}
I think once we get past having confDir set correctly, everything will
be OK. My Java's beyond rusty; this was actually written by someone
else and I'm just doing process improvements, I'm not supposed to do a
lot of code changes on this.
More information about the Anthill
mailing list