Building Java package (javac to all files)

后端 未结 3 2131
温柔的废话
温柔的废话 2021-02-07 14:10

How to compile all files in directory to *.class files?

相关标签:
3条回答
  • 2021-02-07 14:31

    Well, this seems pretty obvious, so I may be missing something

    javac *.java
    

    (With appropriate library references etc.)

    Or perhaps:

    javac -d bin *.java
    

    to javac create the right directory structure for the output.

    Were you looking for something more sophisticated? If so, could you give more details (and also which platform you're on)?

    0 讨论(0)
  • 2021-02-07 14:37

    Yet another way using "find" on UNIX is described here:

    http://stas-blogspot.blogspot.com/2010/01/compile-recursively-with-javac.html

    The following two commands will compile all .java files contained within the directory ./src and its subdirectories:

    find ./src -name *.java > sources_list.txt
    javac -classpath "${CLASSPATH}" @sources_list.txt
    

    First, find generates sources_list.txt, a file that contains the paths to the Java source files. Next, javac compiles all these sources using the syntax @sources_list.txt.

    0 讨论(0)
  • Here's a code fragment that I use to build an entire project where, as usual, source files are in a deeply nested hierarchy and there are many .jar files that must go into the classpath (requires UNIX utilities):

    CLASSPATH=
    for x in $(find | grep jar$); do CLASSPATH="$CLASSPATH:$x"; done
    SRC=$(find | grep java$)
    javac -cp "$CLASSPATH" $SRC
    
    0 讨论(0)
提交回复
热议问题