Results 1 to 2 of 2
  1. #1
    chesl73 is offline Member
    Join Date
    Oct 2009
    Rep Power

    Default How to use relative paths when compiling?

    I have a directory structure as such:
    ----- build
    ----- src
    ----- classes
    ----- lib

    Within the classes I will have my compiled class and within src is the source code lib contains my .jar files.
    In the build directory I have a .bat file that I use to compile the source code into the .class which is stored in the classes folder.
    My build.bat file looks like:

    set root_dir=c:\javaprogram
    javac -d %root_dir%\classes\ -classpath %root_dir%\classes;%root_dir%\lib\one.jar; -sourcepath %root_dir%\src %root_dir%\src\

    This works fine.
    For reasons I won't go into this root diretory will change as this folder will be copied multiple times so ideally what I'd have is instead of root_dir pointing to a fullpath
    I can just use a relative path so that my .bat file would look something like:

    javac -d ..\classes\ -classpath ..\classes;%root_dir%\lib\one.jar; -sourcepath ..\src ..\src\

    were the .. signifies that I'm running this batch file from the build directory so go up one level and down into the src folder to find the .java file.

    This above doesn't work and I get a file ..\src\ not found error.

    Is this possible? If so, how?


  2. #2
    r035198x is offline Senior Member
    Join Date
    Aug 2009
    Rep Power


    Not really a Java question then. You might want to try asking in a Windows scripting forum somewhere.
    Perhaps you could try setting the root to the current directory using something like
    set root_dir=. but I don't know if that works in windows scripting

    r035198x(<---shooting in the dark

Similar Threads

  1. Replies: 2
    Last Post: 10-14-2009, 05:47 AM
  2. how to set relative path in jsp?
    By makpandian in forum JavaServer Pages (JSP) and JSTL
    Replies: 0
    Last Post: 01-02-2009, 09:20 AM
  3. Obtaining relative path outside of executable JAR
    By tjsaker in forum Advanced Java
    Replies: 1
    Last Post: 11-14-2008, 07:48 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts