1

The situation is I have a java project which .java files scattered in many sub-folders. I want to use javac to compile all the .java but I tried command below and failed: javac -sourcepath src And error was: javac: no source files Usage: javac use -help for a list of possible options

So what should I do to compile this project? Thank you!

XiaoYao
  • 2,825
  • 3
  • 20
  • 19

2 Answers2

6

-sourcepath specifies where the javac will find the source files, not what files that you want to compile. You can specify the names of the files that you want to compile, e.g. javac -sourcepath src/ File.java AnotherFile.java, etc., it will look for the input files in src/ then. You can use the @ parameter, too, javac will then read the options and files from text file. Or you can use Ant or Maven, tools for automating software building.

But I recommend using an IDE. I love Eclipse, but other IDEs, like NetBeans are ok, too.

m4tx
  • 3,974
  • 4
  • 33
  • 60
  • Apprently, javac will compile all "out of date" files in sourcepath and classpath even if you only specify one valid "source file" option on the command line: `javac -sourcepath src Empty.java` will build all of src that is out of date as long as Empty.java is valid. –  May 06 '13 at 16:30
3

Well, you can use Maven or Ant. Here is a good explanation on that. https://stackoverflow.com/a/5194967/1438132

But for your problem, there is a command called find.

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

or

javac -classpath "${CLASSPATH} -sourcepath src //along with src specify file names.
Community
  • 1
  • 1
Isuru Madusanka
  • 1,327
  • 4
  • 18
  • 27