找不到Java类JsonFactory异常

找不到Java类JsonFactory异常,java,json,maven,google-api,bukkit,Java,Json,Maven,Google Api,Bukkit,所以我对Java还是一个新手,我的意思是说,我进入Java有一个星期了,所以很多东西对我来说仍然是个谜。 基本上,我正在用谷歌API制作一个SpigotMC插件,从实时流中获取数据。我正在使用Maven,当我在那里运行程序时,它似乎工作得很好。然而,当在实际服务器上运行它时,我会遇到一个奇怪的错误 以下是整个错误消息: org.bukkit.command.CommandException: Unhandled exception executing command 'chatcontrol'

所以我对Java还是一个新手,我的意思是说,我进入Java有一个星期了,所以很多东西对我来说仍然是个谜。 基本上,我正在用谷歌API制作一个SpigotMC插件,从实时流中获取数据。我正在使用Maven,当我在那里运行程序时,它似乎工作得很好。然而,当在实际服务器上运行它时,我会遇到一个奇怪的错误

以下是整个错误消息:

org.bukkit.command.CommandException: Unhandled exception executing command 'chatcontrol' in plugin MinecraftButChatRuinsEverything v0.1
        at org.bukkit.command.PluginCommand.execute(PluginCommand.java:47) ~[spigot-1.14.4.jar:git-Spigot-56f8471-eafd742]
        at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:149) ~[spigot-1.14.4.jar:git-Spigot-56f8471-eafd742]
        at org.bukkit.craftbukkit.v1_14_R1.CraftServer.dispatchCommand(CraftServer.java:710) ~[spigot-1.14.4.jar:git-Spigot-56f8471-eafd742]
        at net.minecraft.server.v1_14_R1.PlayerConnection.handleCommand(PlayerConnection.java:1641) ~[spigot-1.14.4.jar:git-Spigot-56f8471-eafd742]
        at net.minecraft.server.v1_14_R1.PlayerConnection.a(PlayerConnection.java:1481) ~[spigot-1.14.4.jar:git-Spigot-56f8471-eafd742]
        at net.minecraft.server.v1_14_R1.PacketPlayInChat.a(PacketPlayInChat.java:47) ~[spigot-1.14.4.jar:git-Spigot-56f8471-eafd742]
        at net.minecraft.server.v1_14_R1.PacketPlayInChat.a(PacketPlayInChat.java:1) ~[spigot-1.14.4.jar:git-Spigot-56f8471-eafd742]
        at net.minecraft.server.v1_14_R1.PlayerConnectionUtils.lambda$0(PlayerConnectionUtils.java:19) ~[spigot-1.14.4.jar:git-Spigot-56f8471-eafd742]
        at net.minecraft.server.v1_14_R1.TickTask.run(SourceFile:18) [spigot-1.14.4.jar:git-Spigot-56f8471-eafd742]
        at net.minecraft.server.v1_14_R1.IAsyncTaskHandler.executeTask(SourceFile:144) [spigot-1.14.4.jar:git-Spigot-56f8471-eafd742]
        at net.minecraft.server.v1_14_R1.IAsyncTaskHandlerReentrant.executeTask(SourceFile:23) [spigot-1.14.4.jar:git-Spigot-56f8471-eafd742]
        at net.minecraft.server.v1_14_R1.IAsyncTaskHandler.executeNext(SourceFile:118) [spigot-1.14.4.jar:git-Spigot-56f8471-eafd742]
        at net.minecraft.server.v1_14_R1.MinecraftServer.aX(MinecraftServer.java:909) [spigot-1.14.4.jar:git-Spigot-56f8471-eafd742]
        at net.minecraft.server.v1_14_R1.MinecraftServer.executeNext(MinecraftServer.java:902) [spigot-1.14.4.jar:git-Spigot-56f8471-eafd742]
        at net.minecraft.server.v1_14_R1.IAsyncTaskHandler.awaitTasks(SourceFile:127) [spigot-1.14.4.jar:git-Spigot-56f8471-eafd742]
        at net.minecraft.server.v1_14_R1.MinecraftServer.sleepForTick(MinecraftServer.java:886) [spigot-1.14.4.jar:git-Spigot-56f8471-eafd742]
        at net.minecraft.server.v1_14_R1.MinecraftServer.run(MinecraftServer.java:819) [spigot-1.14.4.jar:git-Spigot-56f8471-eafd742]
        at java.lang.Thread.run(Thread.java:834) [?:?]
Caused by: java.lang.NoClassDefFoundError: com/google/api/client/json/JsonFactory
        at Commands.ChatControl.onCommand(ChatControl.java:33) ~[?:?]
        at org.bukkit.command.PluginCommand.execute(PluginCommand.java:45) ~[spigot-1.14.4.jar:git-Spigot-56f8471-eafd742]
        ... 17 more
