• Post Reply Bookmark Topic Watch Topic
  • New Topic

Javac commands : Is this allowed ?  RSS feed

 
Rahul Sudip Bose
Ranch Hand
Posts: 637
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My directory structure : (i use windows OS)



I want to compile my class file such that it lands in the directory \classes\newDir1\newDir2 . The compiler should make these new directories. Is this possible ?
If so, can i do that from :
1) One directory above myProject
2) From inside myProject ?

PS : how to learn and master packages and classpaths ?
 
Stephan van Hulst
Saloon Keeper
Posts: 7817
142
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There are all sorts of automated build scripts and tools that can do that for you.

Personally, when I'm working on a hobby project, I just use a simple batch file I wrote once. Here's an example (Windows Vista). This will compile from src to bin:

@echo off
echo Clearing files...
call clear
echo.
echo Compiling...
javac src\com\example\Main.java -cp %CLASSPATH%;src -d bin -Xlint:unchecked
::echo.
::echo Writing documentation...
::javadoc -subpackages com.example -sourcepath %CLASSPATH%;src -d doc -quiet -version -author -use -link http://download.oracle.com/javase/6/docs/api/ -package -linksource -sourcetab 2
echo.
echo Done.
echo.
cmd /k
@echo on


This batch calls clear.bat, given here:

@echo off
rd bin doc /q /s
md bin doc
 
Jesper de Jong
Java Cowboy
Sheriff
Posts: 16028
87
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can use the -d switch in the javac command to specify the directory to write the class files to, but the compiler will not make the subdirectories newDir1 and newDir2 automatically for you (it will only do that if there is a package statement in the source file - it would then create a directory structure that matches the package name). Note that the directory structure that the source file is in should also match the package name.

You can learn about packages in Lesson: Packages in Oracle's Java Tutorials.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!