Skip to main content
added 352 characters in body
Source Link
Satya Vejus
  • 313
  • 1
  • 3
  • 11

I am trying to run the following method in Loader.java from the command line:

public static void method(String path, String word)

As seen above, I must pass in the variables path and word, and I want the command line to display the System.out.println()'s in the method.

What command can I run to do this?

Note: when I run the following commands,

javac *.java
jar -cvf Loader.jar Loader.class
java -cp ./Loader.jar Loader

I get the following error:

Caused by: java.lang.NoClassDefFoundError: path/to/Loader (wrong name: Loader)

What must I do to successfully run method from the command line?

Here is minimum reproducible version of Loader.java:

public class Loader {
     public static void main(String[] args) {
          method("my/path", "my_word");
     }
     public static void method(String path, String word) {
          System.out.println("Output after doing something");
     }
}

I am trying to run the following method in Loader.java from the command line:

public static void method(String path, String word)

As seen above, I must pass in the variables path and word, and I want the command line to display the System.out.println()'s in the method.

What command can I run to do this?

Note: when I run the following commands,

javac *.java
jar -cvf Loader.jar Loader.class
java -cp ./Loader.jar Loader

I get the following error:

Caused by: java.lang.NoClassDefFoundError: path/to/Loader (wrong name: Loader)

What must I do to successfully run method from the command line?

I am trying to run the following method in Loader.java from the command line:

public static void method(String path, String word)

As seen above, I must pass in the variables path and word, and I want the command line to display the System.out.println()'s in the method.

What command can I run to do this?

Note: when I run the following commands,

javac *.java
jar -cvf Loader.jar Loader.class
java -cp ./Loader.jar Loader

I get the following error:

Caused by: java.lang.NoClassDefFoundError: path/to/Loader (wrong name: Loader)

What must I do to successfully run method from the command line?

Here is minimum reproducible version of Loader.java:

public class Loader {
     public static void main(String[] args) {
          method("my/path", "my_word");
     }
     public static void method(String path, String word) {
          System.out.println("Output after doing something");
     }
}
Source Link
Satya Vejus
  • 313
  • 1
  • 3
  • 11

How to run Java method with arguments from command line?

I am trying to run the following method in Loader.java from the command line:

public static void method(String path, String word)

As seen above, I must pass in the variables path and word, and I want the command line to display the System.out.println()'s in the method.

What command can I run to do this?

Note: when I run the following commands,

javac *.java
jar -cvf Loader.jar Loader.class
java -cp ./Loader.jar Loader

I get the following error:

Caused by: java.lang.NoClassDefFoundError: path/to/Loader (wrong name: Loader)

What must I do to successfully run method from the command line?