0

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

  • Keep in mind that classes in a named package cannot use classes in the unnamed package (i.e. default package, or no package). Classes without a package cannot be imported. Except for small demo-like programs it's best to place all classes in a named package. Also, as pointed out in [the given answer](https://stackoverflow.com/a/63451858/6395627), the module system (added in Java 9) does not allow classes to be in the unnamed package; however, that should only matter if you're using modules (i.e. you have a `module-info.java` file). – Slaw Aug 17 '20 at 14:16
  • And in case there's a confusion of terms, [Maven modules](https://maven.apache.org/guides/mini/guide-multiple-modules.html) are different than [Java modules](https://www.oracle.com/corporate/features/understanding-java-9-modules.html) (although they typically overlap). – Slaw Aug 17 '20 at 14:25
  • [This](https://i.stack.imgur.com/0lPCn.png) is what is inside the Ab.jar. It would have helped if you had listed the files (especially this root directory) in your Question. – Scratte Aug 17 '20 at 20:09
  • okay I will post an image of this directory structure as well. Do reply and help me out @Scratte – Srishti gupta Aug 18 '20 at 14:32
  • Generally you should not post images of structures, but instead as text in a code block. I did it because it was just in a comment. But as the Answer already explained, the problem is the Main.class is the root folder. I imagine you can use it with java 8. I do not use maven and I also do not use an IDE, so I'm unlikely to be able to try setting the Ab.jar on the classpath to find out how it will work out with those tools. – Scratte Aug 18 '20 at 15:02

1 Answers1

0

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.

Nemanja
  • 3,295
  • 11
  • 15
  • Isn't there any problem with the classpath here ?Because "unnamed packed not allowed" is just a warning and when I delete module-info.java ,I dont get this warning anymore.Still I am unable to compile the Chatbot.java class. So will extracting the modules from the jar file will do for me or I have to set classpath manually as I cant see .classpath file as well here – Srishti gupta Aug 17 '20 at 15:04