Can not access com.google.auth.Credentials - java

I am using the firebase admin SDK with IntelliJ whenever I try to run this code I got this error message:
Error:(15, 50) java: cannot access com.google.auth.Credentials
class file for com.google.auth.Credentials not found
this is the code:
import com.google.auth.oauth2.GoogleCredentials;
import com.google.firebase.FirebaseApp;
import com.google.firebase.FirebaseOptions;
import java.io.FileInputStream;
import java.io.IOException;
public class main {
public static void main (String args[]) throws IOException {
FileInputStream serviceAccount =
new FileInputStream("C:/Users/fusion/Desktop/projects/aesf/google-services.json");
FirebaseOptions options = new FirebaseOptions.Builder()
.setCredentials(GoogleCredentials.fromStream(serviceAccount))
.setDatabaseUrl("https://myDataBaseName.firebaseio.com")
.build();
FirebaseApp.initializeApp(options);
}
}
And this is the gradle file:
plugins {
id 'java'
}
version '1.0-SNAPSHOT'
apply plugin: 'java'
sourceCompatibility = 1.8
repositories {
mavenCentral()
}
dependencies {
testCompile group: 'junit', name: 'junit', version: '4.12'
implementation 'com.google.firebase:firebase-admin:6.6.0'
implementation 'com.google.auth:google-auth-library-oauth2-http:0.12.0'
}
gradle :
rootProject.name = 'aesf'

Check you are using one of these
remove them
google-oauth-client-1.22.0.jar
google-oauth-client-appengine-1.22.0.jar
google-oauth-client-servlet-1.22.0.jar
also update your classpath
classpath 'com.google.gms:google-services:4.2.0'

Related

JavaFx Application Class not found in Gradle jar

I am trying to build a jar with the following build.gradle:
plugins {
id 'application'
id 'org.openjfx.javafxplugin' version '0.0.10'
}
application {
mainClass.set("edu.hm.dako.auditLogServer.AdminGuiStarter")
}
jar.enabled = true
javafx {
version = "18"
modules = ['javafx.controls', 'javafx.fxml']
}
sourceSets {
main {
resources {
srcDirs = ["src/main/java"]
includes = ["**/*.fxml"]
}
}
}
dependencies {
implementation project(':common')
implementation project(':communication')
implementation 'org.openjfx:javafx:18'
implementation group: 'org.apache.commons', name: 'commons-configuration2', version: '2.8.0'
implementation group: 'commons-beanutils', name: 'commons-beanutils', version: '1.9.4'
}
repositories {
mavenCentral()
}
jar {
manifest {
attributes "Main-Class": "edu.hm.dako.auditLogServer.AdminGuiStarter"
}
archiveBaseName = 'AdminGradle'
archiveVersion = '0.1.0'
}
The Main class of the project is following:
package edu.hm.dako.auditLogServer;
import java.io.IOException;
import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.stage.Stage;
public class AdminGuiStarter extends Application{
#Override
public void start(Stage stage) {
try {
Parent root = FXMLLoader.load(getClass().getResource("AdminGui.fxml"));
Scene scene = new Scene(root);
stage.setScene(scene);
stage.show();
} catch (IOException e) {
e.printStackTrace();
System.out.println(e);
}
}
// bitte über gradle starten, da sonst JavaFx Runtime components fehlen
public static void main(String[] args) {
launch();
}
}
When I then try to execute the jar, I get this error: java.lang.NoClassDefFoundError: javafx/application/Application
How can I fix this so that the jar will execute successful? When I run the Application via Gradle run, everything works fine.

JUnit testcases is throwing NoClassDefFoundError

