質問編集履歴
1
勘違いしていた場所の訂正とコードの追加
test
CHANGED
@@ -1 +1 @@
|
|
1
|
-
Javaで
|
1
|
+
JavaでGoogle Sheets Apiを使用したときにコンパイル後に実行するとエラーが出る
|
test
CHANGED
@@ -1,47 +1,115 @@
|
|
1
|
-
Javaで
|
1
|
+
JavaでGoogle Sheets apiを使用しているのですが、コンパイル前のIntelliJ Ideaで実行した場合エラーが起きずに実行できるのですが、コンパイル後にコマンドプロンプトで実行するとエラーが出てきます。
|
2
2
|
|
3
|
-
|
3
|
+
コードはこのサイトを参考にしています。
|
4
4
|
|
5
|
-
|
5
|
+
https://developers.google.com/sheets/api/quickstart/java
|
6
|
+
|
7
|
+
|
8
|
+
|
9
|
+
**コード**
|
6
10
|
|
7
11
|
```
|
8
12
|
|
9
|
-
|
13
|
+
public static void main(String[] args) {
|
10
14
|
|
11
|
-
at
|
15
|
+
new SpreadSheets();
|
12
16
|
|
13
|
-
|
17
|
+
}
|
14
18
|
|
15
|
-
at org.bukkit.plugin.java.JavaPlugin.setEnabled(JavaPlugin.java:263) ~[spigot-1.15.2.jar:git-Spigot-2f5d615-d07a78b]
|
16
19
|
|
17
|
-
at org.bukkit.plugin.java.JavaPluginLoader.enablePlugin(JavaPluginLoader.java:351) [spigot-1.15.2.jar:git-Spigot-2f5d615-d07a78b]
|
18
20
|
|
19
|
-
|
21
|
+
public SpreadSheets() {
|
20
22
|
|
21
|
-
|
23
|
+
try {
|
22
24
|
|
23
|
-
|
25
|
+
sheets = getSheetsService();
|
24
26
|
|
25
|
-
at
|
27
|
+
} catch (Exception e) { e.printStackTrace(); }
|
26
28
|
|
27
|
-
|
29
|
+
}
|
28
30
|
|
29
|
-
at net.minecraft.server.v1_15_R1.MinecraftServer.run(MinecraftServer.java:784) [spigot-1.15.2.jar:git-Spigot-2f5d615-d07a78b]
|
30
31
|
|
32
|
+
|
33
|
+
private Credential authorize() throws Exception {
|
34
|
+
|
35
|
+
InputStream inputStream = new FileInputStream(credentials);
|
36
|
+
|
37
|
+
GoogleClientSecrets clientSecrets = GoogleClientSecrets.load(JacksonFactory.getDefaultInstance(), new InputStreamReader(inputStream));
|
38
|
+
|
39
|
+
List<String> scopes = Arrays.asList(SheetsScopes.SPREADSHEETS);
|
40
|
+
|
41
|
+
GoogleAuthorizationCodeFlow flow = new GoogleAuthorizationCodeFlow.Builder(GoogleNetHttpTransport.newTrustedTransport(),JacksonFactory.getDefaultInstance(),clientSecrets,scopes)
|
42
|
+
|
43
|
+
.setDataStoreFactory(new FileDataStoreFactory(new File("tokens")))
|
44
|
+
|
45
|
+
.setAccessType("offline")
|
46
|
+
|
47
|
+
.build();
|
48
|
+
|
49
|
+
Credential credential = new AuthorizationCodeInstalledApp(flow,new LocalServerReceiver())
|
50
|
+
|
51
|
+
.authorize("user");
|
52
|
+
|
53
|
+
return credential;
|
54
|
+
|
55
|
+
}
|
56
|
+
|
57
|
+
|
58
|
+
|
59
|
+
private Sheets getSheetsService() throws Exception{
|
60
|
+
|
61
|
+
Credential credential = authorize();
|
62
|
+
|
63
|
+
return new Sheets.Builder(GoogleNetHttpTransport.newTrustedTransport(),JacksonFactory.getDefaultInstance(),credential)
|
64
|
+
|
65
|
+
.setApplicationName(APPLICATION_NAME)
|
66
|
+
|
67
|
+
.build();
|
68
|
+
|
69
|
+
}
|
70
|
+
|
71
|
+
```
|
72
|
+
|
73
|
+
|
74
|
+
|
75
|
+
**ライブラリー**
|
76
|
+
|
77
|
+
![イメージ説明](57c6a33a3e34c51c73a41580026b158a.png)
|
78
|
+
|
79
|
+
|
80
|
+
|
81
|
+
**エラーコード**
|
82
|
+
|
83
|
+
```
|
84
|
+
|
85
|
+
Error: A JNI error has occurred, please check your installation and try again
|
86
|
+
|
87
|
+
Exception in thread "main" java.lang.NoClassDefFoundError: com/google/api/client/json/JsonFactory
|
88
|
+
|
89
|
+
at java.lang.Class.getDeclaredMethods0(Native Method)
|
90
|
+
|
91
|
+
at java.lang.Class.privateGetDeclaredMethods(Unknown Source)
|
92
|
+
|
93
|
+
at java.lang.Class.privateGetMethodRecursive(Unknown Source)
|
94
|
+
|
95
|
+
at java.lang.Class.getMethod0(Unknown Source)
|
96
|
+
|
31
|
-
at java.lang.
|
97
|
+
at java.lang.Class.getMethod(Unknown Source)
|
98
|
+
|
99
|
+
at sun.launcher.LauncherHelper.validateMainClass(Unknown Source)
|
100
|
+
|
101
|
+
at sun.launcher.LauncherHelper.checkAndLoadMain(Unknown Source)
|
32
102
|
|
33
103
|
Caused by: java.lang.ClassNotFoundException: com.google.api.client.json.JsonFactory
|
34
104
|
|
35
|
-
at java.net.URLClassLoader.findClass(Unknown Source)
|
105
|
+
at java.net.URLClassLoader.findClass(Unknown Source)
|
36
106
|
|
37
|
-
at
|
107
|
+
at java.lang.ClassLoader.loadClass(Unknown Source)
|
38
108
|
|
39
|
-
at
|
109
|
+
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
|
40
110
|
|
41
|
-
at java.lang.ClassLoader.loadClass(Unknown Source)
|
111
|
+
at java.lang.ClassLoader.loadClass(Unknown Source)
|
42
112
|
|
43
|
-
at java.lang.ClassLoader.loadClass(Unknown Source) ~[?:1.8.0_201]
|
44
|
-
|
45
|
-
...
|
113
|
+
... 7 more
|
46
114
|
|
47
115
|
```
|