1

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
  • Are the classes exactly the same, with the same package definition on top? Commented Sep 26, 2008 at 8:48

2 Answers 2

8

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 {} \;

Sign up to request clarification or add additional context in comments.

1 Comment

Here you compile all the file ending in .java, not only the person.java files. Also you don't restrict to one level of subdirectory.
1

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.

2 Comments

in a shell, is there a well to type the above for loop "in" the console, so i dont have to create a separate .sh file?
Yes, just type it as you see it here, or optionally put it all on one line: for f in */person.java; do javac $file; done

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.