MAVEN Eclipse Debug Java Open Source project

Source: Internet
Author: User
Tags java open source projects

All along, you want to read the source code of some Java open source projects, and even want to modify some of the code to achieve the open source project for two times the purpose of development. But always do not know where to start, directly to the source project source code into eclipse, will always report many errors, and can not compile. can open the source code of open source project directly through eclipse, can at least reach the goal of Visual source reading, source navigation, or can solve the problem that the source text is not happy to some extent, because the direct opening does not change the directory result of the source file item, for the modified code, You can find the source file project directory from the command line and compile the project using MVN or ant to see if the modified item is correct.


Since the current Java open source projects are almost always packaged with Maven or ant, the above method solves the problem of reading source to some extent, at least through eclipse, it can achieve the navigation between the source code, but you want to compile the source through eclipse. Even debugging can not be done.


Such a powerful eclipse, how to use it so powerless, the culprit or oneself too ignorant, so powerful maven,eclipse how will not have plug-ins to support it, with the Maven Plug-ins, Eclipse Imports the MAVEN project (that is, the directory structure of most open source projects) that can be edited directly on Eclipse, even through eclipse to compile and debug the source project.


Now that you know how to read the source code for an Open-source project, the next step is to install the Maven plugin for Eclipse, then source code, two development ...


Before said so much nonsense, whether really effective, the following take Axis2 source code for example, do a small experiment example, modify services/listservices request processing source, This enables Web services that were previously only supported by the WSDL method to support OWL4WS Web service descriptions.


First step: Install Maven

Installing maven is simple, download the latest version of Maven from Http://maven.apache.org/download.html, then unzip, configure Maven_home and maven_opts, and the PATH environment variable. Maven_home point to Maven's directory, maven_opts configure Maven execution parameters, because the MAVEN default setting of less memory, the compilation of large projects may appear outofmemory situation, such as I did not set Maven_ OPTS and compile Axis2 source when the outofmemory situation, the last configuration path, point to%maven_opts%\bin can. Makes it possible to use the MAVEN command directly in the command-line interface. More about MAVEN introduction, recommend a book to everyone: "Maven combat", also called "Maven in Action", is written by a Chinese, easy to understand.


Step Two: Install the Eclipse maven plugin

Help->install New Software->add, add the following:

M2e-http://download.eclipse.org/technology/m2e/releases as the http://www.eclipse.org/m2e/download/shows, The path to the above plug-ins should be the latest version of M2E, use the previous version may appear dependent on other plug-ins, resulting in M2E plug-in installation, SB's eclipse also did not hint m2e depends on which Plug-ins caused its installation, the Niang is able to provide help, But it's almost impossible to find one that can be used.

After installing the M2E plug-in, you can open the MAVEN-formatted project through Eclipse and be able to compile the MAVEN-formatted source project with Eclipse, and, of course, create a MAVEN project directly through Eclipse to manage your project using Maven's approach. Maven is really powerful, and if you're using the Java language to write a program, it's really necessary to understand Maven. When you create a project or import a project after installation, you can select Maven. After installing the plugin you will see the following effect:



Step Three: Modify the source code in eclipse

Importing the MAVEN project through eclipse enables you to read and modify the source code using the visual navigation capabilities of Eclipse, as well as directly execute the relevant MVN commands, as shown in the following image:



Fourth step: Compile and package the source code through MVN package, get the release version, test

With Maven, source code compilation and packaging becomes much easier, and can be done directly through Eclipse, select the project right key to run as or right-click the project's Pom.xml file run as. As shown in the following illustration:



Of course, can also be directly through the command line packaging and compiling, I chose to use the command line, because I only modified the AXIS2 source of the two modules, the two modules are axis2-transport-http and Axis2-webapp respectively. The command line editing commands for these two modules are as follows:

[plain] view plain copy print? C:\OPENSOURCE\AXIS2-1.6.0-SRC\AXIS2-1.6.0\MODULES\TRANSPORT\HTTP>MVN clean install [INFO] Build SUCCESS C:\OpenS OURCE\AXIS2-1.6.0-SRC\AXIS2-1.6.0\MODULES\WEBAPP>MVN clean Package [INFO] Building war:c:\opensource\ Axis2-1.6.0-src\axis2-1.6.0\modules\webapp\target\axis2.war [INFO] Build SUCCESS

The MVN install is to install the Axis2-transport-http module into the MAVEN local repository, and MVN package to package the source program in the specified format. Because many of the dependent modules are specified in the Pom.xml file of the WebApp module, including other projects or Axis2 's own modules, such as the Transport-http module, packaging automatically acquires its dependent modules from the local warehouse and packs them. If there is no corresponding module in the local warehouse, it will be downloaded automatically on the Internet, which is why it will take a long time to compile the open source project for the first time.


Copy the Axis2.war package to Tomcat's WebApp directory, start Tomcat, and enter http://localhost:8080/axis2/services/listServices in the browser. You can see that the modified page has been supported for OWL4WS. As shown in the following illustration:



Look back and find this article is full of nonsense, but just want to express, Maven is really gray is very strong, for want to read Java Open-source Project source code, or have in these source code based on two times development impulse of children's shoes, must not miss Maven learning, But feel this way in the modification of the source code, and then test this way is very inconvenient, command line compilation, but also copy to Tomcat under the test run, which has a better reading source code and two times to develop the way, please you must tell me ah.

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.