"Turn" Java Open Source project source code reading method and two times development method

Source: Internet
Author: User

All along, you want to read the source code of some Java open source projects, and even want to modify some code to achieve two development of open source projects. But always do not know where to start, direct source project source code into eclipse, will always report a lot of errors, and can not compile. You can open the source code of the open source project directly through eclipse, at least can achieve the purpose of visual source reading, source navigation, or to some extent to solve the problem of source reading uncomfortable, because directly open and did not change the source file project directory results, for the modified code, You can find the source file project directory from the command line and compile the project with MVN or Ant and see if the modified project is correct.


Because the current Java Open source project is almost all in the form of maven or ant packaging, so the above method to a certain extent solved the problem of reading source, at least through eclipse to achieve the navigation between the source code, but want to compile the source through eclipse, Even debugging can not be done.


So powerful eclipse, how to use it so powerless, the culprit or oneself too ignorant, so powerful maven,eclipse how can not plug-in support, with the Maven plugin, Eclipse Imports Maven projects (that is, the directory structure of most open source projects), which 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 ...


The front said so much nonsense, whether really effective, the following to Axis2 source code for example, do a small experimental example, modify the Services/listservices request processing source, Web services that previously supported only WSDL-style descriptions now also support OWL4WS Web service descriptions.


First step: Install Maven

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


Step two: Install the Maven plugin for Eclipse

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

M2E- http://download.eclipse.org/technology/m2e/releases

As shown in http://www.eclipse.org/m2e/download/, the above plug-in path should be the latest version of M2E, the use of the previous version may appear dependent on other plug-ins, resulting in M2E plug-ins are not installed, The eclipse of SB does not suggest that the m2e depends on which plug-in is not installed, the degree Niang can provide help, but can hardly find a can use.

After installing the M2E plug-in, you can open a MAVEN-formatted project through Eclipse and compile with Eclipse's source project in MAVEN format, or you can create a MAVEN project directly from Eclipse to manage your project using MAVEN. Maven is really powerful, and if you write programs in the Java language, it's necessary to understand Maven's sincerity. When you are finished installing and then creating a project or importing a project, you can choose Maven. After installing the plugin, you will see the following effect:



Step Three: Modify the source code in eclipse

By importing MAVEN projects through Eclipse, you can use Eclipse's visual navigation to read and modify the source code, and execute the relevant MVN commands directly, as shown in the imported program:



Fourth step: Compiling and packaging the source code through the MVN package, getting the release version, testing

With Maven, the compilation and packaging of the source code becomes much easier, and can be done directly through eclipse, by selecting the project right-click Run as or right-clicking on the project's Pom.xml file run as. As shown in the following:



Of course, can also be directly from the command line to package compilation, I choose to use the command line, because I only modified the AXIS2 source of 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 plaincopyprint?

  1. C:\OPENSOURCE\AXIS2-1.6.0-SRC\AXIS2-1.6.0\MODULES\TRANSPORT\HTTP>MVN clean Install

  2. [INFO] BUILD SUCCESS

  3. C:\OPENSOURCE\AXIS2-1.6.0-SRC\AXIS2-1.6.0\MODULES\WEBAPP>MVN Clean Package

  4. [INFO] Building War:c:\opensource\axis2-1.6.0-src\axis2-1.6.0\modules\webapp\target\axis2.war

  5. [INFO] BUILD SUCCESS


MVN Install installs the Axis2-transport-http module into the MAVEN local repository, and the MVN package packages the source program in a specified format. Because many dependent modules are specified in the Pom.xml file of the WebApp module, including modules from other projects or AXIS2 itself, such as the Transport-http module, the modules that they depend on are automatically fetched from the local warehouse and packaged. If there is no corresponding module in the local repository, it will be downloaded automatically online, which is why it takes a long time to compile the open source project for the first time.


Copy the Axis2.war package to Tomcat's WebApp directory, launch Tomcat, 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:



Back to find this article is full of nonsense, but just want to express, MAVEN is always strong gray, for want to read Java Open source project source code, or have on the basis of these source code two times development Impulse child shoes, must not miss Maven's learning, But it feels like this way of changing the source code, and then testing this way is still very inconvenient, command-line compilation, but also copy to Tomcat under test run, which has a better reading source code and two times the way of development, please you must tell me ah.


"Turn" Java Open Source project source code reading method and two times development method

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.