Use the Eclipse plug-in to edit, compile, and debug your application

Source: Internet
Author: User
Tags version control system

What Eclipse is.
Eclipse is an open source, java-based, extensible development platform. For its part, it is just a framework and a set of services for building the development environment through plug-in components. Fortunately, Eclipse comes with a standard set of plug-ins, including Java development tools (Java Development tools,jdt).

While most users are happy to use eclipse as the Java IDE, Eclipse's goal is not limited to this. Eclipse also includes the plug-in development environment (Plug-in Development Environment,pde), which focuses on software developers who want to extend eclipse because it allows them to build tools that seamlessly integrate with the eclipse environment. Because everything in Eclipse is a plug-in, all tool developers have an equal place to play for providing plug-ins to eclipse, as well as providing a consistent and unified integrated development environment for users.

This equality and consistency is not limited to Java development tools. Although Eclipse is developed in the Java language, its purpose is not limited to the Java language; For example, plug-ins that support programming languages such as C/S, COBOL, and Eiffel are already available or are expected to be rolled out. The Eclipse framework can also be used as a basis for other application types unrelated to software development, such as content management systems.

An outstanding example of an ECLIPSE based application is IBM's WebSphere Studio Workbench, which forms the basis of the IBM Java Development tools family. For example, WebSphere Studio application Developer adds support for JSP, servlet, EJB, XML, Web services, and database access.

Eclipse is open source software
Open source software is a software that comes with a license designed to ensure that certain rights are granted to the user. Of course, the most obvious right is that the source code must be available so that users can freely modify and redistribute the software. This protection of user rights is done through a policy called copyleft: the Software License advocates copyright protection, and the user is not allowed to distribute the software unless expressly granted such rights. Copyleft also requires the same license to cover any redistributed software. This actually inverts the purpose of copyright-using copyright to grant user rights, rather than retaining copyright--copyleft for software developers, which is often described as "preserving all copyrights".

The many fears of open source software that have spread around concerns and concerns are related to the so-called "viral" nature of certain copyleft licenses-if you use open source software as part of the program you develop, you will lose your intellectual property because the license will "infect" the proprietary part of your development. In other words, the license may require all software packaged with open source software to be published under the same license. While this may be true for the most famous copyleft license (the GNU general Public License, such as Linux, which is issued under the license), there are other licenses that provide a better balance between commercialization and community considerations.

Open Software Initiative is a non-profit organization that clearly defines the meaning of open source code and the authentication license that meets its standards. Eclipse is licensed under OSI's approved general Public License (CPL) version 1.0, Cpl "is designed to facilitate the commercialization of the program ..." (for a link to the full text of the general Public License version 1.0, see Resources later in this article).

Developers who create plug-ins for Eclipse or use eclipse as the basis for software development applications need to publish any Eclipse code they have used or modified under CPL, but they are free to decide how to grant the code they have added. Proprietary code packaged with software from Eclipse does not need to be licensed as an open source, and the source code does not need to be supplied to the user.

Although most developers do not use eclipse to develop plug-ins or create new products based on Eclipse, the open source nature of Eclipse does not mean that it makes eclipse available for free (although a commercially convenient license means that Plug-ins may cost money). Open source encourages innovation and motivates developers (and even business developers) to contribute code to the public open source repository. There are many reasons for this, but perhaps the most fundamental reason is that the more developers who contribute to the project, the more valuable the project will become to everyone. As the project becomes more useful, more developers will use it and build a community around it, just like the communities that surround Apache and Linux.

What organization Eclipse is.
The Eclipse.org Association manages and directs Eclipse in ongoing development. After it was said that IBM spent 40 million of dollars on developing Eclipse and released it as an open source project, the Eclipse.org Society absorbs a number of software tool providers, including Borland, Merant, Rational, RedHat, SuSE, TogetherSoft and QNX. Since then, other companies have joined, including Hewlett Packard, Fujitsu, and Sybase. Each of these companies sent a representative to the Council, which was responsible for determining the direction and scope of the Eclipse project.

At the highest level, the Project Management Committee (Management COMMITTEE,PMC) manages the Eclipse project. This project is divided into subprojects, with one owner in each subproject. Large subprojects are divided into groups, and each group has a person in charge. Most of these management roles are currently owned by the IBM affiliate Object Technology International (OTI), which originally developed Eclipse, but as an open source project, it welcomes anyone's involvement. The responsibilities of any particular department are sought through the contribution of the Department to the project.