Caused by: java.lang.ClassNotFoundException: com.google.api.client.json.JsonFactory
        at java.net.URLClassLoader.findClass(URLClassLoader.java:471) ~[?:?]
        at org.bukkit.plugin.java.PluginClassLoader.findClass(PluginClassLoader.java:135) ~[spigot-1.14.4.jar:git-Spigot-56f8471-eafd742]
        at org.bukkit.plugin.java.PluginClassLoader.findClass(PluginClassLoader.java:81) ~[spigot-1.14.4.jar:git-Spigot-56f8471-eafd742]
        at java.lang.ClassLoader.loadClass(ClassLoader.java:588) ~[?:?]
        at java.lang.ClassLoader.loadClass(ClassLoader.java:521) ~[?:?]
        at Commands.ChatControl.onCommand(ChatControl.java:33) ~[?:?]
        at org.bukkit.command.PluginCommand.execute(PluginCommand.java:45) ~[spigot-1.14.4.jar:git-Spigot-56f8471-eafd742]
我见过人们有同样的问题,但我从来没有看到一个好的或明确的解决办法。我试着自己修修补补,但没有多大成功。我假设问题是由于加载了一些类,但是我不知道如何处理这些信息

以下是调用getChatId方法后出现问题的类:

package Commands;

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.googleapis.json.GoogleJsonResponseException;
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.services.youtube.YouTube;
import com.google.api.services.youtube.model.LiveBroadcastListResponse;

import java.io.*;
import java.security.GeneralSecurityException;
import java.util.Arrays;
import java.util.Collection;
import java.util.Timer;
import java.util.TimerTask;

public class YouTubeLiveStreamAPI {
    static String streamID;
    private static final String CLIENT_SECRETS = "client_secret.json";
    private static final Collection<String> SCOPES =
            Arrays.asList("https://www.googleapis.com/auth/youtube.readonly");

    private static final String APPLICATION_NAME = "API code samples";
    private static final JsonFactory JSON_FACTORY = JacksonFactory.getDefaultInstance();

    /**
     * Create an authorized Credential object.
     *
     * @return an authorized Credential object.
     * @throws IOException
     */
    public static Credential authorize(final NetHttpTransport httpTransport) throws IOException {
        // Load client secrets.
        File test = new File("src/main/resources/client_secret.json");
        System.out.println(test.exists());
        FileInputStream in = new FileInputStream(test);
//        InputStream in = YouTubeLiveStreamAPI.class.getResourceAsStream(CLIENT_SECRETS);
        GoogleClientSecrets clientSecrets =
                GoogleClientSecrets.load(JSON_FACTORY, new InputStreamReader(in));
        // Build flow and trigger user authorization request.
        GoogleAuthorizationCodeFlow flow =
                new GoogleAuthorizationCodeFlow.Builder(httpTransport, JSON_FACTORY, clientSecrets, SCOPES)
                        .build();
        Credential credential =
                new AuthorizationCodeInstalledApp(flow, new LocalServerReceiver()).authorize("user");
        return credential;
    }

    /**
     * Build and return an authorized API client service.
     *
     * @return an authorized API client service
     * @throws GeneralSecurityException, IOException
     */
    public static YouTube getService() throws GeneralSecurityException, IOException, GoogleJsonResponseException {
        final NetHttpTransport httpTransport = GoogleNetHttpTransport.newTrustedTransport();
        Credential credential = authorize(httpTransport);
        return new YouTube.Builder(httpTransport, JSON_FACTORY, credential)
                .setApplicationName(APPLICATION_NAME)
                .build();
    }

    /**
     * Call function to create API service object. Define and
     * execute API request. Print API response.
     *
     * @throws GeneralSecurityException, IOException, GoogleJsonResponseException
     */
    public static void getChatId(String videoId)
            throws GeneralSecurityException, IOException, GoogleJsonResponseException {
        YouTube youtubeService = getService();
        // Define and execute the API request
        YouTube.LiveBroadcasts.List request = youtubeService.liveBroadcasts()
                .list("snippet");
        LiveBroadcastListResponse response = request.setId(videoId).execute();
        YouTubeNormalChatAPI.chatId = response.getItems().get(0).getSnippet().getLiveChatId();
        YouTubeNormalChatAPI.getService();
        Timer timer = new Timer();
        TimerTask task = new NormalChatTask();
        timer.schedule(task, 0, 5000);
    }
}

