Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to run a maven Project?

I have created java project called OneReports. How can i shift the entire project to Maven. Once i shifted to maven how can run in command prompt. Currently i have the problem of dependency. So i plan to move the project. Could anyone help me to step by step process.

C:\Jars>javac -cp "C:\Program Files\Java\selenium\*.jar";"OneReports.jar";"testng.jar" test\TestngTestSuiteUsingXML.java

C:\Jars>java -cp "C:\Program Files\Java\selenium\*.jar";"OneReports.jar";"testng.jar" test.TestngTestSuiteUsingXML
[[TestNGClassFinder]] Unable to read methods on class test.LoginOneReports - unable to resolve class reference org/openqa/selenium/WebDriver
Exception in thread "main" java.lang.NoClassDefFoundError: org/openqa/selenium/WebDriver
    at java.lang.Class.getDeclaredMethods0(Native Method)
    at java.lang.Class.privateGetDeclaredMethods(Unknown Source)
    at java.lang.Class.privateGetPublicMethods(Unknown Source)
    at java.lang.Class.getMethods(Unknown Source)
    at org.testng.internal.TestNGClassFinder.<init>(TestNGClassFinder.java:59)
    at org.testng.TestRunner.initMethods(TestRunner.java:409)
    at org.testng.TestRunner.init(TestRunner.java:235)
    at org.testng.TestRunner.init(TestRunner.java:205)
    at org.testng.TestRunner.<init>(TestRunner.java:153)
    at org.testng.SuiteRunner$DefaultTestRunnerFactory.newTestRunner(SuiteRunner.java:522)
    at org.testng.SuiteRunner.init(SuiteRunner.java:157)
    at org.testng.SuiteRunner.<init>(SuiteRunner.java:111)
    at org.testng.TestNG.createSuiteRunner(TestNG.java:1299)
    at org.testng.TestNG.createSuiteRunners(TestNG.java:1286)
    at org.testng.TestNG.createSuiteRunners(TestNG.java:1289)
    at org.testng.TestNG.runSuitesLocally(TestNG.java:1140)
    at org.testng.TestNG.run(TestNG.java:1057)
    at test.TestngTestSuiteUsingXML.main(TestngTestSuiteUsingXML.java:20)
Caused by: java.lang.ClassNotFoundException: org.openqa.selenium.WebDriver
    at java.net.URLClassLoader$1.run(Unknown Source)
    at java.net.URLClassLoader$1.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    ... 18 more

C:\Jars>

like image 789
testing Avatar asked Dec 27 '25 20:12

testing


2 Answers

  1. You'll need to install maven.
  2. Then create a maven archetype. The archetype is a base project you can add your code into.
  3. Move your code. Most Maven projects follow conventions for src, test and resource folders you will want to follow when adding your code.
  4. Add your libraries
  5. If you add your code correctly you can build your project using the command mvn clean install. This will build your project as a jar. r
  6. declare your main class in the pom.
  7. Run the jar with the typical commands. java -jar myJar

This sounds like a lot of work but Maven can help immensely with managing and distributing your projects. Most professional Java developers are expected to know maven.

like image 189
jeremyjjbrown Avatar answered Dec 30 '25 11:12

jeremyjjbrown


If i understand it correctly you want to shift your whole java project in to maven, so if yes can you please post your pom file

and for running as a maven project you should have installed apache maven, then can use "mvn clean install test" command what this command will do , this will clean your target folder first then install all your depencies which you have given in pom file and then runs the test

like image 36
Monis Majeed Avatar answered Dec 30 '25 12:12

Monis Majeed



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!