Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Compiling  RSS feed

 
Pieter-Jan Delaruelle
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I was wondering if there is a way to make the compiler always look in the same directory for files to compile.
Until now I've always given the complete pathname to javac but think it is a bit stupid, always retyping the same except for the filename.
Any suggestions, tips, hints, tricks,... ?
 
Svend Rost
Ranch Hand
Posts: 904
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Im not quite sure I understand your question, but I'll give it a
go anyways:

You just want to type: "javac <filename>" instead of
"c:\my\java\path\javac <filename>"
Add javas bin directory to your path (under environmental variables in windows)

You dont want to type the java file names when you compile.
You can either type javac *.java or make a batch (bat) file if your using
windows, or a shell file if your using unix.

Alternatively, you should consider to use an IDE (Intelligent Development
Environment) which handles all the "boring stuff". Try blueJ for small
projects or Eclipse for large projects.

/Svend Rost
 
Tony Morris
Ranch Hand
Posts: 1608
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Change to that directory from your shell.
> man cd
or
> cd /?
...or create a script that opens a shell at that directory.
...or ... the options are endless.
Learn how to use the operating system.
 
Pieter-Jan Delaruelle
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Actually I want to type
javac <filename>
instead of javac C:\directoryWhereFileIsLocated\<filename>
while in C:\Java\bin\

Don't know if I'm making any sense here...

:roll:
 
Jesper de Jong
Java Cowboy
Sheriff
Posts: 16026
87
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So you want to type "javac <filename.java>" while your current directory is not the directory where filename.java is located, and without specifying the directory that filename.java is in.

That's not possible. Why do you want to do it exactly that way? Why don't just add the bin directory of the JDK to the PATH and compile from the directory that the source file is in?

If you don't know how to add the bin directory of the JDK to the PATH, then read the installation notes of the JDK, especially point 5 ("Update the PATH variable").
 
Pieter-Jan Delaruelle
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks everyone for the quick replies.
Especially Jesper Young.
This was actually the solution I was looking for (even though I didn't quite knew it myself yet :roll: )
 
Srinivas Kalvala
Ranch Hand
Posts: 257
Firefox Browser Hibernate Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

If you are working with a huge set of files, then it would be better to go for ant build.
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
HERE are some examples of setting up directories and paths for compiling. It gets a bit trickier when you use packages and separate your java and class files and such.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!