I am trying to executing basic testcase, which I have completed doing setup and I am getting below error:
java.lang.NoClassDefFoundError: org/junit/platform/engine/EngineDiscoveryListener
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:760)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:467)
at java.net.URLClassLoader.access$100(URLClassLoader.java:73)
at java.net.URLClassLoader$1.run(URLClassLoader.java:368)
at java.net.URLClassLoader$1.run(URLClassLoader.java:362)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:361)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at org.junit.platform.launcher.core.LauncherDiscoveryRequestBuilder.getLauncherDiscoveryListener(LauncherDiscoveryRequestBuilder.java:241)
at org.junit.platform.launcher.core.LauncherDiscoveryRequestBuilder.build(LauncherDiscoveryRequestBuilder.java:235)
at org.eclipse.jdt.internal.junit5.runner.JUnit5TestLoader.createUnfilteredTest(JUnit5TestLoader.java:75)
at org.eclipse.jdt.internal.junit5.runner.JUnit5TestLoader.createTest(JUnit5TestLoader.java:66)
at org.eclipse.jdt.internal.junit5.runner.JUnit5TestLoader.loadTests(JUnit5TestLoader.java:53)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:526)
Find below my ConfigServer class:
package org.siaa.devops;
import java.util.Hashtable;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
import org.springframework.cloud.config.server.EnableConfigServer;
import com.jcraft.jsch.JSch;
#SpringBootApplication
#EnableConfigServer
public class ConfigServer extends SpringBootServletInitializer {
private static final String PREFERRED_AUTENTICATION_MODE = "publickey";
public static void main(String[] args) {
// Hack in JSCH to avoid interactive session
// Override PreferredAuthentications in JSCH
Hashtable<String, String> config = new Hashtable<String, String>();
config.put("PreferredAuthentications", PREFERRED_AUTENTICATION_MODE);
JSch.setConfig(config);
SpringApplication.run(ConfigServer.class, args);
}
#Override
protected SpringApplicationBuilder configure(
SpringApplicationBuilder application) {
return application.sources(ConfigServer.class);
}
}
build.gradle
group 'org.siaa.develop'
buildscript {
ext {
//springBootVersion = '1.5.4.RELEASE'
//springBootVersion = '2.0.6.RELEASE'
springBootVersion = '2.2.6.RELEASE'
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
}
}
apply plugin: "io.spring.dependency-management"
apply plugin: 'org.springframework.boot'
apply plugin: 'java'
apply plugin: 'eclipse'
//version = '0.0.1-SNAPSHOT'
//springBoot {
//executable = true
//}
bootJar {
launchScript()
}
ext {
springCloudVersion = 'Hoxton.SR3'
}
sourceCompatibility = 1.8
targetCompatibility = 1.8
repositories {
//mavenCentral()
maven {
url 'http://artifactory.siaa.org/artifactory/siaa-mp-develop'
}
}
dependencies {
compile('org.springframework.cloud:spring-cloud-config-server:2.2.2.RELEASE')
compile('org.springframework.boot:spring-boot-starter-actuator:2.2.6.RELEASE')
compile('org.springframework.cloud:spring-cloud-security:2.2.1.RELEASE')
testCompile('org.springframework.boot:spring-boot-starter-test')
providedRuntime 'org.springframework.boot:spring-boot-starter-tomcat'
//Kafka and spring cloud config monitor
compile('org.springframework.cloud:spring-cloud-starter-bus-kafka:2.0.0.RELEASE')
compile('org.springframework.cloud:spring-cloud-config-monitor:2.2.1.RELEASE')
//Prometheus
compile('io.micrometer:micrometer-registry-prometheus')
implementation("org.junit.jupiter:junit-jupiter:5.6.0")
}
dependencyManagement {
imports {
mavenBom "org.springframework.cloud:spring-cloud-dependencies:${springCloudVersion}"
}
}
Added testcase is ConfigServerTest
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
#RunWith(SpringRunner.class)
#SpringBootTest
public class ConfigServerTest {
#Test
public void contextLoads() {
}
}
I have done research and same code seems to working fine in other machine but causing issue in my local.
Unable to fix it. Please help me out with it.
Gradle version I am using is: Gradle-6.5.1
Java (JRE)version :1.8.0_40
Thanks in advance.

On my Minecraftserver my Plugin doesn't load

