• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How to use relative directory locations when compiling?

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
author
Posts: 23951
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Think of how stupid the average person is. And how half of them are stupider than that. But who reads this tiny ad?
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic