gpt4 book ai didi

Java编译错误: package does not exist

转载 作者:搜寻专家 更新时间:2023-11-01 03:31:31 26 4
gpt4 key购买 nike

在我的工作区 (wsPrivate) 中,我有 3 个 gradle 项目。

  • 刽子手
  • 像素 View
  • 报告

PixelView 和 Reports 项目编译良好。然而,Hangman 使用了这两个项目,有些在编译时找不到包。
查看下面的错误(在编译 Hangman 时弹出):

D:\_wsGitlab\wsPrivate\Hangman\src\main\java\game\core\Game.java:10: error: package hangman does not exist
import hangman.Messages;
^
D:\_wsGitlab\wsPrivate\Hangman\src\main\java\game\core\Game.java:13: error: package viewer does not exist
import viewer.Box;
^
D:\_wsGitlab\wsPrivate\Hangman\src\main\java\game\core\Game.java:14: error: package viewer.figures.boxes does not exist
import viewer.figures.boxes.Borders;

我已经阅读了几乎所有我能找到的关于类路径的信息以及如何解决这个[在我看来]“范围问题”,我也尝试了多种解决方案,但我认为我让事情变得更糟。该程序无需在 eclipse 中编译就可以正常工作,因此我假设代码是正确的。

我现在已经在这上面停留了 3 天,所以如果有人能向我解释我在这条路上开车的地方,那就太好了。如果需要更多信息:请询问 ;)

所以这基本上就是我现在所拥有的:

我的包布局和添加的库:

layout of my packages and added library

我添加到 Hangman 的自定义库:

Custom library that I've added to Hangman

Hangman 项目构建路径上的项目:

Projects on build path of project Hangman

Hangman 项目的订购和导出:

Order and export of project Hangman

另外两个被引用的项目(pixelview/reports):

Other two projects that are referenced

最后但同样重要的是我的build.gradle:

apply plugin: 'application'

mainClassName = "game.core.Game"

repositories {
jcenter()
}

dependencies {
compile 'org.apache.commons:commons-math3:3.6.1'
implementation 'com.google.guava:guava:23.0'
testImplementation 'junit:junit:4.12'
}

jar {
baseName = 'HangmanGame'
version = '2.00.0'
manifest {
attributes(
'Class-Path': configurations.compile.collect { it.getName() }.join(' '),
'Main-Class': 'game.core.Game'
)
}
}

最佳答案

您说您有三个项目 - 我将其解释为一个 Gradle 项目和三个独立的 Gradle 子项目。

如果是这样,你需要一个 settings.gradle 根级别的文件,内容如下

include 'Hangman', 'PixelView', 'Reports'

您可以阅读更多关于 authoring multiproject Gradle builds 的信息在 Gradle 文档中。

关于Java编译错误: package does not exist,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51971421/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com