问题描述
这是我第一次使用maven,我正在尝试使用托管在https://code.google.com/archive/p/program-ab/上的program-ab实现制作聊天机器人,并且我一直在关注@L_502_1@
PS D:\chatterBox\chatterBox> mvn clean install
[INFO] Scanning for projects...
[INFO]
[INFO] ---------------------< com.chatterBox:chatterBox >----------------------
[INFO] Building chatterBox 0.0.1
[INFO] --------------------------------[ jar ]---------------------------------
[INFO]
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ chatterBox ---
[INFO] Deleting D:\chatterBox\chatterBox\target
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ chatterBox ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] copying 82 resources
[INFO]
[INFO] --- maven-compiler-plugin:3.8.0:compile (default-compile) @ chatterBox ---
[WARNING] Can't extract module name from Ab.jar: Main.class found in top-level directory (unnamed package not allowed in module)
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 4 source files to D:\chatterBox\chatterBox\target\classes
[INFO] -------------------------------------------------------------
[ERROR] COMPILATION ERROR :
[INFO] -------------------------------------------------------------
[ERROR] /D:/chatterBox/chatterBox/src/main/java/chatbot/chatbot.java:[4,23] package org.alicebot.ab does not exist
[ERROR] /D:/chatterBox/chatterBox/src/main/java/chatbot/chatbot.java:[5,23] package org.alicebot.ab does not exist
[ERROR] /D:/chatterBox/chatterBox/src/main/java/chatbot/chatbot.java:[6,23] package org.alicebot.ab does not exist
[ERROR] /D:/chatterBox/chatterBox/src/main/java/chatbot/chatbot.java:[7,23] package org.alicebot.ab does not exist
[ERROR] /D:/chatterBox/chatterBox/src/main/java/chatbot/chatbot.java:[8,23] package org.alicebot.ab does not exist
[ERROR] /D:/chatterBox/chatterBox/src/main/java/chatbot/chatbot.java:[9,29] package org.alicebot.ab.utils does not exist
[ERROR] /D:/chatterBox/chatterBox/src/main/java/chatbot/chatbot.java:[20,13] cannot find symbol
symbol: variable MagicBooleans
location: class chatbot.chatbot
[ERROR] /D:/chatterBox/chatterBox/src/main/java/chatbot/chatbot.java:[21,13] cannot find symbol
symbol: class Bot
location: class chatbot.chatbot
[ERROR] /D:/chatterBox/chatterBox/src/main/java/chatbot/chatbot.java:[21,27] cannot find symbol
symbol: class Bot
location: class chatbot.chatbot
[ERROR] /D:/chatterBox/chatterBox/src/main/java/chatbot/chatbot.java:[22,13] cannot find symbol
symbol: class Chat
location: class chatbot.chatbot
[ERROR] /D:/chatterBox/chatterBox/src/main/java/chatbot/chatbot.java:[22,36] cannot find symbol
symbol: class Chat
location: class chatbot.chatbot
[ERROR] /D:/chatterBox/chatterBox/src/main/java/chatbot/chatbot.java:[28,28] cannot find symbol
symbol: variable IoUtils
location: class chatbot.chatbot
[ERROR] /D:/chatterBox/chatterBox/src/main/java/chatbot/chatbot.java:[30,32] cannot find symbol
symbol: variable MagicStrings
location: class chatbot.chatbot
[ERROR] /D:/chatterBox/chatterBox/src/main/java/chatbot/chatbot.java:[38,25] cannot find symbol
symbol: variable MagicBooleans
location: class chatbot.chatbot
[ERROR] /D:/chatterBox/chatterBox/src/main/java/chatbot/chatbot.java:[38,24] illegal parenthesized expression
[ERROR] /D:/chatterBox/chatterBox/src/main/java/chatbot/chatbot.java:[39,78] cannot find symbol
symbol: class History
location: class chatbot.chatbot
[INFO] 16 errors
[INFO] -------------------------------------------------------------
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 4.799 s
[INFO] Finished at: 2020-08-17T17:27:38+05:30
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.0:compile (default-compile) on project chatterBox: Compilation failure: Compilation failure:
[ERROR] /D:/chatterBox/chatterBox/src/main/java/chatbot/chatbot.java:[4,13] cannot find symbol
[ERROR] symbol: variable MagicBooleans
[ERROR] location: class chatbot.chatbot
[ERROR] /D:/chatterBox/chatterBox/src/main/java/chatbot/chatbot.java:[21,13] cannot find symbol
[ERROR] symbol: class Bot
[ERROR] location: class chatbot.chatbot
[ERROR] /D:/chatterBox/chatterBox/src/main/java/chatbot/chatbot.java:[21,27] cannot find symbol
[ERROR] symbol: class Bot
[ERROR] location: class chatbot.chatbot
[ERROR] /D:/chatterBox/chatterBox/src/main/java/chatbot/chatbot.java:[22,13] cannot find symbol
[ERROR] symbol: class Chat
[ERROR] location: class chatbot.chatbot
[ERROR] /D:/chatterBox/chatterBox/src/main/java/chatbot/chatbot.java:[22,36] cannot find symbol
[ERROR] symbol: class Chat
[ERROR] location: class chatbot.chatbot
[ERROR] /D:/chatterBox/chatterBox/src/main/java/chatbot/chatbot.java:[28,28] cannot find symbol
[ERROR] symbol: variable IoUtils
[ERROR] location: class chatbot.chatbot
[ERROR] /D:/chatterBox/chatterBox/src/main/java/chatbot/chatbot.java:[30,32] cannot find symbol
[ERROR] symbol: variable MagicStrings
[ERROR] location: class chatbot.chatbot
[ERROR] /D:/chatterBox/chatterBox/src/main/java/chatbot/chatbot.java:[38,25] cannot find symbol
[ERROR] symbol: variable MagicBooleans
[ERROR] location: class chatbot.chatbot
[ERROR] /D:/chatterBox/chatterBox/src/main/java/chatbot/chatbot.java:[38,78] cannot find symbol
[ERROR] symbol: class History
[ERROR] location: class chatbot.chatbot
[ERROR] -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors,re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more @R_720_4045@ion about the errors and possible solutions,please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException
我认为类路径有问题,但我无法解决。如果有人知道我在哪里做错了,请指导。
chatbot.java
package chatbot;
import java.io.File;
import org.alicebot.ab.Bot;
import org.alicebot.ab.Chat;
import org.alicebot.ab.History;
import org.alicebot.ab.MagicBooleans;
import org.alicebot.ab.MagicStrings;
import org.alicebot.ab.utils.IoUtils;
public class chatbot {
private static final boolean TRACE_MODE = false;
static String botName = "super";
public static void main(String[] args) {
try {
String resourcesPath = getResourcesPath();
System.out.println(resourcesPath);
MagicBooleans.trace_mode = TRACE_MODE;
Bot bot = new Bot("super",resourcesPath);
Chat chatSession = new Chat(bot);
bot.brain.nodeStats();
String textLine = "";
while(true) {
System.out.print("Human : ");
textLine = IoUtils.readInputTextLine();
if ((textLine == null) || (textLine.length() < 1))
textLine = MagicStrings.null_input;
if (textLine.equals("q")) {
System.exit(0);
} else if (textLine.equals("wq")) {
bot.writeQuit();
System.exit(0);
} else {
String request = textLine;
if (MagicBooleans.trace_mode)
System.out.println("STATE=" + request + ":THAT=" + ((History) chatSession.thatHistory.get(0)).get(0) + ":TOPIC=" + chatSession.predicates.get("topic"));
String response = chatSession.multisentenceRespond(request);
while (response.contains("<"))
response = response.replace("<","<");
while (response.contains(">"))
response = response.replace(">",">");
System.out.println("Robot : " + response);
}
}
} catch (Exception e) {
e.printstacktrace();
}
}
private static String getResourcesPath() {
File currDir = new File(".");
String path = currDir.getAbsolutePath();
path = path.substring(0,path.length() - 2);
System.out.println(path);
String resourcesPath = path + File.separator + "src" + File.separator + "main" + File.separator + "resources";
return resourcesPath;
}
}
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.chatterBox</groupId>
<artifactId>chatterBox</artifactId>
<version>0.0.1</version>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>10</maven.compiler.source>
<maven.compiler.target>10</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-controls</artifactId>
<version>11</version>
</dependency>
<dependency>
<artifactId>com.google</artifactId>
<groupId>Ab</groupId>
<version>0.0.4.3</version>
<scope>system</scope>
<systemPath>${pom.basedir}/lib/Ab.jar</systemPath>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
<configuration>
<release>10</release>
</configuration>
</plugin>
<plugin>
<groupId>org.openjfx</groupId>
<artifactId>javafx-maven-plugin</artifactId>
<version>0.0.4</version>
<configuration>
<mainClass>chatbot.App</mainClass>
</configuration>
</plugin>
</plugins>
</build>
</project>
This is the directory structure
This is the directory structure of Program-ab
解决方法
当前看到的问题是您的库Ab.jar有一个名为Main.class的类,该类不驻留在任何软件包中。 Java 10之后(据我所知,您正在使用Java 10)不允许将其驻留在模块内。因此,对该库的更改将能够修复您看到的错误。尝试使用Java 8编译项目。