App Engine - LoggerFactory Restricted Class Error When Using Firebase in Java

五迷三道 提交于 2019-12-11 15:13:05

问题


I'm creating a backend for my Android application using Google App Engine. I'm doing something very simple, which is just initialising my Firebase Admin SDK following instructions here - https://firebase.google.com/docs/admin/setup.

When I do this and run, I get the following error:

java.lang.NoClassDefFoundError: org.slf4j.LoggerFactory is a restricted class. Please see the Google App Engine developer's guide for more details. at com.google.appengine.tools.development.agent.runtime.Runtime.reject(Runtime.java:52) at com.google.firebase.internal.FirebaseThreadManagers.(FirebaseThreadManagers.java:37) at com.google.firebase.FirebaseOptions$Builder.(FirebaseOptions.java:147) at com.example.app.myapplication.backend.MyServlet.doGet(MyServlet.java:34)

Here's my Servlet, which works fine without the Firebase additions. Error occurs at FirebaseOptions:

    public class MyServlet extends HttpServlet {

    @Override
    public void doGet(HttpServletRequest req, HttpServletResponse resp)
            throws IOException {
        resp.setContentType("text/plain");
        resp.getWriter().println("Please use the form to POST to this url");


        FileInputStream serviceAccount =
                new FileInputStream("WEB-INF/MyAppServiceKey.json");

        FirebaseOptions options = new FirebaseOptions.Builder()
                .setCredential(FirebaseCredentials.fromCertificate(serviceAccount))
                .setDatabaseUrl("https://MyApp.firebaseio.com")
                .build();

        FirebaseApp.initializeApp(options);
    }

    @Override
    public void doPost(HttpServletRequest req, HttpServletResponse resp)
            throws IOException {
        String name = req.getParameter("name");
        resp.setContentType("text/plain");
        if (name == null) {
            resp.getWriter().println("Please enter a name");
        }
        resp.getWriter().println("Hello " + name);
    }
}

Here's my build.gradle for the backend:

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

repositories {
    jcenter();
}

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

sourceCompatibility = JavaVersion.VERSION_1_7
targetCompatibility = JavaVersion.VERSION_1_7

dependencies {
    appengineSdk 'com.google.appengine:appengine-java-sdk:1.9.42'
    compile 'javax.servlet:servlet-api:2.5'
    compile 'com.google.firebase:firebase-admin:5.5.0'

}

appengine {
    downloadSdk = true
    appcfg {
        oauth2 = true
    }
}

来源:https://stackoverflow.com/questions/47608785/app-engine-loggerfactory-restricted-class-error-when-using-firebase-in-java

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!