Now that we've examined some of the theories, histories, and management behind Eclipse, let's examine the product itself.

Eclipse Workbench
The first time you open Eclipse, you see the following Welcome screen:

Figure 1. Eclipse Workbench

The Eclipse Workbench consists of several panes called views (view), such as the Navigator view in the upper-left corner. The collection of panes is called a Perspective (perspective). The default perspective is the Resource perspective, which is a basic set of common views for managing projects and viewing and editing files in projects.

The Navigator view allows you to create, select, and delete items. The pane on the right side of the Navigator is the editor area . Depending on the type of document selected in Navigator, an appropriate editor window will open here. If eclipse does not register the appropriate editor for a particular document type (for example, a. doc file on a Windows system), Eclipse will try to open the document using an external editor.

Navigator the following Outline view Displays the outline of the document in the editor, the accuracy of which depends on the type of editor and document, and for Java source files, the outline displays all declared classes, properties, and methods.

The Tasks View collects information about the project you are working on, which can be information generated by Eclipse, such as compilation errors, or tasks that you add manually.

Most of the other features of the workbench, such as menus and toolbars, should be similar to those of other familiar applications. A handy feature is the shortcut toolbar for different perspectives, which is displayed in the left of the screen, which differs significantly from context to history. Eclipse also comes with a robust help system that includes a user's Guide to the Eclipse Workbench and included Plug-ins, such as Java development tools. It is worthwhile to browse through the Help system at least once, so that you can see what options are available and better understand the work flow of Eclipse.

To continue this brief Eclipse trip, we will create a project in Navigator. Right-click the Navigator view and select new=>project. When the New Project dialog box appears, select Java on the left. Standard Eclipse has only one type of Java project, named "Java Project." If plug-ins are installed to provide JSP and servlet support, we will see an additional option for WEB applications from here. For now, select Java Project, enter "Hello" when you are prompted for the project name, and then press Finish.

Next, we'll examine the Java perspective. Depending on how you prefer your screen management, you can change the perspective in the current window by selecting window=>open Perspective=>java , or by selecting window=>new window , and then select the new perspective to open a new window.

As you might expect, the Java perspective contains a set of views that are more appropriate for Java development. One is the upper-left view, which is a hierarchy of various Java packages, classes, jars, and other files. This view is called Package Explorer. Also note that the main menu is already expanded-and there are two new items: Source and refactor.

Java Development Environment (JDE)
To test the Java development environment, we will create and run a "Hello, World" application. Using the Java perspective, right-click the "Hello" item and select New=>class, as shown in Figure 2. In the dialog box that appears, type "Hello" as the class name. In the "Which method stubs would" and "create?" Next, select the public static void main (string[] args) check box, and then press Finish.

Figure 2. Creating a new class in a Java perspective

This creates a. java file in the editor area that contains the Hello class and the empty main () method, as shown in Figure 3. Then add the following code to the method (note that the declaration of which I was intentionally omitted):

Figure 3. The Hello class in the Java editor

You will notice some of the features of the Eclipse editor as you type, including syntax checking and automatic code completion. In version 2.1 (I downloaded the M2 version to try out), when you type open brackets or double quotes, Eclipse automatically provides paired symbols and places the cursor inside a symbol pair.

In other cases, you can invoke the code completion function by pressing Ctrl-space. Code completion provides a context-sensitive list of suggestions that you can select from the list by keyboard or mouse. These recommendations can be either a list of methods for a particular object or a snippet of code that is expanded based on different keywords, such as for or while.

The syntax check relies on incremental compilation. Whenever you save your code, it accepts compilation and syntax checking in the background. By default, syntax errors are underlined with a red underline, and a red dot with a white "X" appears on the left edge. Other errors are indicated by a lightbulb icon on the left side of the editor, which is the problem that the editor may be able to fix for you-the so-called quick fix feature.

The code example above has a lightbulb icon behind the for statement, because the declaration of I is omitted. Double-clicking the icon will bring up the suggested fix list. In this example, it provides suggestions for creating a class field I, a local variable I, or a method parameter I; clicking each of these suggestions displays the code that will be generated. Figure 4 shows the list of recommendations and the code that is generated after a local variable is created.

