简体   繁体   English

使用 Gradle 运行 Java 时出现 ClassNotFoundException

[英]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.

相关问题 Java:使用netty运行程序时出现ClassNotFoundException [Gradle] - Java : ClassNotFoundException when running program with netty [Gradle] Gradle:java.lang.ClassNotFoundException:运行优步时 Jar - Gradle : java.lang.ClassNotFoundException : When running Uber Jar 在 cmd 中运行基于 gradle 的 Java 应用程序时出现 ClassNotFoundException - ClassNotFoundException while running gradle based Java Application in cmd 为新的源集运行testNG测试任务时(等级)ClassNotFoundException - (Gradle) ClassNotFoundException when running testNG test task for new source set Java Web 开始 - 运行时出现 ClassNotFoundException - Java Web Start - ClassNotFoundException when running 在 Windows 上运行 mvn exec:java 时出现 ClassNotFoundException - ClassNotFoundException when running mvn exec:java on Windows 运行java -jar时的java.lang.ClassNotFoundException - java.lang.ClassNotFoundException when running java -jar 在CMD中运行时发生ClassNotFoundException - ClassNotFoundException when running in CMD 运行appium脚本时出现java.lang.ClassNotFoundException - java.lang.ClassNotFoundException is comming when running appium script 在Spark集群上运行程序时出现java.lang.ClassNotFoundException - java.lang.ClassNotFoundException when running program on spark cluster
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM