如何运行 Maven 项目? [英] How to run a maven Project?
本文介绍了如何运行 Maven 项目?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我创建了名为 OneReports 的 Java 项目.如何将整个项目转移到 Maven.一旦我转移到 maven 如何在命令提示符下运行.目前我有依赖性问题.所以我打算把这个项目搬走.任何人都可以帮助我一步一步的过程.
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:\罐子>
推荐答案
- 您需要安装 maven.
- 然后创建一个 maven 原型.原型是一个基础项目,您可以将代码添加到其中.
- 移动您的代码.大多数 Maven 项目遵循 src、test 和资源的约定文件夹 您在添加代码时需要遵循.
- 添加您的库
- 如果您正确添加了代码,您可以使用以下命令构建您的项目
mvn 全新安装
.这会将您的项目构建为 jar. - 在 pom 中声明您的主类.
- 使用典型命令运行 jar.
java -jar myJar
- You'll need to install maven.
- Then create a maven archetype. The archetype is a base project you can add your code into.
- Move your code. Most Maven projects follow conventions for src, test and resource folders you will want to follow when adding your code.
- Add your libraries
- 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 - declare your main class in the pom.
- Run the jar with the typical commands.
java -jar myJar
这听起来像是很多工作,但 Maven 可以极大地帮助管理和分发您的项目.大多数专业 Java 开发人员都应该了解 maven.
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.
这篇关于如何运行 Maven 项目?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文