当前位置: 首页 > 知识库问答 >
问题:

手动配置生成路径时未解析的导入

支智志
2023-03-14

在尝试使用Maven创建我的第一个可执行文件时,我遇到了问题,现在尝试使用install4j。为了保留我的依赖关系,我下载了pom.xml中列出的JAR,将它们添加到构建路径中,并删除了pom.xml。现在,我的一些罐子似乎没有正确导入。我尝试了最新版本和在我的maven项目中运行良好的旧版本,但都不起作用。

  • google-api-client-1.3.2.jar
  • Google-API-Services-Sheets-v4-rev614-1.18.0-rc.jar
  • google-oauth-client-jetty-1.31.4.jar
  • commons-io-1.3.2.jar(不认为使用了这个)

这些是正在工作的导入:

  • 导入com.google.api.client.extensions.jetty.auth.oauth2.LocalServerReceiver;
  • 导入com.google.api.client.googleapis.auth.oauth2.googleauthorizationcodeflow;
  • 导入com.google.api.client.googleapis.auth.oauth2.GoogleClientSecrets;
  • 导入com.google.api.client.googleapis.javanet.googlenetttptransport;
  • 导入com.google.api.services.sheets.v4.sheets;
    null

这是我的代码的MRE:

package misc;

import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.Collections;

import com.google.api.client.auth.oauth2.Credential;
import com.google.api.client.extensions.java6.auth.oauth2.AuthorizationCodeInstalledApp;
import com.google.api.client.extensions.jetty.auth.oauth2.LocalServerReceiver;
import com.google.api.client.googleapis.auth.oauth2.GoogleAuthorizationCodeFlow;
import com.google.api.client.googleapis.auth.oauth2.GoogleClientSecrets;
import com.google.api.client.googleapis.javanet.GoogleNetHttpTransport;
import com.google.api.client.http.javanet.NetHttpTransport;
import com.google.api.client.json.JsonFactory;
import com.google.api.client.json.jackson2.JacksonFactory;
import com.google.api.client.util.store.FileDataStoreFactory;
import com.google.api.services.sheets.v4.Sheets;

public class GoogleSheetsStuff {
    
    private static final String APPLICATION_NAME = "Google Sheets API Java Quickstart";
    private static final JsonFactory JSON_FACTORY = JacksonFactory.getDefaultInstance();
    private static final String TOKENS_DIRECTORY_PATH = "tokens2";

    private static final List<String> SCOPES = Collections.singletonList(SheetsScopes.SPREADSHEETS);
    private static final String CREDENTIALS_FILE_PATH = "/credentials.json";

    private static Credential getCredentials(final NetHttpTransport HTTP_TRANSPORT) throws IOException {
        InputStream in = GoogleSheetsStuff.class.getResourceAsStream(CREDENTIALS_FILE_PATH);
        if (in == null) {
            throw new FileNotFoundException("Resource not found: " + CREDENTIALS_FILE_PATH);
        }
        GoogleClientSecrets clientSecrets = GoogleClientSecrets.load(JSON_FACTORY, new InputStreamReader(in));
        GoogleAuthorizationCodeFlow flow = new GoogleAuthorizationCodeFlow.Builder(
                HTTP_TRANSPORT, JSON_FACTORY, clientSecrets, SCOPES)
                .setDataStoreFactory(new FileDataStoreFactory(new java.io.File(TOKENS_DIRECTORY_PATH)))
                .setAccessType("offline")
                .build();
        LocalServerReceiver receiver = new LocalServerReceiver.Builder().setPort(8888).build();
        return new AuthorizationCodeInstalledApp(flow, receiver).authorize("user");
    }

    public static Sheets buildService () throws GeneralSecurityException, IOException {
        final NetHttpTransport HTTP_TRANSPORT = GoogleNetHttpTransport.newTrustedTransport();
        Sheets service = new Sheets.Builder(HTTP_TRANSPORT, JSON_FACTORY, getCredentials(HTTP_TRANSPORT))
                .setApplicationName(APPLICATION_NAME)
                .build();
        return service;
    }
}

共有1个答案

韩宜春
2023-03-14

您不必手动下载JAR并将其添加到类路径中以包含在项目运行时中。你只需要一个大罐子。下面是一个如何创建的示例:-

http://tutorials.jenkov.com/maven/maven-build-fat-jar.html

 类似资料:
  • 本文向大家介绍Spring手动生成web.xml配置文件过程详解,包括了Spring手动生成web.xml配置文件过程详解的使用技巧和注意事项,需要的朋友参考一下 步骤一: 找到自己所创建的项目名,效果如下: 步骤二: 右击自己所创建的项目————》Java EE Tools————》点击Generate Deployment Descriptor Stub,完成这几步,即可,效果如下: 最后,就

  • 问题内容: 我在debian jessie上安装了elasticsearch 1.7.3。它使用默认配置文件,并且可以正常工作。但是当我打电话给它返回一个错误: 文件存在,我可以在nano中打开他。 有/ etc / default / elasticsearch文件: 和文件中没有记录。 有人知道为什么会失败吗? 问题答案: 这不是问题的解决。但是我解决了我的问题。 生成bash-command

  • 我试图通过JNA在eclipse中使用GStreamer。Processing为此提供了一个库,如果我试图通过从eclipse中以applet的形式运行sketch来运行代码,那么一切都很好,但是当我试图执行整个应用程序时,我会得到一个警告列表(在相机第一次调用时),如下所示 这条路似乎不对... 我从来没有写过需要jna的库,我试图使用这个库,如果可能的话,有什么建议吗?

  • 本文向大家介绍Spring boot 默认静态资源路径与手动配置访问路径的方法,包括了Spring boot 默认静态资源路径与手动配置访问路径的方法的使用技巧和注意事项,需要的朋友参考一下 在application.propertis中配置 如果自定义访问路径则需要添加WebConfig配置类 在controller中 在浏览器中访问地址 localhost:8081/index 以上所述是小编

  • 问题内容: 嘿,我在应用程序中实现了涂鸦功能。画线时,移动手指时看不到线路径。我可以看到线条向上的时间,例如TouchUp,有人可以帮助我,以便我可以看到沿着路径移动手指时绘制的线条。 问题答案:

  • 问题内容: 我正在寻找Eclipse存储其启动配置的文件。我正在Ubuntu中进行一些Java开发。 我正在开发的一个可执行文件需要另一个可执行文件的输出作为其参数。可以这么说,“ B”的输出需要作为命令行参数传递给“ A”。在Eclipse中,我不想每次都手动更改“运行配置”。Eclipse将这些配置(尤其是参数)存储在哪里? 我在项目的extras文件夹中找到了“ eclipseArgumen