@@ -219,6 +219,8 @@ private AnnotationValue getAnnotationValue(AnnotationMirror annotation, String n
219219
220220 private static final String [] SOURCE_ROOTS = {"src/test/java/" , "src/main/java/" };
221221
222+ private static final String [] RESOURCE_ROOTS = {"src/test/resources/" , "src/main/resources/" };
223+
222224 private void writeResource () {
223225 int count = collectedPaths .size ();
224226 if (count > 0 ) {
@@ -229,6 +231,11 @@ private void writeResource() {
229231 "Copying " + count + " demo-source " + (count == 1 ? "file" : "files" ) + " to class output" );
230232 }
231233 for (String sourcePath : collectedPaths ) {
234+ // Files under META-INF/resources/ are already packaged into the JAR by Maven's
235+ // resource-processing phase; the processor does not need to copy them.
236+ if (isFromMetaInfResources (sourcePath )) {
237+ continue ;
238+ }
232239 try {
233240 FileObject source = openSourceFile (sourcePath );
234241 FileObject resource =
@@ -248,6 +255,16 @@ private void writeResource() {
248255 }
249256 }
250257
258+ private static boolean isFromMetaInfResources (String normalizedPath ) {
259+ for (String root : RESOURCE_ROOTS ) {
260+ if (normalizedPath .startsWith (root )) {
261+ String relative = normalizedPath .substring (root .length ());
262+ return relative .startsWith ("META-INF/resources/" ) || relative .equals ("META-INF/resources" );
263+ }
264+ }
265+ return false ;
266+ }
267+
251268 private FileObject openSourceFile (String path ) throws IOException {
252269 for (String root : SOURCE_ROOTS ) {
253270 if (path .startsWith (root )) {
@@ -256,6 +273,17 @@ private FileObject openSourceFile(String path) throws IOException {
256273 .getResource (StandardLocation .SOURCE_PATH , "" , path .substring (root .length ()));
257274 }
258275 }
276+ // Resource files (src/test/resources/, src/main/resources/) are copied to CLASS_OUTPUT
277+ // by Maven's process-*-resources phase, which runs before test-compile (and therefore
278+ // before annotation processors). Read them from CLASS_OUTPUT using the path relative to
279+ // the resources root.
280+ for (String root : RESOURCE_ROOTS ) {
281+ if (path .startsWith (root )) {
282+ return processingEnv
283+ .getFiler ()
284+ .getResource (StandardLocation .CLASS_OUTPUT , "" , path .substring (root .length ()));
285+ }
286+ }
259287 return processingEnv .getFiler ().getResource (StandardLocation .SOURCE_PATH , "" , path );
260288 }
261289}
0 commit comments