• Post Reply Bookmark Topic Watch Topic
  • New Topic

How to use relative directory locations when compiling?  RSS feed

 
charlie Lazin
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a directory structure as such:
c:\javaprogram
----- build
----- src
----- classes
----- lib

Within the classes I will have my compiled class and within src is the source code NewClass.java. 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\NewClass.java

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\NewClass.java

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\NewClass.java not found error.

Is this possible? If so, how?

Thanks
 
Henry Wong
author
Sheriff
Posts: 23295
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
charlie Lazin wrote: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\NewClass.java

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\NewClass.java not found error.


What you are describing should work fine. I have done this myself many times.


And BTW, welcome to the ranch...

Henry
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!