-3

This is my MRE.

Here is how my project is structured

Project structure here

Settings.json file

{
  "java.project.referencedLibraries": [
    "lib/weka.jar"
  ]
}

Main.java

import weka.core.Instances;

public class Main {
    public static void main(String[] args) throws Exception {
        // Load a dataset (replace with your .arff file)
        System.out.println("Hello");
    }
}

main.class

// Source code is decompiled from a .class file using FernFlower decompiler (from Intellij IDEA).
public class Main {
   public Main() {
   }

   public static void main(String[] var0) throws Exception {
      System.out.println("Hello");
   }
}

The error coming from main.java is

Unused Import(hints(1): 1:1-1:28)
package weka.core does not exist(errors(1): 1:8-1:12)
The import weka.core.Instances is never usedJava(268435844)
package weka
weka

img of error

upon running

javac -cp .;lib/weka.jar src/Main.java

compiles with no issues. this cmd built a Main.class in my src folder.

however, upon running

java -cp .;lib/weka.jar Main

the error is

Error: Could not find or load main class Main
Caused by: java.lang.ClassNotFoundException: Main
New contributor
Christopher Pray is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.
10
  • 1
    As I told you in staging ground, I cannot reproduce this. javac -cp .:weka.jar Mcve.java with import weka; in Mcve.java produces a class file, no errors. Maybe edit and simplify the question. If you can compile on the command line, it's a vscode problem. If you can't maybe the download was bad. unzip -l weka.jar should show what's in the jar file. Add a minimal reproducible example, i.e., start with just importing weka and compiling just 1 .java file. As is, this may not be reproducible. Commented yesterday
  • Note that the question has nothing to do with VSCode. VSCode does just what the Java compiler does. Can you compile the code using a command line? Commented yesterday
  • thank you for your reply robert. wen i run javac -cp .;lib/weka.jar src/Main.java -d build/ no class file is created. when i am in my vscode terminal, i do not think i can run unzip, however the powershell equivalent should be Expand-Archive as i searched up. i did this and it says "jar is not a supported archive file format. .zip is the only supported archive file format. At line:1 char:1" Commented yesterday
  • @SergeyAKryukov thank you for your reply sergey. whenever i run: javac src/Main.java, in cmd prompt in my file directory C:/Users/tacob/Desktop/java_ml_project2, the same error "package Weka.core does not exist" comes up Commented yesterday
  • 1
    Well, perhaps you have to put all together. It looks like you have only two artifacts on input, 1) weka.jar and 2) Main.java (with the class Main), and your only issue is messing up some paths... How come you mix up VSCode and command line. Can you isolate things and only build and run anything via a command line, not VSCode? And then address VSCode build and run... Commented yesterday

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.