包命令;
导入com.google.api.client.auth.oauth2.Credential;
导入com.google.api.client.extensions.java6.auth.oauth2.AuthorizationCodeInstalledApp;
导入com.google.api.client.extensions.jetty.auth.oauth2.LocalServerReceiver;
导入com.google.api.client.googleapis.auth.oauth2.googleaauthorizationcodeflow;
导入com.google.api.client.googleapis.auth.oauth2.GoogleClientSecrets;
导入com.google.api.client.googleapis.javanet.GoogleNetHttpTransport;
导入com.google.api.client.googleapis.json.GoogleJsonResponseException;
导入com.google.api.client.http.javanet.NetHttpTransport;
导入com.google.api.client.json.JsonFactory;
导入com.google.api.client.json.jackson2.JacksonFactory;
导入com.google.api.services.youtube.youtube;
导入com.google.api.services.youtube.model.LiveBroadcastListResponse;
导入java.io.*;
导入java.security.GeneralSecurityException;
导入java.util.array;
导入java.util.Collection;
导入java.util.Timer;
导入java.util.TimerTask;
公共类YouTubeLiveStreamAPI{
静态字符串流线型;
私有静态最终字符串CLIENT\u SECRETS=“CLIENT\u secret.json”;
私有静态最终收集作用域=
Arrays.asList(“https://www.googleapis.com/auth/youtube.readonly");
私有静态最终字符串应用程序\u NAME=“API代码示例”;
私有静态最终JsonFactory JSON_FACTORY=JacksonFactory.getDefaultInstance();
/**
*创建授权凭据对象。
*
*@返回授权凭证对象。
*@抛出异常
*/
公共静态凭据授权(最终NetHttpTransport httpTransport)引发IOException{
//加载客户端机密。
文件测试=新文件(“src/main/resources/client_secret.json”);
System.out.println(test.exists());
FileInputStream in=新的FileInputStream(测试);
//InputStream in=YouTubeLiveStreamAPI.class.getResourceAsStream(客户端机密);
谷歌客户机密=
load(JSON_工厂,新的InputStreamReader(in));
//生成流并触发用户授权请求。
GoogleAuthorizationCodeFlow=
新的GoogleAuthorizationCodeFlow.Builder(httpTransport、JSON_工厂、clientSecrets、SCOPES)
.build();
凭证=
新的AuthorizationCodeInstalledApp(流,新的LocalServerReceiver())。授权(“用户”);
返回凭证;
}
/**
*生成并返回授权的API客户端服务。
*
*@返回授权的API客户端服务
*@抛出GeneralSecurityException,IOException
*/
公共静态YouTube getService()抛出GeneralSecurityException、IOException、GoogleJsonResponseException{
最终NetHttpTransport-httpTransport=GoogleNetHttpTransport.newTrustedTransport();
凭证=授权(httpTransport);
返回新的YouTube.Builder(httpTransport、JSON_工厂、凭证)
.setApplicationName(应用程序名称)
.build();
}
/**
*调用函数来创建API服务对象。定义并
*执行API请求。打印API响应。
*
*@throws-GeneralSecurityException、IOException、GoogleJsonResponseException
*/
公共静态void getChatId(字符串videoId)
抛出GeneralSecurityException、IOException、GoogleJsonResponseException{
YouTube YouTube服务=getService();
//定义并执行API请求
YouTube.LiveBroadcasts.List请求=youtubeService.LiveBroadcasts()
.列表(“片段”);
LiveBroadcastListResponse=request.setId(videoId.execute();
YouTubeNormalChatAPI.chatId=response.getItems().get(0.getSnippet().getLiveChatId();
YouTubeNormalChatAPI.getService();
定时器=新定时器();
TimerTask任务=新的NormalChatTask();
时间表(任务,0,5000);
}
}
以下是我的依赖项:

<dependency>
            <groupId>org.spigotmc</groupId>
            <artifactId>spigot-api</artifactId>
            <version>1.12.2-R0.1-SNAPSHOT</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>com.google.api-client</groupId>
            <artifactId>google-api-client</artifactId>
            <version>1.30.6</version>
        </dependency>
        <dependency>
            <groupId>com.google.oauth-client</groupId>
            <artifactId>google-oauth-client-jetty</artifactId>
            <version>1.30.4</version>
        </dependency>
        <dependency>
            <groupId>com.google.apis</groupId>
            <artifactId>google-api-services-youtube</artifactId>
            <version>v3-rev212-1.25.0</version>
        </dependency>

org.spigotmc
插口api
1.12.2-R0.1-快照
假如
com.google.api-client
谷歌api客户端
1.30.6
com.google.oauth-client
谷歌oauth客户端jetty
1.30.4
com.google.api
谷歌api服务youtube
v3-rev212-1.25.0

我知道这是一件漫长而复杂的事情,但我非常感谢您的帮助

您似乎缺少一个类/包com.google.api.client.json。JsonFactory@JoakimDanielson问题是,我确实导入了它,如果我正常运行程序,它就会工作。只是在通过插口运行时出现了一些奇怪的错误。您是否先创建了一个jar,然后将其部署到您的插口服务器?如果是这样,你是通过mvn包创建jar的吗?@SteffenJacobs我没有,我应该这样做吗?我所做的只是将其添加到依赖项并运行mvn安装。如果这是不正确的,说明或链接到一些资源,以及关于整个部署的说明将是一个很大的挑战