How to run a maven Project?

让人想犯罪 __ 提交于 2021-02-05 08:29:07

问题


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>


回答1:


  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.




回答2:


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



来源:https://stackoverflow.com/questions/22085993/how-to-run-a-maven-project

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!