0

I have the following :

 <mkdir dir="${build.dir}/serverNIO" />
   <copy todir="${build.dir}/serverNIO" overwrite="true" verbose="true">
    <fileset dir="resources/serverresources">
        <include name="*.properties" />
    </fileset>
</copy>

I want to copy the properties file from one folder to the other, all other tasks work fine except this one. Why does this happen? I do not even get any error message,and the file are in the location mentioned.

So when I try to run my server:

MacBook-Pro:ClientServerNio ramapriyasridharan$ ant run_server
Buildfile: /Users/ramapriyasridharan/Downloads/ClientServerNio/build.xml

init:
    [mkdir] Created dir: /Users/ramapriyasridharan/Downloads/ClientServerNio/bin
    [mkdir] Created dir: /Users/ramapriyasridharan/Downloads/ClientServerNio/dist

compile_server:
    [mkdir] Created dir: /Users/ramapriyasridharan/Downloads/ClientServerNio/bin/serverNIO
     [copy] Copying 1 file to /Users/ramapriyasridharan/Downloads/ClientServerNio/bin/serverNIO
     [copy] Copying /Users/ramapriyasridharan/Downloads/ClientServerNio/resources/serverresources/server.properties to /Users/ramapriyasridharan/Downloads/ClientServerNio/bin/serverNIO/server.properties

init:

compile_common_server:
    [javac] Compiling 3 source files to /Users/ramapriyasridharan/Downloads/ClientServerNio/bin/serverNIO

init:

compile_database_api:
    [javac] Compiling 1 source file to /Users/ramapriyasridharan/Downloads/ClientServerNio/bin/serverNIO
    [javac] Compiling 5 source files to /Users/ramapriyasridharan/Downloads/ClientServerNio/bin/serverNIO

jar_server:
      [jar] Building jar: /Users/ramapriyasridharan/Downloads/ClientServerNio/dist/server.jar

run_server:
     [java] Exception in thread "main" java.io.FileNotFoundException: /ClientServerNio/bin/serverNIO/server.properties (No such file or directory)
     [java]     at java.io.FileInputStream.open(Native Method)
     [java]     at java.io.FileInputStream.<init>(FileInputStream.java:146)
     [java]     at java.io.FileInputStream.<init>(FileInputStream.java:101)
     [java]     at ch.ethz.rama.asl.server.MessageServer.main(Unknown Source)
     [java] Java Result: 1

EDIT :

Now it suddenly seems to copy files, only thing is my server program cannot find the properties file,even tought its in the same directory, what should I do?

LoveMeow
  • 3,858
  • 9
  • 44
  • 66

1 Answers1

1

The Ant script copies server.properties to...

/Users/ramapriyasridharan/Downloads/ClientServerNio/bin/serverNIO/server.properties

...but the Java program launched in the run_server target is looking for the file at...

/ClientServerNio/bin/serverNIO/server.properties

To fix this, either:

  • <copy> in the Ant script needs to copy server.properties to /ClientServerNio/bin/serverNIO
  • MessageServer.main needs to change so it looks for server.properties under /Users/ramapriyasridharan
Chad Nouis
  • 6,861
  • 1
  • 27
  • 28
  • I get it! But I would like this program to be deployed on any computer, so if I used the absolute path wont I run into problems? Is there anyway I could use the relative path? – LoveMeow Oct 07 '15 at 14:19
  • Can you modify `MessageServer.java`? If so, you can use [`System.getProperty("user.home")`](http://stackoverflow.com/questions/585534/what-is-the-best-way-to-find-the-users-home-directory-in-java) to get the current user's home directory. – Chad Nouis Oct 07 '15 at 14:27
  • 1
    Also, you can use `..` in Ant to represent the parent directory relative to another directory. For example, `../anotherDir` represents a sibling directory named `anotherDir`. – Chad Nouis Oct 07 '15 at 14:29
  • I can modify MessageServer.java! so I can get the home diretory and do add /ClientServerNio/bin/serverNIO/server.properties. – LoveMeow Oct 07 '15 at 16:15
  • The home directory is ClientServerNio? or ClientServerNio/bin/? I tried it it doesnt seem to find the file, I think I am doing something else wrong,will get back to you with an update. – LoveMeow Oct 07 '15 at 16:16