Google App Engine using maven - google-app-engine

I've been trying to create a single project which can run both on sql and gae (where the 'datanucleus.properties' file needs to be changed) under a single maven folder structure. I first tried to get the Greeting example on the GAE website using mysql (this now works). Then, inspiring myself from beardedgeeks tutorial, I have tried to add the required dependencies so as to run the stuff on gae. By typing in mvn gae:run, however, I get the following error, posted at http://pastebin.com/fJ7c7xfx. I have spent a large amount of time searching google etc. for answers, but haven't been able to advance my case.
I would be glad to get some pointers.
Cheers,
manojo

This question is tagged [JDO] but the following trace:
Caused by: java.lang.ClassNotFoundException: javax.persistence.InheritanceType
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:307)
at com.google.appengine.tools.development.IsolatedAppClassLoader.loadClass(IsolatedAppClassLoader.java:151)
at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
... 77 more
suggests that you're missing the JPA API jar (provided by org.apache.geronimo.specs:geronimo-jpa_1.0_spec:1.1.1).
<dependency>
<groupId>org.apache.geronimo.specs</groupId>
<artifactId>geronimo-jpa_3.0_spec</artifactId>
<version>1.1.1</version>
</dependency>
Since you're not using JPA, you shouldn't have to do that but it appears that the JPA API is somehow referenced by the datanucleus appengine plugin as explained by #Datanucleus.

The people at Google unwisely put a reference in to that JPA class in their plugin and so it requires that you have the jpa.jar (the Geronimo one will do) in your CLASSPATH. An issue was raised on them a long time ago to fix it, but sadly they don't actively maintain their plugin.

Related

Firebase access within GAE

It seems that the latest sdk com.google.firebase:firebase-server-sdk:3.0.0 relies on creating threads for most calls, e.g., com.google.firebase.database.FirebaseDatabase.getReference
This is a problem when using GAE since it promptly throws an Exception:
servlet java.security.AccessControlException: access denied ("java.lang.RuntimePermission" "modifyThreadGroup")
Are we suppoed to just use the JVM sdk (com.firebase:firebase-client-jvm) instead?
The instructions aren't so clear and it seems like the legacy website is the only one where we can get the secret. The new website gives us the .json file.
Has anyone had any success with using the new v3 version with GAE?
Yes. Just tested.
As with the 2.x SDKs, you can work around the threading limitation by using manual scaling.
While the Cloud guide on using Firebase with GAE is a bit outdated, the section on manual scaling should still be useful to help you through this.
More on ThreadManager here.
I was experiencing the same problem and discovered the cause in this blog thread.
When adding dependences, I had included appengine-java-sdk but overlooked appengine-api-1.0-sdk. Adding it eliminated the exception. The full dependencies block is:
dependencies {
appengineSdk 'com.google.appengine:appengine-java-sdk:1.9.48'
compile 'javax.servlet:servlet-api:2.5'
compile 'com.google.firebase:firebase-server-sdk:3.0.3'
compile 'com.google.appengine:appengine-api-1.0-sdk:1.9.48'
}
Include the JSON file in the "Resource Files" of appengine-web.xml.
Example:
<resource-files>
<include path="/**.xml" />
<exclude path="/feeds/**.xml" />
</resource-files>
See the link https://cloud.google.com/appengine/docs/java/config/appref#resource_files .
"The files that listed in the element are accessible by the application code using the filesystem. These files are stored on the application servers with the app as opposed to how static files are stored and served.".

GAE: java.lang.NoSuchMethodError: com.google.api.client.json.GenericJson.set

