Recently very hot 12306 of the booking software go-home, I also downloaded a copy down, used a bit, but also from SVN to the code down, but in eclipse unexpectedly, the dependent jar package is not found, later learned that people use MAVEN to manage dependencies, So I went to see MAVEN and found that it was a very powerful and convenient tool to record a simple configuration and use.
The first is to download, give an address on the line, too much needless to say. : http://maven.apache.org/download.html
Next is the configuration, download down must be able to run it.
Maven runs on several environment variables:m2_home,M2 , and java_home, plus M2 and%java_home%\bin are guaranteed in path.
After extracting maven to local, create a new value for the local maven path named M2_home in the environment variable, add an environment variable named M2 with a value of%m2_home%\bin, and add%m2_home%\bin to path, the most basic Java_ HOME needs to be assigned to the local JDK directory.
After setting the environment variables above, enter mvn-version in command line cmd and the correct result will indicate that the configuration is complete.
To run the example at the end, enter it at the command line:
MVN archetype:generate-dgroupid=com.mycompany.app-dartifactid=my-app-darchetypeartifactid= Maven-archetype-quickstart-dinteractivemode=false
When Maven runs for the first time, it automatically downloads frequently used dependencies and some other files to the local repository, which may need to be executed more than once for network reasons to eventually succeed. After the success, MAVEN has already set up our project structure, in the execution command line directory, has created a directory called My-app, the project directory structure is as follows:
my-app|--pom.xml '--src |--main | '--java | '--com | '--MyCompany | '--app | '--App.java '--Test '--Java '--com '--mycompany '--App '--Apptest.java
Java code is stored in the Src/main directory, and the test code is stored in the Src\test directory.
Like ant scripts, Ant needs Build.xml, and maven needs pom.xml. Pom.xml describes dependencies in a project, requires those jars, configures it, and Maven automatically helps you download the required packages from the Web. Detailed description of the Pom.xml file save the next time you're talking.
After the project is created, it should be packaged and compiled, using the MVN Package command. After the build succeeds, the packaged jar package can be executed using the following command.
JAVA-CP Target/my-app-1.0-snapshot.jar com.mycompany.app.App
The result is output: Hello world!
Some of the other commands that Maven uses are:
- Validate verifying the integrity of the project must information
- Test run Unit Testing code
- Verify Verification Package
- Install local jar package to warehouse
- Deploy deployment Project
- Compile compiling a project
- Package Packaging Project
- Clean clears the previous build result
- Site Build Project Document
- Integration-test
There is also a convenient place where you can do many things in one command, such as:
MVN Clean Dependency:copy-dependencies Package
The above command cleans up the output of the project, then copies the dependencies and finally packages the items.
Having learned the basics of MAVEN, there are ways to deal with SVN's go-home code. After installing MAVEN, directly MVN the package will be OK, let maven automatically download the required dependencies, not successful more than a few to try to download all the dependencies will be able to properly compile the successful. For the comrades who want to improve the software, you can post a new version of the update.
Java Development MAVEN Environment configuration and introduction