Figure 4. Quick Fix recommend

Double-clicking the suggestion inserts the suggested code in the appropriate location in your code.

Once the code compiles without errors, you can choose Run from the Eclipse menu to execute the program (note that there is no separate compilation step here, because the compilation is done when you save the code.) If the code has no syntax errors, it can run. A Launch Configurations dialog box appears with the appropriate default settings, and press the Run button in the upper-right corner. A new tabbed pane appears in the following pane (console), showing the output of the program, as shown in Figure 5.

Figure 5. Output of the program

You can also run programs in the Java debugger. First double-click the gray edge of the left side of the editor view to set a breakpoint in main () System.out.println () after the call to System.out.println (). A blue dot will appear there. Then choose Debug from the Run menu. As described above, a Launch Configurations dialog box appears. Please select Run. The perspective will automatically switch to the Debug perspective, which has a number of interesting new views, as shown in Figure 6:

Figure 6. Debug Pivot Chart

First, notice the Debug view in the upper-left corner of the perspective. This view displays the call stack, and there is a toolbar in the title bar that allows you to control the execution of the program, including continuing, suspending or terminating it, tracking the next statement, stepping through the next statement, or returning from the method.

The upper-right pane contains a number of tabbed views, including Variables, breakpoints, Expressions, and Display. Here I clicked the Variables view so that we could see the current value of I.

You can get more information about these views with context-sensitive Help: Click the title of the view, and then press F1.

Additional plugins
In addition to plug-ins such as JDT for editing, compiling, and debugging applications, there are a number of plug-ins available that support the complete development process from modeling, build automation, unit testing, performance testing, versioning to configuration management.

The Eclipse standard comes with plug-ins that work with CVS, which is an open source concurrent version system for source control (Concurrent versions system). The team plug-in connects to the CVS server, allowing members of the development teams to manipulate a set of source code files without overwriting other people's changes. There is no further discussion of how to source control from within Eclipse, as this requires the installation of a CVS server, but it is an important and essential feature of Eclipse to support the development team rather than just stand-alone development.

Some of the Third-party plug-ins that are available or have been announced to be launched include:

version control and configuration management CVS merant PVCS Rational ClearCase

UML Modeling Omondo eclipseuml Rational XDE (instead of Rose) together WebSphere Studio Edition

graphic Batik SVG Macromedia Flash

Web Development, HTML, XML Macromedia Dreamweaver Xmlbuddy

Application Server Integration Sysdeo Tomcat Launcher

For a more complete list of available plug-ins, see the links in resources.

Example: A plug-in for UML modeling
To see examples of plug-ins and see how it is integrated with Eclipse, download the popular Omondo eclipseuml (see Resources for links); You need to register, but the plugin is free. This plug-in relies on GEF, the graphical Editor Framework, which is another Eclipse plug-in. GEF is part of the Tools sub project. To download GEF, go to the Eclipse Web site (see Resources), select "Downloads", and then click the "Tools PMC Downloads page" link. Note that you will need to download the GEF version recommended by Omondo (GEF 2.0 for Omondo 1.0.2).

After downloading, the installation of the plug-in is usually done by decompressing the download file and copying its contents to the Eclipse plug-in directory. In this case, GEF needs to extract the Eclipse directory (it will automatically enter the plug-in directory from that directory). For security reasons, you might want to unzip it to a temporary directory, and then copy the related directory from there accordingly. If Eclipse is running, you need to stop it and then restart it so that it recognizes the newly installed plug-in.

Once the ECLIPSEUML (and GEF) installation is complete, you can create a class diagram just as you would create a Java class file. In the Java perspective, right-click the "Hello" item in Package Explorer and choose new=>otherfrom the pop-up menu. There will be a new option for UML in the left pane of the New dialog box. The free version of ECLIPSEUML only supports class diagrams, so the only option on the right is UML class Diagram. Please select UML class Diagram and type a name for the class diagram, such as "Hello":

Figure 7. Class Diagram Editor

A graphical editor appears in the editor area with a canvas for drawing class diagrams. You can create class diagrams in two ways: reverse-engineer existing code by dragging Java files from Package Explorer onto class diagrams, or by using the drawing tools available on the toolbar above the blank class diagram. To experiment with the first method, create a new class named person (using file=>new=>class) and give it the two private properties listed below:

