简体   繁体   English

清理构建 Java 命令行

[英]Clean Build Java Command Line

I am compiling my project written using eclipse using the command line as follows我正在使用命令行编译使用 eclipse 编写的项目,如下所示

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.每当我重新编译时,除非我删除所有.class文件并重新编译,否则更改不会受到影响。 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.基本上,您应该编译应用程序中的所有 Java 文件。

Options include:选项包括:

  • Use a full build system such as Ant.使用完整的构建系统,例如 Ant。
  • On a Unix box, use something like:在 Unix 机器上,使用类似的东西:

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

    assuming you don't have too many (or use xargs if necessary).假设您没有太多(或在必要时使用xargs )。

  • 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".这是一个简单的技巧,可以删除所有以扩展名“.class”结尾的文件。 When you compile with javac , it will compile all the files again without you having to worry about directory structure either.当您使用javac编译时,它将再次编译所有文件,而您也不必担心目录结构。

In case you are on windows you can get the alternative for find here.如果您在 Windows 上,您可以在这里找到替代方法

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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