@Resource.lookup – How to solve classpath problems when compiling or testing with gradle

I’ve started this week with Gradle and tried to convert one project from maven to Gradle.
Besides of some, I think beginner mistakes, I faced with the following problem.

With JEE6 the @Resource annotation was extented with the “lookup” attribute. This attribute links to any resource which uses a global JNDI name.

Something like this:

[code language=”Java”]
public class MainController {
Boolean isProductiveServer;

public Boolean getIsProductiveServer() {
return isProductiveServer;

When you try to compile this as usual, your compilation will fail with this error

MainController.java:5: cannot find symbol
symbol : method lookup()
location: @interface javax.annotation.Resource
@Resource(lookup = “server/isProductive”)

The problem is, that this definition of @Resource is not available in standard JDK6. So when compile / run / test those code you must let the -Djava.endorsed.dirs directive point to the directory where the endorsed api library is located. For maven I found a good guide here. But for Gradle it was a little bit more time-consuming. After all I found a solution in the gradle forum (see here).

I extracted the gradilzed way of maven to add this libraries to “-Djava.endorsed.dirs”.

[code language=”groovy”]
apply plugin: ‘java’
repositories {

configurations {
compile.extendsFrom endorsed

dependencies {
endorsed group:’javax’, name:’javaee-endorsed-api’, version:’6.0′

task stageEndorsed(type: Sync) {
from configurations.endorsed
into temporaryDir

tasks.withType(Compile) {
dependsOn stageEndorsed
options.compilerArgs << "-Djava.endorsed.dirs=${stageEndorsed.destinationDir}"

Finally, it worked and as is expected fast and much better readable than the maven-XML-code

1 Kudos

Leave a Reply

Your email address will not be published. Required fields are marked *