0

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 Enabled
    • processor project properties > java compiler > annotations processing > enable annotation processing is Enabled
    • processor project properties > java compiler > annotations processing > enable processing in Editor is Enabled
    • processor project properties > java compiler > annotations processing > Factory Path > Enable project specific settings is Enabled
    • processor 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 that beaninfo.vm and velocity.properties files have been included in the exported JAR. Also make sure the file META-INF/services/javax.annotation.processing.Processor has also been included in the JAR by selecting Export all output folders fro checked projects on the JAR 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 Enabled
    • client project properties > java compiler > annotations processing > enable annotation processing is Enabled
    • client project properties > java compiler > annotations processing > enable processing in Editor is Enabled
    • client project properties > java compiler > annotations processing > Factory Path > Enable project specific settings is Enabled
    • client 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.

foivaras
  • 238
  • 4
  • 11

1 Answers1

0

I'm not an eclipse user. But when I see this message:

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.

I immediately think about a version mismatch. There must still be some 1.4 class or jar files somewhere when you switch to 1.5 ou 1.7.

Please make sure you clean the whole project and remove any 1.4 dependencies when you upgrade.

Claude Brisson
  • 4,085
  • 1
  • 22
  • 30
  • That is a usual cause of corresponding problems others had, according to google and that's why I de-maven-ized the projects in the first place. Even if it is a version mismatch, I still cannot find the way to fix it or narrow down the problem any more. Also tried cleaning whole workspace but still no luck. – foivaras Apr 27 '16 at 14:06