MAVEN Learning notes-Converting a common Java project into a MAVEN project (3)

Source: Internet
Author: User

Converting a common Java project into a MAVEN project is not a very big task, it only takes the following steps to make the conversion successful. Here I use a simple selenium test small demon as an example.

    1. Move all associated libraries in a project
    2. Convert a selenium project into a MAVEN project
    3. Add Maven dependent libraries to the project
    4. Create a Maven Test folder schema
STEP1: Move all associated libraries in a project

Select the project you want to convert:build path > Configure build Path

STEP2: Converting a selenium project into a MAVEN project

1) Right-click the project you want to convert,Configure > Convert Maven Project

2) required to fill in the group ID and artifact ID, this does not need to change, with the default project provided by the

3) After successful conversion, the project's structure in Eclipse becomes the following

no pre-conversion structure Post-conversion structure

STEP3: Adding Maven dependent libraries to the project

Now we need to add the dependencies needed in the project to the local central source, and for this project, we know we are missing the Selenium jar package, the JUnit jar package, and so on.

1) go to http://www.mvnrepository.com/above to find selenium

2) Click Selenium Java

3) Select the version of selenium you want to use

4) information about selenium in Maven will be displayed, and then add this information to Pom.xml

5) Add selenium dependency information to pom.xml, can be added in the process of dependencies, save, this time will download the relevant dependency package to the local source center. (Need a little time, have any questions, can refer to before Maven (1) mentioned, solve the problem)

6) Copy the information in the Pom.xml directly into the XML file and save it .

7) All errors will be resolved after waiting for the dependent package to be downloaded

Step4 creating a Maven Test folder schema

The next step is to test the truth, and see if the converted selenium project can run, choose pom.xml > Run as > Maven test Results-----------The test case is not executed, why is it? Take a closer look at log and find that Maven defaults to the source code found under the \src\main\resource path, and the test source is in \src\test\resources.

The output is:

[INFO] Scanning forprojects ...                                                                         [INFO] [INFO]------------------------------------------------------------------------[INFO] Building MavenConvertDemon10.0.1-Snapshot[info]------------------------------------------------------------------------[INFO] [INFO]---maven-resources-plugin:2.6: Resources (default-resources) @ MavenConvertDemon1---[WARNING] Using platform encoding (Cp1252 actually) to copy filtered resources, i.e. build is platform dependent![INFO] Skip non existing resourcedirectory d:\junit\mavenconvertdemon1\src\main\resources[info] [info]---maven-compiler-plugin:3.1: Compile (default-compile) @ MavenConvertDemon1---[INFO] nothing to compile-All classes is up to date[info] [INFO]---maven-resources-plugin:2.6: Testresources (default-testresources) @ MavenConvertDemon1---[WARNING] Using platform encoding (Cp1252 actually) to copy filtered resources, i.e. build is platform dependent![INFO] Skip non existing resourcedirectory d:\junit\mavenconvertdemon1\src\test\resources[info] [info]---maven-compiler-plugin:3.1: Testcompile (default-testcompile) @ MavenConvertDemon1---[INFO] No sources to compile[info] [info]---maven-surefire-plugin:2.12.4: Test (default-test) @ MavenConvertDemon1---[INFO]------------------------------------------------------------------------[INFO] BUILD Success[info]------------------------------------------------------------------------[INFO] Total Time:2.999S[info] finished at: -- Geneva-06t16: A: the+ ,:xx[INFO] Final memory:6m/15m[info]------------------------------------------------------------------------
So the goal now is how to customize the MAVEN directory structure?

The following code is the source code is set to the SRC directory, the source of the test is placed under the Src/test, so modified to solve the problem just now, the test ran up. Such a selenium project is converted into a MAVEN project.

< Build >    < sourcedirectory >src/</sourcedirectory>     <  Testsourcedirectory>src/test</testsourcedirectory> </ Build >

Results after successful output:

[INFO] Scanning forprojects ...                                                                         [INFO] [INFO]------------------------------------------------------------------------[INFO] Building MavenConvertDemon10.0.1-Snapshot[info]------------------------------------------------------------------------[INFO] [INFO]---maven-resources-plugin:2.6: Resources (default-resources) @ MavenConvertDemon1---[WARNING] Using platform encoding (Cp1252 actually) to copy filtered resources, i.e. build is platform dependent![INFO] Skip non existing resourcedirectory d:\junit\mavenconvertdemon1\src\main\resources[info] [info]---maven-compiler-plugin:3.1: Compile (default-compile) @ MavenConvertDemon1---[INFO] nothing to compile-All classes is up to date[info] [INFO]---maven-resources-plugin:2.6: Testresources (default-testresources) @ MavenConvertDemon1---[WARNING] Using platform encoding (Cp1252 actually) to copy filtered resources, i.e. build is platform dependent![INFO] Skip non existing resourcedirectory d:\junit\mavenconvertdemon1\src\test\resources[info] [info]---maven-compiler-plugin:3.1: Testcompile (default-testcompile) @ MavenConvertDemon1---[INFO] Changes detected-Recompiling theModule![WARNING] File encoding has notbeen set, using platform encoding Cp1252, i.e. build is platform dependent![INFO] Compiling1source file to D:\Junit\MavenConvertDemon1\target\test-Classes[info] [INFO]---maven-surefire-plugin:2.12.4: Test (default-test) @ MavenConvertDemon1---[INFO] Surefire report Directory:d:\junit\mavenconvertdemon1\target\surefire-reports-------------------------------------------------------T E s T s-------------------------------------------------------Running test. Testseleniumdemon1feb6, - 4: +: -PM Org.openqa.selenium.os.unixprocess$seleniumwatchdog Destroyharderinfo:command failed to close cleanly. Destroying forcefully (v2). [Email protected] Tests Run:1, Failures:0, Errors:0, skipped:0, Time elapsed:31.452secresults:tests Run:1, Failures:0, Errors:0, skipped:0[INFO]------------------------------------------------------------------------[INFO] BUILD Success[info]------------------------------------------------------------------------[INFO] Total Time:38.029S[info] finished at: -- Geneva-06t16: +: $+ ,:xx[INFO] Final memory:11m/26m[info]------------------------------------------------------------------------

PS; with a MAVEN standard directory structure:

————————————————————————————————

Whooooshhhhhhhhhhhh .......

Blimey what is that?

That is your life mate

Oh, I wasn't quite ready. Can I have another go?

Sorry mate, only one per person.

MAVEN Learning notes-Converting a common Java project into a MAVEN project (3)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.