Search code examples
bashfindjavac

Passing multiple java files to javac with find


I have this:

javac -d "$PWD/target/classes" \
      -cp "$CLASSPATH:$PWD/src/main/java" \
      "$(find "$PWD/src/main/java/huru" -name '*.java')"

but I get:

javac: file not found: /home/oleg/codes/oresoftware/vertx.api/src/main/java/huru/Foo.java
/home/oleg/codes/oresoftware/vertx.api/src/main/java/huru/entity/BaseModel.java
/home/oleg/codes/oresoftware/vertx.api/src/main/java/huru/entity/InterfaceContainer.java
/home/oleg/codes/oresoftware/vertx.api/src/main/java/huru/entity/KCClassEntity.java
/home/oleg/codes/oresoftware/vertx.api/src/main/java/huru/entity/BaseEntity.java
/home/oleg/codes/oresoftware/vertx.api/src/main/java/huru/entity/UserModel.java
/home/oleg/codes/oresoftware/vertx.api/src/main/java/huru/query/QueryBuilder.java
/home/oleg/codes/oresoftware/vertx.api/src/main/java/huru/TestVerticle.java
/home/oleg/codes/oresoftware/vertx.api/src/main/java/huru/middleware/JWTHandler.java

so I tried using xargs to put it on one line:

javac -d "$PWD/target/classes" \
      -cp "$CLASSPATH:$PWD/src/main/java:$m2" \
      "$(find "$PWD/src/main/java/huru" -name '*.java' | xargs)"

but then I get:

javac: file not found: /home/oleg/codes/oresoftware/vertx.api/src/main/java/huru/Foo.java /home/oleg/codes/oresoftware/vertx.api/src/main/java/huru/entity/BaseModel.java /home/oleg/codes/oresoftware/vertx.api/src/main/java/huru/entity/InterfaceContainer.java /home/oleg/codes/oresoftware/vertx.api/src/main/java/huru/entity/KCClassEntity.java /home/oleg/codes/oresoftware/vertx.api/src/main/java/huru/entity/BaseEntity.java /home/oleg/codes/oresoftware/vertx.api/src/main/java/huru/middleware/ErrorHandler.java /home/oleg/codes/oresoftware/vertx.api/src/main/java/huru/util/Asyncc.java /home/oleg/codes/oresoftware/vertx.api/src/main/java/huru/routes/IBasicHandler.java /home/oleg/codes/oresoftware/vertx.api/src/main/java/huru/routes/RouteHelper.java

where xargs puts everything in one line. All these java files exist, the paths are correct, but it's clear that the results from find aren't work. Does anyone know how to do this right?


Solution

  • So one technique is to use a temp file (which sucks but it works):

    find . -name '.java' >  my.files
    javac @my.files
    

    yes the @ character is necessary, according to javac spec, so java knows it's a file to read.

    but I am still looking for a way to find the results of find directly to javac instead of having to use a temp file.