1

I have 4 Java-Data:

Common.java
Constants.java
KeywordsEditor.java
ExecutionEngine.java (There is here a Main-Method) 

I have successful compiled in Command-Line with this Command from Project-Directory (C:\ProjectDemo\src\main\java\ValueInput)

javac -cp "C:\Users\ABC\selenium-java-2.48.2\selenium-2.48.2\selenium-java-2.48.2.jar;selenium-server-standalone-3.141.59.j‌​ar" *.java 

I got 4 Data .class in the same Directory. Now i want to run them with this code:

java -cp "C:\Users\ABC\selenium-java-2.48.2\selenium-2.48.2\selenium-java-2.48.2.jar;selenium-server-standalone-3.141.59.j‌​ar" ExecutionEngine 

But i got Error:

Error: ExecutionEngine main class could not be found or loaded 

``` 
I've tried with some same code else:
```
java -cp "C:\Users\ABC\selenium-java-2.48.2\selenium-2.48.2\selenium-java-2.48.2.jar;libs\*;selenium-server-standalone-3.141.59.j‌​ar" ExecutionEngine 

java -cp "C:\Users\ABC\selenium-java-2.48.2\selenium-2.48.2\selenium-java-2.48.2.jar;libs/*;selenium-server-standalone-3.141.59.j‌​ar" ExecutionEngine 
```

And some more, but they don't work. Can somebody help me?

1 Answers1

1

Update

From your comment, I learnt that you have package ValueInput; mentioned in ExecutionEngine.java. Therefore, you should use the switch -d when compiling:

javac -d . -cp "C:\Users\ABC\selenium-java-2.48.2\selenium-2.48.2\selenium-java-2.48.2.jar;selenium-server-standalone-3.141.59.j‌​ar" *.java

The option -d . asks the compiler to place the generated class files at the current directory. Now, if you use the command ls in Mac/Unix or dir in Windows, you will see a directory, ValueInput has been created and all the .class files have been placed inside this directory. Learn more about the switches by simply using the command javac

In order to execute ExecutionEngine.class, you can now use the following command:

java -cp ".;C:\Users\ABC\selenium-java-2.48.2\selenium-2.48.2\selenium-java-2.48.2.jar;selenium-server-standalone-3.141.59.j‌​ar" ValueInput.ExecutionEngine 

You can also check this answer for a similar solution.

Side note: You should follow the Java naming conventions. As per the convention, the name of the package should be something like value.input.

Original answer

The root cause of the problem is using only jars with -cp. You missed realizing that your ExecutionEngine.class is not in the jars; rather it is at the current directory which is denoted by a dot (.) which you missed to include in the classpath.

Thus, the correct command will be:

java -cp ".;C:\Users\ABC\selenium-java-2.48.2\selenium-2.48.2\selenium-java-2.48.2.jar;selenium-server-standalone-3.141.59.j‌​ar" ExecutionEngine 

It doesn't matter where you put . i.e. the current directory e.g. the following will also work for you:

java -cp "C:\Users\ABC\selenium-java-2.48.2\selenium-2.48.2\selenium-java-2.48.2.jar;selenium-server-standalone-3.141.59.j‌​ar;." ExecutionEngine 

Note for Mac:

The separator used for this purpose in Mac is : instead of ; e.g.

javac -cp mysql-connector-java-5.1.49.jar MysqlDemo.java
java -cp mysql-connector-java-5.1.49.jar:. MysqlDemo

Note for Java-11 onwards: Java-11 allows launching Single-File Source-Code programs without compiling e.g.

java -cp mysql-connector-java-5.1.49.jar MysqlDemo.java

You can learn more about it from this article.

Arvind Kumar Avinash
  • 71,965
  • 6
  • 74
  • 110
  • Hi, Thanks for your answer, i have tried both solutions, but it still not work. I'm working with Windows, not with Linux – MusterTester Aug 12 '20 at 16:03
  • Try removing the double-quotes. – Arvind Kumar Avinash Aug 12 '20 at 16:05
  • @MusterTester - Does `ExecutionEngine.java` have `package ...` line in the beginning? – Arvind Kumar Avinash Aug 12 '20 at 17:20
  • Yes, 4 java-Data are in package ValueInput (C:\ProjectDemo\src\main\java\ValueInput). After compiled i'v got 8 data (four .java and 4 .class in the same Directory) – MusterTester Aug 12 '20 at 17:26
  • It doesn't work. I'm also in this directory: C:\ProjectDemo\src\main\java\ValueInput>java -cp ".;C:\Links\H_MA\selenium-java-2.48.2\selenium-2.48.2\selenium-java-2.48.2.jar;selenium-server-standalone-3.141.59.jar" ValueInput/ExecutionEngine – MusterTester Aug 12 '20 at 17:41
  • @MusterTester - I've added an update to my answer. Feel free to comment in case it doesn't work. – Arvind Kumar Avinash Aug 12 '20 at 17:48
  • Thank you for your response. This Problem make me sick. I'v tried all possibilities, but it still not work, haizzzzzzz :( – MusterTester Aug 12 '20 at 17:56
  • I need to check your java files. If you can send me the files, I can look into it and help you solve the problem. – Arvind Kumar Avinash Aug 12 '20 at 18:03
  • Hi, Don't worry more about that. It was a spelling mistake, my bad !!! This work now with your solution: java -cp ".;C:\Users\ABC\selenium-java-2.48.2\selenium-2.48.2\selenium-java-2.48.2.jar;selenium-server-standalone-3.141.59.j‌​ar" ExecutionEngine. Many thanks :) – MusterTester Aug 13 '20 at 09:41