0

I have created an application that uses selenium-server-standalone-2.47.1.jar and javax.mail.jar. The code works on eclipse, but I would like to run the same from command line. So I exported the project to a runnable jar file which contains both selenium and javax.mail.jar. My code contains RTC.java which has the Main function and another Ex.java. Both the class files are generated in com folder. My App1.jar file is located in C:\installers.

I used the command:

 c:\installers> java -cp App1.jar com.RTC

It says:

Exception in thread "main" java.lang.NoClassDefFoundError: org.openqa.selenium.WebDriver

Further I used:

 java -cp .App1.jar com.RTC

Then it says could not find or load main class com.RTC.

What am I doing wrong?

Michał Szkudlarek
  • 1,443
  • 1
  • 21
  • 35
Ansu
  • 41
  • 8

2 Answers2

0

I used the command:

c:\installers> java -cp App1.jar com.RTC

It says:

Exception in thread "main" java.lang.NoClassDefFoundError:
org.openqa.selenium.WebDriver

That exception usually means that a .class file was found but it didn't contain the right class. Check how you're putting it into the JAR. It's directory and file name must match its package and class name.

It sometimes also seems to mean that a secondary class wasn't found. Normally secondary JAR files are mentioned in the class-path entry of the manifest of the main JAR file, along with the main-classname, so you can use

java -jar App1.jar

Further I used:

java -cp .App1.jar com.RTC

Then it says could not find or load main class com.RTC.

I'm not surprised. If the first command got as far as it did, the JAR filename doesn't start with a dot. Cannot imagine why you tried this. It is nonsense.

user207421
  • 305,947
  • 44
  • 307
  • 483
0

I found the solution. I need not create a jar file which has the reference jars. I have to mention my jar which has my code and the reference jars that I am using in the class path.

My code is in App.jar.The reference jars are

selenium-server-standalone-2.47.1.jar and javax.mail.jar.

so I used c:\installers> java -cp selenium-server-standalone-2.47.1.jar;javax.mail.jar;App.jar com.RTC

Thank You.

Ansu
  • 41
  • 8