質問編集履歴
1
勘違いしていた場所の訂正とコードの追加
title
CHANGED
@@ -1,1 +1,1 @@
|
|
1
|
-
Javaで
|
1
|
+
JavaでGoogle Sheets Apiを使用したときにコンパイル後に実行するとエラーが出る
|
body
CHANGED
@@ -1,24 +1,58 @@
|
|
1
|
-
JavaでMinecraftのBukkitのApiとGoogle SpreadSheets apiを同じプログラムで使用しているのですが、エラーを吐いてしまってGoogle SpreadSheetsの方が使用てきません。
|
2
|
-
Bukkitの方でLoggerの場所もエラーが出ているのでLoggerかなと思ったのですが、いまいちLoggerの仕組みや使い方などわかっていません。
|
3
|
-
|
1
|
+
JavaでGoogle Sheets apiを使用しているのですが、コンパイル前のIntelliJ Ideaで実行した場合エラーが起きずに実行できるのですが、コンパイル後にコマンドプロンプトで実行するとエラーが出てきます。
|
2
|
+
コードはこのサイトを参考にしています。
|
3
|
+
https://developers.google.com/sheets/api/quickstart/java
|
4
|
+
|
5
|
+
**コード**
|
4
6
|
```
|
7
|
+
public static void main(String[] args) {
|
8
|
+
new SpreadSheets();
|
9
|
+
}
|
10
|
+
|
11
|
+
public SpreadSheets() {
|
12
|
+
try {
|
13
|
+
sheets = getSheetsService();
|
14
|
+
} catch (Exception e) { e.printStackTrace(); }
|
15
|
+
}
|
16
|
+
|
17
|
+
private Credential authorize() throws Exception {
|
18
|
+
InputStream inputStream = new FileInputStream(credentials);
|
19
|
+
GoogleClientSecrets clientSecrets = GoogleClientSecrets.load(JacksonFactory.getDefaultInstance(), new InputStreamReader(inputStream));
|
20
|
+
List<String> scopes = Arrays.asList(SheetsScopes.SPREADSHEETS);
|
21
|
+
GoogleAuthorizationCodeFlow flow = new GoogleAuthorizationCodeFlow.Builder(GoogleNetHttpTransport.newTrustedTransport(),JacksonFactory.getDefaultInstance(),clientSecrets,scopes)
|
22
|
+
.setDataStoreFactory(new FileDataStoreFactory(new File("tokens")))
|
23
|
+
.setAccessType("offline")
|
24
|
+
.build();
|
25
|
+
Credential credential = new AuthorizationCodeInstalledApp(flow,new LocalServerReceiver())
|
26
|
+
.authorize("user");
|
27
|
+
return credential;
|
28
|
+
}
|
29
|
+
|
30
|
+
private Sheets getSheetsService() throws Exception{
|
31
|
+
Credential credential = authorize();
|
32
|
+
return new Sheets.Builder(GoogleNetHttpTransport.newTrustedTransport(),JacksonFactory.getDefaultInstance(),credential)
|
33
|
+
.setApplicationName(APPLICATION_NAME)
|
34
|
+
.build();
|
35
|
+
}
|
36
|
+
```
|
37
|
+
|
38
|
+
**ライブラリー**
|
39
|
+

|
40
|
+
|
41
|
+
**エラーコード**
|
42
|
+
```
|
43
|
+
Error: A JNI error has occurred, please check your installation and try again
|
5
|
-
java.lang.NoClassDefFoundError: com/google/api/client/json/JsonFactory
|
44
|
+
Exception in thread "main" java.lang.NoClassDefFoundError: com/google/api/client/json/JsonFactory
|
45
|
+
at java.lang.Class.getDeclaredMethods0(Native Method)
|
46
|
+
at java.lang.Class.privateGetDeclaredMethods(Unknown Source)
|
47
|
+
at java.lang.Class.privateGetMethodRecursive(Unknown Source)
|
6
|
-
at
|
48
|
+
at java.lang.Class.getMethod0(Unknown Source)
|
7
|
-
at パッケージ.onEnable(クラス名.java:87) ~[?:?]
|
8
|
-
at org.bukkit.plugin.java.JavaPlugin.setEnabled(JavaPlugin.java:263) ~[spigot-1.15.2.jar:git-Spigot-2f5d615-d07a78b]
|
9
|
-
at org.bukkit.plugin.java.JavaPluginLoader.enablePlugin(JavaPluginLoader.java:351) [spigot-1.15.2.jar:git-Spigot-2f5d615-d07a78b]
|
10
|
-
at org.bukkit.plugin.SimplePluginManager.enablePlugin(SimplePluginManager.java:480) [spigot-1.15.2.jar:git-Spigot-2f5d615-d07a78b]
|
11
|
-
at org.bukkit.craftbukkit.v1_15_R1.CraftServer.enablePlugin(CraftServer.java:464) [spigot-1.15.2.jar:git-Spigot-2f5d615-d07a78b]
|
12
|
-
at org.bukkit.craftbukkit.v1_15_R1.CraftServer.enablePlugins(CraftServer.java:378) [spigot-1.15.2.jar:git-Spigot-2f5d615-d07a78b]
|
13
|
-
at net.minecraft.server.v1_15_R1.MinecraftServer.a(MinecraftServer.java:457) [spigot-1.15.2.jar:git-Spigot-2f5d615-d07a78b]
|
14
|
-
at net.minecraft.server.v1_15_R1.DedicatedServer.init(DedicatedServer.java:274) [spigot-1.15.2.jar:git-Spigot-2f5d615-d07a78b]
|
15
|
-
at net.minecraft.server.v1_15_R1.MinecraftServer.run(MinecraftServer.java:784) [spigot-1.15.2.jar:git-Spigot-2f5d615-d07a78b]
|
16
|
-
at java.lang.
|
49
|
+
at java.lang.Class.getMethod(Unknown Source)
|
50
|
+
at sun.launcher.LauncherHelper.validateMainClass(Unknown Source)
|
51
|
+
at sun.launcher.LauncherHelper.checkAndLoadMain(Unknown Source)
|
17
52
|
Caused by: java.lang.ClassNotFoundException: com.google.api.client.json.JsonFactory
|
18
|
-
at java.net.URLClassLoader.findClass(Unknown Source)
|
53
|
+
at java.net.URLClassLoader.findClass(Unknown Source)
|
19
|
-
at org.bukkit.plugin.java.PluginClassLoader.findClass(PluginClassLoader.java:167) ~[spigot-1.15.2.jar:git-Spigot-2f5d615-d07a78b]
|
20
|
-
at org.bukkit.plugin.java.PluginClassLoader.findClass(PluginClassLoader.java:96) ~[spigot-1.15.2.jar:git-Spigot-2f5d615-d07a78b]
|
21
|
-
at java.lang.ClassLoader.loadClass(Unknown Source)
|
54
|
+
at java.lang.ClassLoader.loadClass(Unknown Source)
|
55
|
+
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
|
22
|
-
at java.lang.ClassLoader.loadClass(Unknown Source)
|
56
|
+
at java.lang.ClassLoader.loadClass(Unknown Source)
|
23
|
-
...
|
57
|
+
... 7 more
|
24
58
|
```
|