I try to follow this tutorial on java code generation utilizing annotations and Velocity template engine. (I'm using eclipse ee mars.)
On the annotated project, annotation processing is enabled and the processor (as an exported jar) is included in Factory Path. the processor has dependencies which are velocity
and velocity-tools
so I included them too in Factory path (velocity-dep is used which contains all velocity's dependencies).
problem is: when I include velocity-dep-1.4.jar everything works fine and code is generated but when I switch to
any other version (1.5 or 1.7) I get error The specified class for ResourceManager (org.apache.velocity.runtime.resource.ResourceManagerImpl) does not implement org.apache.velocity.runtime.resource.ResourceManager; Velocity is not initialized correctly.
on error log.
I need to utilize velocity 1.7 to proceed with my project.
Tried same things on three different pc's with same results.
I have ran out of ideas, any help would be really appreciated.
Update1 (added steps to reproduce in Eclipse):
To generate processor's jar:
clone this github repo:
https://github.com/halx4/question.StackOverflow.velocity-template-engine-configuration-on-eclipse/tree/master
It contains 2 eclipse projects, a processor and an annotated project(client). I have included all dependencies and made them non-maven projects just to make sure the problem is not maven-related.make sure that:
processor project properties > java compiler > annotations processing > enable project specific settings
is Enabledprocessor project properties > java compiler > annotations processing > enable annotation processing
is Enabledprocessor project properties > java compiler > annotations processing > enable processing in Editor
is Enabledprocessor project properties > java compiler > annotations processing > Factory Path > Enable project specific settings
is Enabledprocessor project properties > java compiler > annotations processing > Factory Path > metainf-services-1.1.jar
is Enabled as annotation processor containing JAR. Now it should be possible to export the processor as a (non-executable)JAR. Make sure thatbeaninfo.vm
andvelocity.properties
files have been included in the exported JAR. Also make sure the fileMETA-INF/services/javax.annotation.processing.Processor
has also been included in the JAR by selectingExport all output folders fro checked projects
on theJAR export
menu. The exported jar may be placed in NoMavenClient project's folder. for convenience the processor's JAR(theProcessor.jar) has already been placed in this folder.
To apply annotation processing:
- open eclipse error log (
window > show > error log
) to see messages from the processor - make sure that:
client project properties > java compiler > annotations processing > enable project specific settings
is Enabledclient project properties > java compiler > annotations processing > enable annotation processing
is Enabledclient project properties > java compiler > annotations processing > enable processing in Editor
is Enabledclient project properties > java compiler > annotations processing > Factory Path > Enable project specific settings
is Enabledclient project properties > java compiler > annotations processing > Factory Path > theProcessor.jar , velocity-tools-2.0.jar ,
velocity-1.7-dep.jar
are Enabled as annotation processor containing JARs.
On this stage, hitting Apply will invoke the processor. On the error log view I see "The specified class for ResourceManager..." error message.
*BUT if I include in factory path the files theProcessor.jar , velocity-tools-2.0.jar ,
velocity-dep-1.4.jar
and hit Apply, I get on error log "creating source file ..." which means success.
see image for better understanding: configurations
Update2
- continuing my investigation on the subject, I tried to reproduce the problem in intelliJ IDEA and I simply could not. Everything works fine with velocity 1.4 or 1.7 and code files are generated as expected.
One important (maybe) difference between eclipse's and IDEA's configuration procedure is the place where the annotations processor's dependencies should be declared.
On IDEA, the processors' dependencies are declared as ordinary module's(same as eclipse's ) dependencies
but on eclipse if they are being declared as simple project dependencies in the build path, are not visible by the processor. Instead, they should be declared in
Factory Path
which is the same place where the annotation processors are declared. Still though, the question is not considered answered as I'd better find a solution in eclipse rather than developing the whole project in a new for me IDE. - Also configuring annotation processing through maven seems to result in different behaviour between the two IDEs. On the aforementioned tutorial's page, the author has uploaded (see his comments) a a git repo with maven projects demonstrating what he discusses. cloning this repo on IDEA and compiling, made the annotation processing work without touch any setting as all was configured with maven. I did not even had to package the processor in a jar..! Eclipse did not make any annotation processing out of the box. (and I do have m2e-apt installed; just to clarify)
If anybody tries any of the procedures I try to explicate, and has different results, please let me know.
Still though, the question is not considered answered as I'd better find a solution in eclipse rather than developing the whole project in a new for me IDE.