简体   繁体   中英

Clean Build Java Command Line

I am compiling my project written using eclipse using the command line as follows

javac file.java

And then to run:

java file (args here)

How would I run a clean build, or compilation? Whenever I recompile, the changes are not getting affected unless I delete all the .class files and recompile. Please note that the the main file will call other classes too.

Thanks

You should compile all the Java files in your application to be sure, basically.

Options include:

  • Use a full build system such as Ant.
  • On a Unix box, use something like:

     javac `find . -name '*.java'`

    assuming you don't have too many (or use xargs if necessary).

  • If you're not using packages (and you really should be) you can just use:

     javac *.java

Here's how I handle this.

rm $(find . -name "*.class")
javac <MainClass>.java
java <MainClass>

It's a simple trick that removes all files ending with the extension ".class". When you compile with javac , it will compile all the files again without you having to worry about directory structure either.

In case you are on windows you can get the alternative for find here.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM