Eclipse works quite a bit differently than standalone Maven. Maven uses javac
from JDK. By default javac
only processes .java
files and generates .class files in the same directory as .java
sources. Maven asks it to generate classes in a separate directory and javac
only moves .class files there.
The reason for this is that javac
gives you more freedom in organizing your source files than most developers use. For instance javac
does not care if your class is located in a folder structure that mimics declared packages. You can put a module together by putting several .java
files along with some other files like .properties
or .xml
in the same folder. Your .java
files can have different package declarations. For instance you can have files A.java:
package aaa.bbb;
class A {}
and B.java:
package zzz.uuu;
class B {}
If you ask javac
to put classes in a target directory, it will create necessary subfolders for .class
files, that will resemble the package structure. However it cannot do so for properties and xml files, because they do not contain package declarations. Such 'resource' management is left for the build tool.
Maven expects that you put such resources in another source folder (resources). They will be copied to generated package structure, so you should match it in resource folder. This is why it does not copy non-java files in source folders.
Eclipse expects you to put even .java
files in a target package structure and complains if your package declaration does not reflect relative path of the file. This is where you have less freedom compared to bare javac
. Thanks to this rule it can copy resources along with .class files and does not need another 'resource' folder.
You can configure Eclipse to use source folder as output folder. Eclipse will not touch resources in this case.