谷歌应用引擎后端 - Javax.persistence缺失 - Android电子工作室 [英] Google Apps Engine Backend - Javax.persistence missing - Android Studio

查看:190
本文介绍了谷歌应用引擎后端 - Javax.persistence缺失 - Android电子工作室的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想迁移到Android的工作室和我的应用程序引擎code使用以下

所列的实体框架

 进口javax.persistence.Entity;
进口javax.persistence.Id;@实体
公共类AppVersion {@ID
私人字符串的applicationName;
私人诠释minVersionRequired;公共字符串getApplicationName(){
    返回的applicationName;
}
公众诠释getMinVersionRequired(){
    返回minVersionRequired;
}
公共无效setApplicationName(字符串的applicationName){
    this.applicationName = applicationName的;
}
setminVersionRequired(INT minVersionRequired)公共无效{
    this.minVersionRequired = minVersionRequired;
}
}

只是创造Android Studio中后端(0.5.6)不工作,我无法导入javax.persistence。*

从这个链接我发现我需要创建persistence.xml文件(这是自动在Eclipse创建)。我在那里的文件结构它应该去只是想不通。我理解它需要在META-INF文件夹,但我不知道在哪里对应的gradle为(或者,如果它已经在构建的gradle文件创建)。
当前文件的结构:

  -src
  -主要
    -java
      -com.package.test
        类文件
    -webapp
      -css
      -js
      -WEB-INF

摇篮构建文件:

  buildscript {
    库{
        mavenCentral()
    }
    依赖{
        类路径'com.google.appengine:gradle这个-AppEngine上-插件:1.9.1
    }
}库{
    mavenCentral();
}应用插件:Java的
应用插件:战争
应用插件:应用引擎sourceCompatibility = 1.7
targetCompatibility = 1.7依赖{
  appengineSdk'com.google.appengine:AppEngine上-Java的SDK:1.9.1
  编译com.google.appengine:AppEngine上的端点:1.9.1
  编译com.google.appengine:AppEngine上的端点-DEPS:1.9.1
  编译'的javax.servlet:servlet的API:2.5
}AppEngine上{
  downloadSdk =真
  appcfg {
    的oauth2 =真
  }
  端点{
    getClientLibsOnBuild =真
    getDiscoveryDocsOnBuild =真
  }
}


解决方案

Android的工作室的App Engine样本不使用JPA。

不过,如果你想使用JPA,您需要添加JPA的依赖,这描述了你可能会发现这些是什么的 https://developers.google.com/appengine/docs/java/datastore/jpa/overview-dn2

因此​​,这些(或其中的某些子集)


  • ASM-4.0.jar

  • DataNucleus的-API JPA-3.1.3.jar

  • DataNucleus的核心-3.1.3.jar

  • JDO-API-3.0.1.jar

  • DataNucleus的-API JDO-3.1.3.jar

  • DataNucleus的-的AppEngine-2.1.2.jar

  • Geronimo的jpa_2.0_spec-1.0.jar

  • JTA-1.1.jar

旁观maven.org对于那些依赖将揭示如何将其纳入的build.gradle文件,编译依赖关系:

ASM-4.0:

 编译org.ow2.asm:ASM:4.0

DataNucleus的-API JPA-3.1.3:

 编译org.datanucleus:DataNucleus的-API JPA:3.1.3

等。

您想要的版本完全一样他们在的AppEngine SDK,以确保兼容性。另外,还要确保你对你的项目运行提升的任务。

I'm trying to migrate to Android studio and my app engine code uses the Entity framework listed below

import javax.persistence.Entity;
import javax.persistence.Id;

@Entity
public class AppVersion {

@Id
private String applicationName;
private int minVersionRequired;

public String getApplicationName() {
    return applicationName;
}
public int getMinVersionRequired() {
    return minVersionRequired;
}
public void setApplicationName(String applicationName) {
    this.applicationName = applicationName;
}
public void setminVersionRequired(int minVersionRequired) {
    this.minVersionRequired = minVersionRequired;
}
}

Just creating a backend in Android Studio (0.5.6) doesn't work, I can't import javax.persistence.*

From this link I discovered that I needed to create a persistence.xml file (this was automatically created in Eclipse). I just can't figure out where in the file structure it is supposed to go. I understand it needs to be in the META-INF folder but I don't know where that corresponds for gradle (or if it has to be created in the gradle build file). Current file structure:

-src
  -main
    -java
      -com.package.test
        class files
    -webapp
      -css
      -js
      -WEB-INF

Gradle build file:

buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath 'com.google.appengine:gradle-appengine-plugin:1.9.1'
    }
}

repositories {
    mavenCentral();
}

apply plugin: 'java'
apply plugin: 'war'
apply plugin: 'appengine'

sourceCompatibility = 1.7
targetCompatibility = 1.7

dependencies {
  appengineSdk 'com.google.appengine:appengine-java-sdk:1.9.1'
  compile 'com.google.appengine:appengine-endpoints:1.9.1'
  compile 'com.google.appengine:appengine-endpoints-deps:1.9.1'
  compile 'javax.servlet:servlet-api:2.5'
}

appengine {
  downloadSdk = true
  appcfg {
    oauth2 = true
  }
  endpoints {
    getClientLibsOnBuild = true
    getDiscoveryDocsOnBuild = true
  }
}

解决方案

Android Studio's App Engine samples don't use JPA.

However if you want to use JPA, you need to add the JPA dependencies, this describes where you might find out what those are https://developers.google.com/appengine/docs/java/datastore/jpa/overview-dn2

So these (or some subset of these)

  • asm-4.0.jar
  • datanucleus-api-jpa-3.1.3.jar
  • datanucleus-core-3.1.3.jar
  • jdo-api-3.0.1.jar
  • datanucleus-api-jdo-3.1.3.jar
  • datanucleus-appengine-2.1.2.jar
  • geronimo-jpa_2.0_spec-1.0.jar
  • jta-1.1.jar

Look on maven.org for those dependencies will reveal how to include them in build.gradle files as compile dependencies:

asm-4.0 :

compile 'org.ow2.asm:asm:4.0'

datanucleus-api-jpa-3.1.3 :

compile 'org.datanucleus:datanucleus-api-jpa:3.1.3'

and so on.

You want the versions to be exactly as they are in the appengine sdk to ensure compatibility. Also make sure you run the enhance task on your project.

这篇关于谷歌应用引擎后端 - Javax.persistence缺失 - Android电子工作室的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