My Minecraft Plugin doesn't load
I tried reinstalling Java
rebuilding the jar
and tried to remake the code
I used java 11
in IntelliJ Idea
and I used Minecraft 1.15.2
on MacOS 10.15.7
and I coded in Kotlin
Error Message:
org.bukkit.plugin.InvalidPluginException: Abnormal plugin type
at org.bukkit.plugin.java.PluginClassLoader.<init>(PluginClassLoader.java:80) ~[spigot-1.15.2.jar:git-Spigot-a99063f-be6aaf0]
at org.bukkit.plugin.java.JavaPluginLoader.loadPlugin(JavaPluginLoader.java:135) ~[spigot-1.15.2.jar:git-Spigot-a99063f-be6aaf0]
at org.bukkit.plugin.SimplePluginManager.loadPlugin(SimplePluginManager.java:394) ~[spigot-1.15.2.jar:git-Spigot-a99063f-be6aaf0]
at org.bukkit.plugin.SimplePluginManager.loadPlugins(SimplePluginManager.java:301) [spigot-1.15.2.jar:git-Spigot-a99063f-be6aaf0]
at org.bukkit.craftbukkit.v1_15_R1.CraftServer.loadPlugins(CraftServer.java:353) [spigot-1.15.2.jar:git-Spigot-a99063f-be6aaf0]
at net.minecraft.server.v1_15_R1.DedicatedServer.init(DedicatedServer.java:210) [spigot-1.15.2.jar:git-Spigot-a99063f-be6aaf0]
at net.minecraft.server.v1_15_R1.MinecraftServer.run(MinecraftServer.java:784) [spigot-1.15.2.jar:git-Spigot-a99063f-be6aaf0]
at java.lang.Thread.run(Thread.java:834) [?:?]
Caused by: java.lang.InstantiationException
at jdk.internal.reflect.InstantiationExceptionConstructorAccessorImpl.newInstance(InstantiationExceptionConstructorAccessorImpl.java:48) ~[?:?]
at java.lang.reflect.Constructor.newInstance(Constructor.java:490) ~[?:?]
at java.lang.Class.newInstance(Class.java:584) ~[?:?]
at org.bukkit.plugin.java.PluginClassLoader.<init>(PluginClassLoader.java:76) ~[spigot-1.15.2.jar:git-Spigot-a99063f-be6aaf0]
... 7 more
My Main Class the only Class that the Project have (it is in Kotlin):
package main
import org.bukkit.Bukkit
import org.bukkit.command.Command
import org.bukkit.command.CommandExecutor
import org.bukkit.command.CommandSender
import org.bukkit.entity.Entity
import org.bukkit.entity.Player
import org.bukkit.event.EventHandler
import org.bukkit.event.Listener
import org.bukkit.event.player.PlayerJoinEvent
import org.bukkit.inventory.PlayerInventory
import org.bukkit.plugin.PluginManager
import org.bukkit.plugin.java.JavaPlugin
public abstract class Loader : JavaPlugin(), Listener, CommandExecutor{
override fun onEnable() {
Bukkit.broadcastMessage("Aura Plugin test by Woody1474747")
}
override fun onCommand(sender: CommandSender, command: Command, label: String, args: Array<out String>): Boolean {
if(sender is Player){
when(command.name){
"aura" -> {
val plinv:PlayerInventory = sender.getInventory()
val item1 = plinv.getItem(0)
val item8 = plinv.getItem(8)
sender.sendMessage(item1.toString())
}
}
}
return true
}
}
My plugin.yml
name: auraplugtest
version: 1.0.0
description: fsaf
main: main.Loader
commands:
aura:
usage: /<command>
My build.gradle:
id 'java'
id 'org.jetbrains.kotlin.jvm' version '1.3.61'
id 'com.github.johnrengelman.shadow' version '2.0.4'
}
group 'org.example'
version '1-SNAPSHOT'
sourceCompatibility = 1.8
repositories {
mavenCentral()
}
repositories {
maven {
url = 'https://hub.spigotmc.org/nexus/content/repositories/snapshots/'
content {
includeGroup 'org.bukkit'
includeGroup 'org.spigotmc'
}
}
maven {
url = 'https://oss.sonatype.org/content/repositories/snapshots'
}
}
dependencies {
compileOnly 'org.bukkit:bukkit:1.14.4-R0.1-SNAPSHOT'
}
dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8"
testCompile group: 'junit', name: 'junit', version: '4.12'
}
sourceCompatibility = 1.8
targetCompatibility = 1.8
compileKotlin {
kotlinOptions.jvmTarget = "1.8"
}
compileTestKotlin {
kotlinOptions.jvmTarget = "1.8"
}
The answer is simple, your class cannot be abstract!
Fixed code:
// removed abstract keyword
public class Loader : JavaPlugin(), Listener, CommandExecutor {
// ...
}

When I compile Java(fx) application for Android, with the SoundPool use, the java compiler says "package android.media does not exist"

