[英]ClassNotFoundException when running Java with Gradle
I recently started learning how to use Gradle and am having an issue of a ClassNotFoundException when trying to run a server.我最近开始学习如何使用 Gradle 并且在尝试运行服务器时遇到 ClassNotFoundException 问题。 I'm not sure where I'm going wrong with this.我不确定我哪里出了问题。 I have no problems running the server or client in the command line, so I'm not sure why Gradle's giving me so much trouble.我在命令行中运行服务器或客户端没有问题,所以我不确定为什么 Gradle 给我带来这么多麻烦。
Am I just misunderstanding how Gradle's classpath declaration works?我只是误解了 Gradle 的类路径声明是如何工作的吗? After looking online, I thought it might be because my code wasn't directly in a src/main folder, so I moved both files to one, but I'm still getting the same error.在网上看了之后,我想可能是因为我的代码没有直接在 src/main 文件夹中,所以我将两个文件都移到了一个,但我仍然遇到同样的错误。
Any help would be greatly appreciated.任何帮助将不胜感激。
This is the classpath:这是类路径:
classpath = sourceSets.main.runtimeClasspath
main = 'ser321-spring2021-A-amarce1.Assignment3.tcp.src.main.Server'
And my GitHub/command line path is as follows:而我的 GitHub/命令行路径如下:
ser321-spring2021-A-amarce1/Assignment3/tcp/src/main/Server.java
The class path starts inside the source set, ie after /src/main/…
. class 路径在源集内部开始,即在/src/main/…
之后。 Your class Server
is located in the default package.您的 class Server
位于默认的 package 中。 I assume it does not have a package com.example;
我假设它没有package com.example;
as first line.作为第一行。
You need to move it to the correct package:您需要将其移动到正确的 package:
…/src/main/ser321-spring2021-A-amarce1/Assignment3/tcp/Server.java
and add the corresponding package declaration:并添加相应的 package 声明:
package ser321-spring2021-A-amarce1.Assignment3.tcp;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.