Starting from June, 12 my app that is used DriveAPI faced the following error (it's shown in GAE server log):
java.lang.NoSuchMethodError: com.google.api.client.json.GenericJson.set(Ljava/lang/String;Ljava/lang/Object;)Lcom/google/api/client/json/GenericJson;
at com.google.api.client.googleapis.auth.oauth2.GoogleClientSecrets$Details.set(GoogleClientSecrets.java:166)
at com.google.api.client.googleapis.auth.oauth2.GoogleClientSecrets$Details.set(GoogleClientSecrets.java:87)
at com.google.api.client.json.JsonParser.parse(JsonParser.java:357)
at com.google.api.client.json.JsonParser.parseValue(JsonParser.java:586)
at com.google.api.client.json.JsonParser.parse(JsonParser.java:350)
at com.google.api.client.json.JsonParser.parseValue(JsonParser.java:586)
at com.google.api.client.json.JsonParser.parse(JsonParser.java:289)
at com.google.api.client.json.JsonParser.parse(JsonParser.java:266)
at com.google.api.client.json.JsonParser.parseAndClose(JsonParser.java:141)
at com.google.api.client.json.JsonFactory.fromInputStream(JsonFactory.java:223)
at com.google.api.client.googleapis.auth.oauth2.GoogleClientSecrets.load(GoogleClientSecrets.java:195)
at finbudget.server.handlers.lists.cronimport.AutoImportBackend.doImport(AutoImportBackend.java:112)
at finbudget.server.handlers.lists.cronimport.AutoImportBackend.doPost(AutoImportBackend.java:76)
......
It seems like this problem comes with 1.8.1 version of AppEngine release. Before it worked well... Did someone have the same problem? And what could be the solution for this?
It's a classpath collision.
If war/WEB-INF/lib contains multiple versions of the DriveAPI jars, strange issues may result from the wrong version loading during runtime. Removing outdated jars solves the problem.
(Note: I copied and formatted the answer that the original asker added to the question via an edit. I did this as a cleanup task.)

Jersey linking support with Google App Engine issue

I didn't manage to use the Jersey linking support with Google App Engine, I'm getting these exceptions when trying to access the application :
Caused by: javax.el.ELException: Could not find expression factory class
...
Caused by: java.lang.ClassNotFoundException: de.odysseus.el.ExpressionFactoryImpl
As specified in the documentation, I put this in the Jersey servlet section of the web.xml :
<init-param>
<param-name>com.sun.jersey.spi.container.ContainerResponseFilters</param-name>
<param-value>com.sun.jersey.server.linking.LinkFilter</param-value>
</init-param>
I also add the jersey-server-linking-1.13.jar to the WEB-INF/lib directory of my project.
I tried to add el-api.jar first, then juel-2.1.0.jar to the WEB-INF/lib directory but I'm still getting these errors.
I'd like to know if someone could give me some hints about the way to deal with this. When I don't use the Jersey linking jar, everything is working as expected.
I had a similar problem with my GAE app. It was working fine with el-api and el-impl but started asking for de.odysseus.el.ExpressionFactoryImpl as development progressed. I made the switch but when I added JUEL to my pom.xml, I got the same error as John Prince (java.security.AccessControlException).
The solution for GAE users is to use JUEL 2.2.7.
At the time of this writing, 2.2.7 is not available in maven central. However, you can find it on
<repository>
<id>repo-id</id>
<name>repo-name</name>
<url>https://oss.sonatype.org/content/repositories/snapshots/</url>
</repository>
and link with whatever you need from
<dependency>
<groupId>de.odysseus.juel</groupId>
<artifactId>juel-api</artifactId>
<version>2.2.7-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>de.odysseus.juel</groupId>
<artifactId>juel-impl</artifactId>
<version>2.2.7-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>de.odysseus.juel</groupId>
<artifactId>juel-spi</artifactId>
<version>2.2.7-SNAPSHOT</version>
</dependen
Source: https://github.com/beckchr/juel/issues/73
The issue is due to de.odysseus.el.ExpressionFactoryImpl class not being found. I will assume that you have added the jars as you have mentioned to the WEB-INF\lib folder.
I would suggest that you view the JAR files via theProject Explorer , simple expand them in Eclipse and see if you can find the de.odysseus.el.ExpressionFactoryImpl class in ny of the JAR files that you have added.
I "solved" the problem by adding "juel" and "juel-impl" as dependencies of my project (we're using Maven; if you're doing it manually, you might have to figure out exactly what those projects contain).
However, as soon as I did that, I started getting a different exception:
java.security.AccessControlException: access denied (java.io.FilePermission C:\Program Files (x86)\Java\jdk1.6.0_33\jre\lib\el.properties read)
at java.security.AccessControlContext.checkPermission(AccessControlContext.java:374)
at java.security.AccessController.checkPermission(AccessController.java:546)
at java.lang.SecurityManager.checkPermission(SecurityManager.java:532)
at com.google.appengine.tools.development.DevAppServerFactory$CustomSecurityManager.checkPermission(DevAppServerFactory.java:289)
...
I'm pretty sure that's because it's running afoul of GAE restrictions.
I noticed in the original ClassNotFound exception it was trying to use the URLClassLoader; I'm also wondering if that problem was ultimately a GAE issue as well.
At this point, it seems like Jersey linking support isn't compatible with GAE.
This issue is (or rather was) due to a missing implementation of the Unified Expression Language. The EL API defines a static method that looks up an implementation of the ExpressionFactory class. There are various ways to define which implementation is to be used:
Use the Services API (as detailed in the JAR specification). If a resource with the name of META-INF/services/javax.el.ExpressionFactory exists, then its first line, if present, is used as the UTF-8 encoded name of the implementation class.
Use the properties file "lib/el.properties" in the JRE directory. If this file exists and it is readable by the java.util.Properties.load(InputStream) method, and it contains an entry whose key is "javax.el.ExpressionFactory", then the value of that entry is used as the name of the implementation class.
Use the javax.el.ExpressionFactory system property. If a system property with this name is defined, then its value is used as the name of the implementation class.
Use a platform default implementation.
(Source: http://docs.oracle.com/javaee/7/api/javax/el/ExpressionFactory.html#newInstance())
App Engine appears to have defined JUEL as default implementation but does not provide the respective packages.
In order to solve this, you need to (1) provide EL API and implementation packages and (2) use one of the above ways to link it. See https://stackoverflow.com/a/19814199/2099217 for details.

Getting Started with GWT RequestFactory

I'm new to GWT. I've manage to do the tutorial about how to build the simple StockWatcher application.
Now, I want to load the data from the server. After reading about the many different ways to do it in GWT I decide to use RequestFactory because apparently it the most affective way to write maintainable application.
The problem is that there is no tutorial about RequestFactory and Eclipse is hard enough to manage when you know if, it even harder to manage when I'm using a new tool like GWT.
I've manage to find the different jars required for RequestFactory like
gwt-servlet.jar
gwt-servlet-deps.jar
requestfactory-server.jar
Now I get the following error:
java.lang.RuntimeException: The RequestFactory ValidationTool must be run for the com.google.gwt.sample.stockwatcher.shared.service.StockWatcherRequestFactory RequestFactory type
I've even found a direction for this as well: RequestFactoryInterfaceValidation
but it's still not working.
I've add the com.google.web.bindery.requestfactory.apt.ValidationTool to my build path and it seem to help (the message was gone) but then I got different error message.
I've push the source to github repository.
Any help will be great.
I'll try to make a post once I'll manage to get this working so other can use it.
Thank you,
Ido.
I figure this out. object is not an instance of declaring class means that we try to invoke a instance method on object which is not of the type the method is declared on.
My mistake was that in my ServiceLocator implementation I mistakably return an instance of my domain model object (StockQuote) instead of the DAO (StockQuoteDao). This cause RequestFactory code to try and invoke StockQuoteDao.getNum method on StockQuote instance.
Ido.
If you are using google plugin for eclipse use this
http://vivagwt.blogspot.com/2011/09/requestfactory-en-gwt-24.html
you need rebuild you project every time you change you requestcontext
note: gwt-servlet.jar is needed if you use RPC
Also you may automatically run RequestFactory ValidationTool with maven in compiling phase:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<forceJavacCompilerUse>true</forceJavacCompilerUse>
</configuration>
<dependencies>
<dependency>
<groupId>com.google.web.bindery</groupId>
<artifactId>requestfactory-apt</artifactId>
<version>2.6.1</version>
</dependency>
</dependencies>
</plugin>

jTwitter, oAuth, and Google App Engine. NoClassDefFoundError

I'm trying to use jTwitter to get an oauth instance to twitter with my consumer key/secret and access token/secret. This is well documented in the javadoc here. I have downloaded signpost, signpost-jetty, and the jtwitter library, but after deploying and running the servlet, I get a error java.lang.NoClassDefFoundError: winterwell/jtwitter/OAuthSignpostClient Eclipse isn't complaining about the class not being there, because it is there-- I can see it in the JAR file itself, which is in my project. So, I said forget it, I'll try out OAuthScribeClient instead, but this generated a VERY SIMILAR ERROR java.lang.NoClassDefFoundError: org/scribe/oauth/Token This one confuses me even further because I have the following code in my java file, and it compiles without error or warning:
import org.scribe.oauth.Token;
Token token = new Token("myaccesstokeninfo", "accesstokensecret");
Clearly, I'm missing something very fundamental, but I am at an absolute loss as to what it may be. Thanks.
Usually "NoClassDefFoundError" happens when you forget to copy all jar-files to your "/war/WEB-INF/lib" directory, so those libs will be unavailable from server-side.
Xo4yHaMope is probably right.
If you're working from Eclipse but running using a web container, then your runtime classpath might be different from your project classpath - which can cause this error.
In order to complete Ben Winters answer what I actually did and worked is add the jar in
the libs folder within the project
see also here about folder hierarchy.
When you do this eclipse will normally add the jar to the android dependencies before launching the application. What I realise is that adding a jar in the build path will make classes available only during the build

Resources