How to get resouce in eclipse jdt-apt environment?
Asked Answered
M

0

7

I'm developing an annotation processor. And here is a classic maven project structrue.

project
- src/main
  - java // SOURCE_PATH
  - resources // SOURCE_PATH
- target
  - classes // CLASS_PATH and CLASS_OUTPUT
  - generated-sources
    - annotations // SOURCE_OUTPUT

Everything is ok in maven with javac. But when I want to intergrate it into eclipse, I find eclipse apt only support CLASS_OUTPUT and SOURCE_OUTPUT.

I think CLASS_OUTPUT is also ok because it's equals to CLASS_PATH. Then I get the following exception

org.eclipse.core.internal.resources.ResourceException: Resource '/test-annotation-use-processer/target/classes/config.properties' does not exist.
    at org.eclipse.core.internal.resources.Resource.checkExists(Resource.java:335)
    at org.eclipse.core.internal.resources.Resource.checkAccessible(Resource.java:209)
    at org.eclipse.core.internal.resources.File.getContents(File.java:275)
    at org.eclipse.core.internal.resources.File.getContents(File.java:268)
    at org.eclipse.jdt.internal.apt.pluggable.core.filer.IdeInputFileObject.openInputStream(IdeInputFileObject.java:86)

Well, the file does exists in disk. I don't know what's wrong for eclipse.

Is there any workaround to get resource in eclipse apt?

Mikkel answered 3/4, 2018 at 13:22 Comment(4)
Did you create/import the project as a maven project in Eclipse? Eclipse has built-in support for maven projects.Sverdlovsk
@Sverdlovsk Of course. The problem is about 'the built-in support'.Mikkel
do you really keep you 'test-annotation-use-processer' project in the file-system root? Since path to the resource in the stack-trace starts with '/', means that this is an absolute path, not relative to your working dir, right?Bebeeru
@Bebeeru The string (resource uri) is given by Filer. I think it is relative to eclipse workspace (a vitrual path). If not, it is a bug for eclispe.Mikkel

© 2022 - 2024 — McMap. All rights reserved.