In a Java application for Android, made in JavaFX under Eclipse Neon2, I want to use the android media SoundPool class.
To do that, I have added, in the Java Build Path:
the android-sdks platform : android-25 (called android.jar).
the jfxdvk-8.60.8.jar
Then, for instance, I create a SoundPool instance as follows:
import android.media.SounPool;
import android.media.MediaPlayer;
...
SoundPool sp = new SoundPool(MAX_STREAMS,AudioManager.STREAM_MUSIC,0);
The syntax is correct and the Eclipse editor does not notice any error.
But, when compiling the file, I have two errors "package android.media does not exist import android.media.AudioManager" and "package android.media does not exist import android.media.SoundPool;", and then, (it is a consequence), "cannot find symbols" at "AudioManager.STREAM_MUSIC" and at "new SoundPool" of the previous line code.
I don't understand these errors because I have added, in my JavaBuild Path, this android-sdks platform: android.jar (android-25) ad the Eclipse editor can fetch these two imports.
Thanks in advance for your response
Further information:
Errors raised on java compilation:
[sts] -----------------------------------------------------
[sts] Starting Gradle build for the following tasks:
[sts] androidInstall
[sts] -----------------------------------------------------
:validateManifest
:collectMultiDexComponents
:compileJavaC:\Users\pascal\workspaceNeon\JFX_withGluon_11.0gAvecSoundPoolKO\src\main\java\com\gluonapplication\GluonApplication.java:3: error: package android.media does not exist
import android.media.AudioManager;
^
C:\Users\pascal\workspaceNeon\JFX_withGluon_11.0gAvecSoundPoolKO\src\main\java\com\gluonapplication\GluonApplication.java:4: error: package android.media does not exist
import android.media.SoundPool;
^
C:\Users\pascal\workspaceNeon\JFX_withGluon_11.0gAvecSoundPoolKO\src\main\java\com\gluonapplication\GluonApplication.java:635: error: cannot find symbol
static SoundPool androidSoundPoolApplication = null;
----------------------
Related code:
package com.gluonapplication;
import android.media.AudioManager;
import android.media.SoundPool;
import com.gluonhq.charm.down.Services; // line 3
import com.gluonhq.charm.down.plugins.AccelerometerService; // line 4
......
final static int MAX_STREAMS = 10;
static SoundPool androidSoundPoolApplication = null; // line 635
And the build.gradle:
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'org.javafxports:jfxmobile-plugin:1.3.2'
}
}
apply plugin: 'org.javafxports.jfxmobile'
repositories {
jcenter()
maven {
url 'http://nexus.gluonhq.com/nexus/content/repositories/releases'
}
}
mainClassName = 'com.gluonapplication.GluonApplication'
dependencies {
compile 'com.gluonhq:charm:4.3.0'
}
jfxmobile {
downConfig {
version '3.2.0'
plugins 'accelerometer', 'compass', 'device', 'orientation', 'storage', 'vibration', 'display', 'magnetometer', 'lifecycle', 'statusbar', 'position'
}
android {
applicationPackage = 'com.gluonapplication'
manifest = 'src/android/AndroidManifest.xml'
androidSdk = 'C:/Users/pascal/AppData/Local/Android/sdk'
resDirectory = 'src/android/res'
compileSdkVersion = '25'
buildToolsVersion = '25.0.1'
}
ios {
infoPList = file('src/ios/Default-Info.plist')
forceLinkClasses = [
'com.gluonhq.**.*',
'javax.annotations.**.*',
'javax.inject.**.*',
'javax.json.**.*',
'org.glassfish.json.**.*'
]
}
}

How to run Junit TestSuites from gradle?

I am trying to migrate from Ant build to Gradle in my project. There are a bunch of test cases (subclasses of junit.framework.TestCase) and few test suites (subclasses of junit.framework.TestSuite). Gradle automatically picked up all test cases(subclasses of junit.framework.TestCase) to be run, but not the suites (subclasses of junit.framework.TestSuite).
I probably could work around by calling ant.junit to run it. But, I feel there should be a native easy way to force gradle to pick them and run. I couldn't find anything in the document . Am I missing something?
This was hard for me to figure out, but here is an example:
// excerpt from https://github.com/djangofan/WebDriverHandlingMultipleWindows
package webdriver.test;
import http.server.SiteServer;
import java.io.File;
import java.io.IOException;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.runner.RunWith;
import org.junit.runners.Suite;
#RunWith(Suite.class)
#Suite.SuiteClasses({ TestHandleCacheOne.class, TestHandleCacheThree.class, TestHandleCacheThree.class })
public class SuiteOne extends MultiWindowUtils {
public static SiteServer fs;
#BeforeClass
public static void setUpSuiteOne() {
File httpRoot = new File("build/resources/test");
System.out.println("Server root directory is: " + httpRoot.getAbsolutePath() );
int httpPort = Integer.parseInt("8080");
try {
fs = new SiteServer( httpPort , httpRoot );
} catch (IOException e) {
e.printStackTrace();
}
initializeBrowser( "firefox" );
System.out.println("Finished setUpSuiteOne");
}
#AfterClass
public static void tearDownSuiteOne() {
closeAllBrowserWindows();
System.out.println("Finished tearDownSuiteOne");
}
}
And a build.gradle similar to this:
apply plugin: 'java'
apply plugin: 'eclipse'
group = 'test.multiwindow'
ext {
projTitle = 'Test MultiWindow'
projVersion = '1.0'
}
repositories {
mavenCentral()
}
dependencies {
compile group: 'org.seleniumhq.selenium', name: 'selenium-java', version: '2.+'
compile group: 'junit', name: 'junit', version: '4.+'
compile group: 'org.slf4j', name: 'slf4j-api', version: '1.7.+'
}
task testGroupOne(type: Test) {
//include '**/*SuiteOne.*'
include '**/SuiteOne.class'
reports.junitXml.destination = "$buildDir/test-results/SuiteOne")
reports.html.destination = "$buildDir/test-results/SuiteOne")
}
task testGroupTwo(type: Test) {
//include '**/*SuiteTwo.*'
include '**/SuiteTwo.class'
reports.junitXml.destination = "$buildDir/test-results/SuiteTwo")
reports.html.destination = "$buildDir/test-results/SuiteTwo")
}

Categories