1

We are using Appengine Endpoints Java with Guava and when Function is used inside an endpoint method the API generator returns an exception.

Function is NOT part of the method signature. Its just used inside the method to transform a list. Comment out this body part and it generates OK.

Guava sure is in the classpath, and other parts of the application uses it normally.

I'm not sure its related to Guava or any outside API would give the same error.

The method:

@ApiMethod(
    httpMethod = "GET",
    name = "ledgers.accountgroups.get",
    path="ledgers/{ledgerId}/accountgroups")
public Collection<IAccountGroup> listAccountGroups(@Named("ledgerId") String ledgerId, User user) throws Exception {
collaboratorDAO.assertCollaboratorOn(ledgerId, user);
List<Group> groups = accountGroupsDAO.getAccountGroups(ledgerId);
List<IAccountGroup> transformedGroups = Lists.transform(groups, new Function<Group, IAccountGroup>() {
    @Override
    public IAccountGroup apply(Group group) {
        return group.createClient();
    }
});
return transformedGroups;

}

The exception:

INFO: Successfully processed ./war/WEB-INF/appengine-web.xml
interface com.google.api.server.spi.config.Api
interface com.google.api.server.spi.config.Api
Exception in thread "main" java.lang.NoClassDefFoundError: com/google/common/base/Function
    at java.lang.Class.getDeclaredMethods0(Native Method)
    at java.lang.Class.privateGetDeclaredMethods(Class.java:2436)
    at java.lang.Class.getDeclaredMethods(Class.java:1793)
    at com.google.api.server.spi.MethodHierarchyReader.addServiceMethods(MethodHierarchyReader.java:174)
    at com.google.api.server.spi.MethodHierarchyReader.readMethodHierarchyIfNecessary(MethodHierarchyReader.java:44)
    at com.google.api.server.spi.MethodHierarchyReader.getEndpointOverrides(MethodHierarchyReader.java:99)
    at com.google.api.server.spi.config.annotationreader.ApiConfigAnnotationReader.readEndpointMethods(ApiConfigAnnotationReader.java:215)
    at com.google.api.server.spi.config.annotationreader.ApiConfigAnnotationReader.loadEndpointMethods(ApiConfigAnnotationReader.java:92)
    at com.google.api.server.spi.config.ApiConfigLoader.loadConfiguration(ApiConfigLoader.java:55)
    at com.google.api.server.spi.tools.AnnotationApiConfigGenerator.generateConfigObjects(AnnotationApiConfigGenerator.java:237)
    at com.google.api.server.spi.tools.AnnotationApiConfigGenerator.generateConfig(AnnotationApiConfigGenerator.java:185)
    at com.google.api.server.spi.tools.GenApiConfigAction.genApiConfig(GenApiConfigAction.java:78)
    at com.google.api.server.spi.tools.GetClientLibAction.getClientLib(GetClientLibAction.java:66)
    at com.google.api.server.spi.tools.GetClientLibAction.execute(GetClientLibAction.java:49)
    at com.google.api.server.spi.tools.EndpointsTool.execute(EndpointsTool.java:66)
    at com.google.api.server.spi.tools.EndpointsTool.main(EndpointsTool.java:92)
Caused by: java.lang.ClassNotFoundException: com.google.common.base.Function
    at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
    ... 16 more

It's very simple not to use Guava at this point, and it works. I just want to know why this is happening as I need a more have use of Guava in other parts.

Update:

I think it the same problem as:

Google Cloud Endpoints doesn't know about the Work class from Objectify 4 Transaction, causing ClassNotFoundException

Any tips?

Thanks!

Community
  • 1
  • 1
kcaldas
  • 49
  • 6
  • Please explain your dependencies. Whether you use Guava 1.0 (current stable version is 13.0.1, latest candidate is 14.0-rc3) or you don't have Guava at all in your classpath. – Olivier Grégoire Feb 22 '13 at 11:43
  • Guava version 14.0-rc1 on classpath. I think its not related to Guava. Please take a look at the linked question. – kcaldas Feb 22 '13 at 13:02
  • Yes, I agree with your assessment that it's related to the other question. There appears to be an issue with endpoints.sh picking up other classes during library generation. – Dan Holevoet Feb 22 '13 at 19:13

0 Answers0