/** Person.java
 * @author David
 *
/public class Person {
private String name;
private address address;

/**
 * Returns the address.
 * @return Address
/getaddress () {return address
         ;
}

/**
 * Returns the name.
 * @return String
 *
/public string getName () {return
        name;
}

/**
 * Sets the address.
 * @param address "to set
 *
/public void setaddress (address) {
        this.address = Address;
     }

/**
 * Sets the name.
 * @param name the name to set
 *
/public void SetName (String name) {
       this.name = name;
}

}

(Admittedly, I just typed the line for name and address.) Getter and setter methods are generated automatically through Eclipse, that is, right-click the source code and select the source=>generate Getter and setterfrom the pop-up menu. )

Please save and close Person.java HELLO.UCD.

Figure 8. Person class Diagram

To create a Java class from UML, click the New Class button on the toolbar at the top of the class Diagram window, the third button on the left, and then click the class Diagram. When the New Class Wizard opens, type adress as the class name, and then click Finish.

You can add properties to a class by right-clicking the class name and selecting new=>attribute. In the New Properties dialog box, enter the property name, type, and visibility. Then right-click the class name and select New=>method to add the method.

When you change a class diagram, the Source Editor window below the figure reflects the changes you made. Finally, you can draw a diagram of the two classes by clicking the association button (fifth from the left) and drawing a line segment from the person class to the address class. This will bring up another dialog box where you can enter the associated attributes (refer to ECLIPSEUML Help for more on the required information). The completed diagram should resemble the following:

Figure 9. Correlation

This UML plug-in demonstrates several typical features of the Eclipse plug-in. First, it shows the tight integration between tools. There is absolutely no way to see how many components are working; integration with the Eclipse platform and JDT is seamless. For example, when the person class is created, it displays a syntax error because one of its property address is not defined. Once the address class is created in a UML diagram, the components are displayed separately.

Another feature is the ability of ECLIPSEUML to leverage the functionality provided by other Plug-ins--in this case, the GEF plug-in, which provides tools for developing visual editors.

Another feature relates to the way eclipseuml Plug-ins use multi-level functionality for distribution. The basic plug-ins that support the class diagram are free, but more mature versions are paid to be used.

Eclipse Platform Architecture
The Eclipse platform is a framework for a powerful set of services that support plug-ins such as the JDT and plug-in development environments (PDE). It consists of several major components: platform runtime, Workspace, Workbench, Team support, and help.

Figure 10. Eclipse Platform Architecture

Platform
The platform runtime is the kernel that checks which plug-ins are installed at startup and creates registry information about them. To reduce startup time and resource usage, it loads the plug-in when it actually requires any plug-ins. In addition to the kernel, everything else is implemented as a plugin.

Work Area
A workspace is a plug-in that is responsible for managing user resources. This includes user-created projects, files in those projects, and file changes and other resources. The workspace is also responsible for notifying other plug-ins of information about resource changes, such as file creation, deletion, or change.

worktable
The workbench provides the user interface for Eclipse. It is built using standard window Toolkit (SWT) and a more advanced API (JFace); SWT is a non-standard substitute for the Java swing/awt GUI API, and JFace is based on SWT and provides user interface components.

SWT has proved to be the most controversial part of Eclipse. SWT maps more closely to the native graphics features of the underlying operating system than Swing or SWT, which not only makes SWT faster, but also makes Java programs look and feel more like native applications. Using this new GUI API may limit the portability of the Eclipse Workbench, but the SWT porting version for most popular operating systems is already available.

Eclipse's use of SWT only affects the portability of eclipse itself--any Java applications built with eclipse will not be affected unless they use SWT instead of using SWING/AWT.

Team Support
The team support component is responsible for providing version control and configuration management support. It adds views as needed to allow the user to interact with any version control system (if any) that is used. Most plug-ins do not need to interact with the team support components unless they provide version control services.

Help
The Help component has the scalability capabilities that are equivalent to the Eclipse platform itself. As with Plug-ins adding functionality to Eclipse, it helps provide an additional navigation structure that allows tools to add documents as HTML files.
Author Blog: http://blog.csdn.net/njchenyi/ related articles

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.