linux to compile multiple java file

我的未来我决定 提交于 2019-12-24 10:20:46

问题


here is my directory structure.

/user/a /user/b /user/b

inside folder a,b,c there is a file person.java (it is the Same file, just a one line modification.

now, on my shell, im on my /user/ directory and i try to do

   javac */person.java

the shell returns the following error,

person.java:14: duplicate class: person

Is there anything to resolve this?


回答1:


I think the problem here might be, that javac tries to compile everything in one go, which naturally results in duplicated class definitions.

A simple way to resolve this would be

find . -name '*.java' -exec javac {} \;

Edit:

Or to be more precise find . -name 'person.java' -maxdepth 2 -exec javac {} \;




回答2:


I would go for the small shell script:

for f in */person.java; do
  javac $file
done

First line find all the files person.java in a sub-directory, second line compile the file.



来源:https://stackoverflow.com/questions/138318/linux-to-compile-multiple-java-file

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!