Home » Language IDEs » Java Development Tools (JDT) » APT plugin generated source files classpath issue
APT plugin generated source files classpath issue [message #233690] |
Wed, 02 August 2006 10:09  |
Eclipse User |
|
|
|
Originally posted by: pisymbol.gmail.com
Hello Guys,
I wrote a simple annotation processor plugin that works like a champ in
that it generates the right files in .apt_generated. However, it seems
that when it tries to compile the files, it seems to be missing my
project's classpath (pre-apt-compiled files). I thought that the
..apt_generated files would just see my current project's classpath (I
was wrong).
Is there a way to add the current project's classpath to my plugin's
annotation processor? I realize that -Aclasspath is passed to my
processor but I'm not exactly sure what I need to do with that.
Any help would be much appreciated!
-aps
|
|
| | |
Re: APT plugin generated source files classpath issue [message #233848 is a reply to message #233717] |
Sun, 06 August 2006 13:35   |
Eclipse User |
|
|
|
Originally posted by: pisymbol.gmail.com
Walter Harley wrote:
> "Alexander" <pisymbol@gmail.com> wrote in message
> news:eaqbmo$lic$1@utils.eclipse.org...
>> Hello Guys,
>>
>> I wrote a simple annotation processor plugin that works like a champ in
>> that it generates the right files in .apt_generated. However, it seems
>> that when it tries to compile the files, it seems to be missing my
>> project's classpath (pre-apt-compiled files). I thought that the
>> .apt_generated files would just see my current project's classpath (I was
>> wrong).
>>
>> Is there a way to add the current project's classpath to my plugin's
>> annotation processor? I realize that -Aclasspath is passed to my
>> processor but I'm not exactly sure what I need to do with that.
>>
>> Any help would be much appreciated!
>
>
> Hi, Alexander.
>
> The compilation classpath for generated files is the same as that for the
> non-generated ones; they're all considered part of the same project. The
> annotation processor generates files and (perhaps) errors, but it does not
> compile anything, that's all done by the same JDT core compiler.
>
> Can you be more specific about the compilation error you're encountering?
Walter, thanks for responding! I was traveling so sorry for the delay
in response.
Okay, what I have is a simple Java class that gets transformed into an
EJB3 bean. The JBoss IDE plugin is installed and the EJB3 classpath
container libraries are configured as part of the project and part of
the ".classpath" of my project. However, if I use
filer.createSourceFile() and see the generated file in
..apt_generated/<package path>, Eclipse can not resolve the CLASSPATH
within my project, i.e. red squiggly lines. Its really weird. Even
after I do a Project->Clean with the generated file, it can not see the
EJB annotation references.
Any clue?
I have been able to work around htis by generating a text file and using
ant rules.
Another issue I have is the APT ANT task has ZERO documentation. Can
you PLEASE point me on how to use that?
Thanks!
-aps
|
|
|
Re: APT plugin generated source files classpath issue [message #234000 is a reply to message #233848] |
Tue, 08 August 2006 16:40   |
Eclipse User |
|
|
|
Originally posted by: wharley.bea.com
"Alexander" <pisymbol@gmail.com> wrote in message
news:eb598g$ch6$1@utils.eclipse.org...
>
> Okay, what I have is a simple Java class that gets transformed into an
> EJB3 bean. The JBoss IDE plugin is installed and the EJB3 classpath
> container libraries are configured as part of the project and part of the
> ".classpath" of my project. However, if I use filer.createSourceFile()
> and see the generated file in .apt_generated/<package path>, Eclipse can
> not resolve the CLASSPATH within my project, i.e. red squiggly lines. Its
> really weird. Even after I do a Project->Clean with the generated file,
> it can not see the EJB annotation references.
Sorry, still not quite understanding you. Do you mean that in your
(hand-written) code, you are seeing red squiggles for the references to
generated classes?
You should have an entry in the Java Build Path dialog for the
..apt_generated folder, as an additional source folder. (The entry should be
automatically created at the same time that you enable annotation processing
for the project.) Is that entry present?
> Another issue I have is the APT ANT task has ZERO documentation. Can you
> PLEASE point me on how to use that?
I've asked another member of the team to respond to that part of your
question.
Thanks,
-walter
|
|
| |
Re: APT plugin generated source files classpath issue [message #234275 is a reply to message #234000] |
Fri, 11 August 2006 12:16   |
Eclipse User |
|
|
|
Originally posted by: pisymbol.gmail.com
Walter Harley wrote:
> "Alexander" <pisymbol@gmail.com> wrote in message
> news:eb598g$ch6$1@utils.eclipse.org...
>> Okay, what I have is a simple Java class that gets transformed into an
>> EJB3 bean. The JBoss IDE plugin is installed and the EJB3 classpath
>> container libraries are configured as part of the project and part of the
>> ".classpath" of my project. However, if I use filer.createSourceFile()
>> and see the generated file in .apt_generated/<package path>, Eclipse can
>> not resolve the CLASSPATH within my project, i.e. red squiggly lines. Its
>> really weird. Even after I do a Project->Clean with the generated file,
>> it can not see the EJB annotation references.
>
> Sorry, still not quite understanding you. Do you mean that in your
> (hand-written) code, you are seeing red squiggles for the references to
> generated classes?
No, I'm seeing squiggles in the .apt_generated code.
> You should have an entry in the Java Build Path dialog for the
> .apt_generated folder, as an additional source folder. (The entry should be
> automatically created at the same time that you enable annotation processing
> for the project.) Is that entry present?
Yes it is and all is well. For example, I have in my src/java source
folder:
com/blah/blah/Source.java
My plugin is installed. As I save the Source.java file a new file gets
created in:
..apt_generated/com/blah/blah/NewSource.java
This NewSource.java has EJB annotation references that are in my
project's classpath (i.e. if I use the SAME annotations within my
current project source folder they resolve). HOWEVER, for some reason
Eclipse does not want to recognize these references in my generated
files.
Does that make sense?
Btw, I'm using the JBoss plugin which creates a Classpath Container
reference in my .classpath to the proper EJB3 libraries in JBoss client
directory (and ejb3.deployer).
I think the issue is that APT or at least the classpath passed to APT is
not honoring my project's classpath container definition from the
plugin. That is my only guess without investigating source.
>> Another issue I have is the APT ANT task has ZERO documentation. Can you
>> PLEASE point me on how to use that?
>
> I've asked another member of the team to respond to that part of your
> question.
Thanks Walter, that would be really helpful.
-aps
|
|
|
Re: APT plugin generated source files classpath issue [message #234282 is a reply to message #234008] |
Fri, 11 August 2006 12:18   |
Eclipse User |
|
|
|
Originally posted by: pisymbol.gmail.com
Jess Garms wrote:
>
>> Another issue I have is the APT ANT task has ZERO documentation. Can
>> you PLEASE point me on how to use that?
>
> Under help, you can find the following entry:
>
> JDT Plug-in Developer Guide -> JDT Annotation Processing -> Headless Build
>
> This gives some information on how to use the apt ant task to build a
> workspace, but it is slightly out of date on the location of a jar file.
> Below is the content of that help entry.
>
> -------------------------------------------------
> Building with Ant
> Again, you will need an installation of Eclipse with the APT plugin
> installed. Given this, the "apt" task can be invoked with the following
> xml in your build.xml file:
> <project name="test_eclipse" default="build" basedir=".">
>
> <taskdef name="apt" classname="org.eclipse.jdt.apt.core.build.JdtApt"/>
>
> <target name="build">
> <apt workspace="%WORKSPACE%" eclipseHome="%ECLIPSE_HOME%"/>
> </target>
>
> </project>
>
> You will need to add the jar for APT to your ant installation's lib
> directory, or place it on the classpath when invoking ant. The jar lives in
> %ECLIPSE_HOME%/plugins/org.eclipse.jdt.apt.core_X/aptcore.ja r
> --------------------------------------------------
>
> Update: the jar is no longer inside the plugin, but is the plugin itself:
>
> %ECLIPSE_HOME%/plugins/org.eclipse.jdt.apt.core_3.2.0.v20060 602-1740.jar
>
> We'll update the docs to reflect that.
>
> Let me know if you have any other questions.
>
> Cheers,
> Jess Garms
Thanks Jess, saw this in the doc but to be honest, this is borderline
unusable. Also, why isn't the apt task just part of the APACHE ANT of
3.2 in perhaps contrib. Why make me reference that file within my ANT
build.xml? This is one area of Eclipse that drives me nuts (ANT and
Eclipse's ANT build reconciliation).
-aps
|
|
|
Re: APT plugin generated source files classpath issue [message #234430 is a reply to message #234275] |
Mon, 14 August 2006 16:12   |
Eclipse User |
|
|
|
Originally posted by: wharley.bea.com
"Alexander" <pisymbol@gmail.com> wrote in message
news:ebiagk$23e$1@utils.eclipse.org...
> [...]
> Yes it is and all is well. For example, I have in my src/java source
> folder:
>
> com/blah/blah/Source.java
>
> My plugin is installed. As I save the Source.java file a new file gets
> created in:
>
> .apt_generated/com/blah/blah/NewSource.java
>
> This NewSource.java has EJB annotation references that are in my project's
> classpath (i.e. if I use the SAME annotations within my current project
> source folder they resolve). HOWEVER, for some reason Eclipse does not
> want to recognize these references in my generated
> files.
I'm still having a bit of a hard time understanding your situation. Am I
right about the following?
- You have an annotation processor of your own, that reads annotations of
your own on a plain Java file and generates an EJB.
- The EJB contains EJB-related annotations that should be coming from the
JBoss libraries, by way of the JBoss classpath container. But, those
annotations are instead causing compilation errors: that is, when you try to
compile the generated EJB code, you get errors on the annotations.
So, if my understanding is correct:
Precisely what errors are being reported?
Are you sure the code that your processor is generating is actually correct?
In particular, are there import statements for the annotations? Do the
generated files compile properly if you take them and simply copy them into
another JBoss-enabled project, as if you had typed them by hand? APT is
responsible for generating code, but once the code is generated, compilation
happens exactly the same way that it would for user-created code.
> Btw, I'm using the JBoss plugin which creates a Classpath Container
> reference in my .classpath to the proper EJB3 libraries in JBoss client
> directory (and ejb3.deployer).
Does it make any difference if you add the libraries to the classpath
explicitly, rather than relying on the JBoss classpath container?
> I think the issue is that APT or at least the classpath passed to APT is
> not honoring my project's classpath container definition from the plugin.
> That is my only guess without investigating source.
APT doesn't do any compilation. It just runs processors. Compilation
errors come from the compiler. When processors request information about
types, that information comes from the compiler, using the same
(project-wide) compiler classpath that it uses for all the other files in
the project.
Processors can also explicitly create errors, by calling methods on the
Messager interface, but it doesn't sound like the errors you're talking
about are coming from your processor. I can't tell for sure until you tell
me what the errors are.
Thanks,
-walter
|
|
|
Re: APT plugin generated source files classpath issue [message #234580 is a reply to message #234430] |
Wed, 16 August 2006 18:21   |
Eclipse User |
|
|
|
Originally posted by: pisymbol.gmail.com
Walter Harley wrote:
> "Alexander" <pisymbol@gmail.com> wrote in message
> news:ebiagk$23e$1@utils.eclipse.org...
>> [...]
>> Yes it is and all is well. For example, I have in my src/java source
>> folder:
>>
>> com/blah/blah/Source.java
>>
>> My plugin is installed. As I save the Source.java file a new file gets
>> created in:
>>
>> .apt_generated/com/blah/blah/NewSource.java
>>
>> This NewSource.java has EJB annotation references that are in my project's
>> classpath (i.e. if I use the SAME annotations within my current project
>> source folder they resolve). HOWEVER, for some reason Eclipse does not
>> want to recognize these references in my generated
>> files.
>
> I'm still having a bit of a hard time understanding your situation. Am I
> right about the following?
>
> - You have an annotation processor of your own, that reads annotations of
> your own on a plain Java file and generates an EJB.
>
> - The EJB contains EJB-related annotations that should be coming from the
> JBoss libraries, by way of the JBoss classpath container. But, those
> annotations are instead causing compilation errors: that is, when you try to
> compile the generated EJB code, you get errors on the annotations.
>
> So, if my understanding is correct:
>
> Precisely what errors are being reported?
The annotations are not being resolved. Plain and simple. If I copy
the generated source file under a normal EJB3 project (JBoss plugin
1.6.0 GA I think), they are resolved without a problem. Its only within
my project that uses APT. The one workaround I was using again was to
just createTextFile instead of createSourceFile which for some reason
doens't cause Eclipse any grief (looks like it ignores the file for
compilation) - its like the compiler ignores these files. Then I build
with ANT and all is good.
Btw, an ANT build which references the EJB3 libraries directly also
works. Its only Eclipse that is having the issue with resolving the
annotations via the JBoss IDE classpath container variable.
> Are you sure the code that your processor is generating is actually correct?
Absolutely! An ANT compile and deploy proves it.
> In particular, are there import statements for the annotations?
Yup, its part of the template I'm using.
Do the
> generated files compile properly if you take them and simply copy them into
> another JBoss-enabled project, as if you had typed them by hand?
Yes.
> APT is
> responsible for generating code, but once the code is generated, compilation
> happens exactly the same way that it would for user-created code.
Right, but doesn't APT pass the CLASSPATH to JAVAC at some point? I
thought APT degenerates into a JAVAC if no annotations are found
(essentially).
>> Btw, I'm using the JBoss plugin which creates a Classpath Container
>> reference in my .classpath to the proper EJB3 libraries in JBoss client
>> directory (and ejb3.deployer).
>
> Does it make any difference if you add the libraries to the classpath
> explicitly, rather than relying on the JBoss classpath container?
Yes. Seems like there is some issue with using a classpath container
variable and the APT plugin framework (I would expect it to honor any
classpath container variables).
> APT doesn't do any compilation. It just runs processors. Compilation
> errors come from the compiler. When processors request information about
> types, that information comes from the compiler, using the same
> (project-wide) compiler classpath that it uses for all the other files in
> the project.
Then this should WORK! (as expected)
> Processors can also explicitly create errors, by calling methods on the
> Messager interface, but it doesn't sound like the errors you're talking
> about are coming from your processor. I can't tell for sure until you tell
> me what the errors are.
Definitely compilation errors at this point. The processor does it job,
generates the source files and exits. At that point, I see the new
files under .apt_generated/<package>/*/*.java and I get squiggly lines
on JUST the JBoss annotations. Project->Clean, Refresh (F5), etc.
doesn't help. There are other classes and methods I'm referencing from
my own JAR file that resolve perfectly but they are added manually on my
build path, i.e. they are in .classpath as "lib" not "con" etc.
Sorry for not getting back quicker, I've been travelling and this exact
project has been on hold a bit.
I'm just trying to understand if this is pilot error on my part or a
real bug in the framework! :D!
-aps
|
|
|
Re: APT plugin generated source files classpath issue [message #234590 is a reply to message #234430] |
Wed, 16 August 2006 18:23   |
Eclipse User |
|
|
|
Originally posted by: pisymbol.gmail.com
Walter Harley wrote:
> "Alexander" <pisymbol@gmail.com> wrote in message
> news:ebiagk$23e$1@utils.eclipse.org...
>> [...]
>> Yes it is and all is well. For example, I have in my src/java source
>> folder:
>>
>> com/blah/blah/Source.java
>>
>> My plugin is installed. As I save the Source.java file a new file gets
>> created in:
>>
>> .apt_generated/com/blah/blah/NewSource.java
>>
>> This NewSource.java has EJB annotation references that are in my project's
>> classpath (i.e. if I use the SAME annotations within my current project
>> source folder they resolve). HOWEVER, for some reason Eclipse does not
>> want to recognize these references in my generated
>> files.
>
> I'm still having a bit of a hard time understanding your situation. Am I
> right about the following?
>
> - You have an annotation processor of your own, that reads annotations of
> your own on a plain Java file and generates an EJB.
>
> - The EJB contains EJB-related annotations that should be coming from the
> JBoss libraries, by way of the JBoss classpath container. But, those
> annotations are instead causing compilation errors: that is, when you try to
> compile the generated EJB code, you get errors on the annotations.
>
> So, if my understanding is correct:
>
> Precisely what errors are being reported?
The annotations are not being resolved. Plain and simple. If I copy
the generated source file under a normal EJB3 project (JBoss plugin
1.6.0 GA I think), they are resolved without a problem. Its only within
my project that uses APT. The one workaround I was using again was to
just createTextFile instead of createSourceFile which for some reason
doens't cause Eclipse any grief (looks like it ignores the file for
compilation) - its like the compiler ignores these files. Then I build
with ANT and all is good.
Btw, an ANT build which references the EJB3 libraries directly also
works. Its only Eclipse that is having the issue with resolving the
annotations via the JBoss IDE classpath container variable.
> Are you sure the code that your processor is generating is actually correct?
Absolutely! An ANT compile and deploy proves it.
> In particular, are there import statements for the annotations?
Yup, its part of the template I'm using.
Do the
> generated files compile properly if you take them and simply copy them into
> another JBoss-enabled project, as if you had typed them by hand?
Yes.
> APT is
> responsible for generating code, but once the code is generated, compilation
> happens exactly the same way that it would for user-created code.
Right, but doesn't APT pass the CLASSPATH to JAVAC at some point? I
thought APT degenerates into a JAVAC if no annotations are found
(essentially).
>> Btw, I'm using the JBoss plugin which creates a Classpath Container
>> reference in my .classpath to the proper EJB3 libraries in JBoss client
>> directory (and ejb3.deployer).
>
> Does it make any difference if you add the libraries to the classpath
> explicitly, rather than relying on the JBoss classpath container?
Yes. Seems like there is some issue with using a classpath container
variable and the APT plugin framework (I would expect it to honor any
classpath container variables).
> APT doesn't do any compilation. It just runs processors. Compilation
> errors come from the compiler. When processors request information about
> types, that information comes from the compiler, using the same
> (project-wide) compiler classpath that it uses for all the other files in
> the project.
Then this should WORK! (as expected)
> Processors can also explicitly create errors, by calling methods on the
> Messager interface, but it doesn't sound like the errors you're talking
> about are coming from your processor. I can't tell for sure until you tell
> me what the errors are.
Definitely compilation errors at this point. The processor does it job,
generates the source files and exits. At that point, I see the new
files under .apt_generated/<package>/*/*.java and I get squiggly lines
on JUST the JBoss annotations. Project->Clean, Refresh (F5), etc.
doesn't help. There are other classes and methods I'm referencing from
my own JAR file that resolve perfectly but they are added manually on my
build path, i.e. they are in .classpath as "lib" not "con" etc.
Sorry for not getting back quicker, I've been travelling and this exact
project has been on hold a bit.
I'm just trying to understand if this is pilot error on my part or a
real bug in the framework! :D!
-aps
|
|
|
Re: APT plugin generated source files classpath issue [message #234645 is a reply to message #234590] |
Thu, 17 August 2006 13:22  |
Eclipse User |
|
|
|
Originally posted by: wharley.bea.com
"Alexander" <pisymbol@gmail.com> wrote in message
news:ec05ti$s5q$2@utils.eclipse.org...
>> Precisely what errors are being reported?
>
> The annotations are not being resolved. Plain and simple.
Okay. We've established that there are red squiggly lines. Is there hover
text if you dangle over the squiggly? If so, exactly what is the text? Are
there any problems reported in the problems pane, after you do a build? If
so, what is the full text of the problem? Is there anything in the error
log?
I'm sorry, I'm sure it seems plain and simple at your end, but I'm not
looking at your monitor and from my perspective it's hard to know what
you're seeing.
> If I copy
> the generated source file under a normal EJB3 project (JBoss plugin
> 1.6.0 GA I think), they are resolved without a problem.
Good, thanks.
> Right, but doesn't APT pass the CLASSPATH to JAVAC at some point? I
> thought APT degenerates into a JAVAC if no annotations are found
> (essentially).
Not in Eclipse. In Eclipse, APT is implemented as a "compilation
participant" - essentially a separate build step that is allowed to
contribute new types, which then trigger another round of compilation. In
other words, APT's relationship to the compiler is strictly dependent; it
does not pass anything *to* the compiler (except for a list of newly
generated files), it gets everything *from* the compiler. All compilation
is done by the compiler, and it is done with exactly the same classpath, and
other compiler settings, as it would be if the code were static rather than
generated.
The one caveat there is that, when annotation processing is first enabled
for a project, the APT code causes the generated source folder to be added
to the classpath. But that's a one-time action that either works or it
doesn't - after it's done, there is no distinction between whether the entry
was added manually or automatically. There is no APT classpath container;
we do not modify the classpath on the fly in any way. (We tried to, at
first; it caused a lot of headaches.)
But it's possible that the implementation of the JBoss classpath container
is doing something that is somehow incompatible with types being modified on
the fly. I don't know what that would be, but that's why I'm trying to
figure out what's going on here.
Is it possible to add the JBoss libraries directly to the classpath of this
project, as an experiment, rather than relying on the JBoss classpath
container?
> I'm just trying to understand if this is pilot error on my part or a
> real bug in the framework! :D!
Thus far, it doesn't seem like you're doing anything wrong.
|
|
|
Goto Forum:
Current Time: Tue Sep 16 17:23:23 EDT 2025
Powered by FUDForum. Page generated in 0.04695 seconds
|