简体   繁体   中英

Can't extract module name from Ab.jar: Main.class found in top-level directory (unnamed package not allowed in module)

This is my first time using maven and I am trying to make a Chat bot using program-ab implementation which is hosted on https://code.google.com/archive/p/program-ab/ and I have been following https://howtodoinjava.com/ai/java-aiml-chatbot-example/ <-- this tutorial. But as I am using maven I chose to install Ab.jar into your local maven repository but when I run the command mvn clean package or mvn clean compile I get the "[WARNING] Can't extract module name from Ab.jar: Main.class found in top-level directory (unnamed package not allowed in module)" but the project does get built. The problem is when I make Chatbot program which is using classes defined in Ab.jar file and again run mvn clean install I get the following error..

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,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
[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,24] illegal parenthesized expression
[ERROR] /D:/chatterbox/chatterbox/src/main/java/chatbot/Chatbot.java:[39,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 information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException

I think there's a problem with the classpath but I couldn't get how to resolve it. If anyone know where I am doing mistake plz guide.

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("&lt;"))
                                response = response.replace("&lt;", "<");
                            while (response.contains("&gt;"))
                                response = response.replace("&gt;", ">");
                            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

The problem that you see currently is that your library Ab.jar has a class named Main.class which doesn't reside in any of the packages. This is not allowed post Java 10 (As far as I can see you are using java 10 ) to reside within a module. Hence the change to that library would be able to fix the error you see. Try to use Java 8 to compile your project.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM