JavaでGoogle Sheets apiを使用しているのですが、コンパイル前のIntelliJ Ideaで実行した場合エラーが起きずに実行できるのですが、コンパイル後にコマンドプロンプトで実行するとエラーが出てきます。
コードはこのサイトを参考にしています。
https://developers.google.com/sheets/api/quickstart/java
コード
public static void main(String[] args) { new SpreadSheets(); } public SpreadSheets() { try { sheets = getSheetsService(); } catch (Exception e) { e.printStackTrace(); } } private Credential authorize() throws Exception { InputStream inputStream = new FileInputStream(credentials); GoogleClientSecrets clientSecrets = GoogleClientSecrets.load(JacksonFactory.getDefaultInstance(), new InputStreamReader(inputStream)); List<String> scopes = Arrays.asList(SheetsScopes.SPREADSHEETS); GoogleAuthorizationCodeFlow flow = new GoogleAuthorizationCodeFlow.Builder(GoogleNetHttpTransport.newTrustedTransport(),JacksonFactory.getDefaultInstance(),clientSecrets,scopes) .setDataStoreFactory(new FileDataStoreFactory(new File("tokens"))) .setAccessType("offline") .build(); Credential credential = new AuthorizationCodeInstalledApp(flow,new LocalServerReceiver()) .authorize("user"); return credential; } private Sheets getSheetsService() throws Exception{ Credential credential = authorize(); return new Sheets.Builder(GoogleNetHttpTransport.newTrustedTransport(),JacksonFactory.getDefaultInstance(),credential) .setApplicationName(APPLICATION_NAME) .build(); }
エラーコード
Error: A JNI error has occurred, please check your installation and try again Exception in thread "main" java.lang.NoClassDefFoundError: com/google/api/client/json/JsonFactory at java.lang.Class.getDeclaredMethods0(Native Method) at java.lang.Class.privateGetDeclaredMethods(Unknown Source) at java.lang.Class.privateGetMethodRecursive(Unknown Source) at java.lang.Class.getMethod0(Unknown Source) at java.lang.Class.getMethod(Unknown Source) at sun.launcher.LauncherHelper.validateMainClass(Unknown Source) at sun.launcher.LauncherHelper.checkAndLoadMain(Unknown Source) Caused by: java.lang.ClassNotFoundException: com.google.api.client.json.JsonFactory at java.net.URLClassLoader.findClass(Unknown Source) at java.lang.ClassLoader.loadClass(Unknown Source) at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source) at java.lang.ClassLoader.loadClass(Unknown Source) ... 7 more
回答1件
あなたの回答
tips
プレビュー