How to get Eclipse The website http://www.eclipse.org is where you can download Eclipse. You can go to the Download section and choose the binary for your platform (Windows, Linux, Solaris, Mac OS, etc). Eclipse is free! The Eclipse Workbench Creating a Java project 1. Right-click in the Navigator view to bring up a context menu and select New→Project. [EA] 2. In the New Project dialog box, Eclipse presents the project options: Java, Plug-in Development, and Simple. Because you want to create a Java program, select Java on the left side of the dialog box. [EA] 3. Select Java Project. If you’ve installed other types of Java development plug-ins, various other types of Java projects may potentially be listed here (EJBs and servlets, for example). But the JDT that comes standard with Eclipse only offers support for standard Java applications, so you must choose the Java Project option.[EA] 4. Click Next to start the New Java Project Wizard. [EA] 5. The first dialog box prompts you for a project name. This is a simple “Hello, world” example, so enter Hello. Clicking Next would take you to a dialog box that lets you change a number of Java build settings, but for this example you don’t need to change anything. [EA] 6. Click Finish. [EA] 7. Eclipse notifies you that this kind of project is associated with the Java perspective and asks whether you want to switch to the Java perspective. Check the Don’t Show Me This Message Again box and click Yes. [EA] Creating a Java Class Now that we have our project, it is time to create our first Java program. We don't have to put our classes in packages, but it is a good practice to structure and organize our classes in packages. It is a good style to start the name of the package with lower letters. There should be no empty spaces left in package name. A good guideline for your package names is the naming schema from Sun (Take a look at Java API). Finally, add a name for this particular project: hello. Following are the steps to create a sample Java program: 1. Right-click on the package and select New→Class. 2. The first field, Source Folder, is by default the project’s folder—leave this as it is. [EA] 3. In the class name field, enter HelloWorld. [EA] 4. In the section Which Method Stubs Would You Like to Create?, check the box for public static void main(String[] args). [EA] 5. Click Finish, and the New Java Class Wizard will create the appropriate directory structure for the package and the source file HelloWorld.java under this package name. [EA] Running the Java program You’re now ready to run this program. There are several things you might want to consider when running a Java program, including the Java runtime it should use, whether it will take any command-line parameters, and, if more than one class has a main() method, which one to use. The standard way to start a Java program in Eclipse is to select Run→Run from the Eclipse menu. Doing so brings up a dialog box that lets you configure the launch options for the program; before running a program, you need to create a launch configuration or select an existing launch configuration. [EA] For most simple programs, you don’t need a special launch configuration, so you can use a much easier method to start the program: First make sure the HelloWorld source is selected in the editor (its tab is highlighted in blue) and then do the following from the Eclipse menu: 1. Select Run→Run As→Java Application. 2. Because you’ve made changes to the program, Eclipse prompts you to save your changes before it runs the program. Click OK. 3. The Task view changes to a Console view and displays your program output [EA] You may wonder why no separate step is required to compile the .java file into a .class file. This is the case because the Eclipse JDT includes a special incremental compiler and evaluates your source code as you type it. Thus it can highlight things such as syntax errors and unresolved references as you type. (Like Eclipse’s other friendly features, this functionality can be turned off if you find it annoying.) If compilation is successful, the compiled .class file is saved at the same time your source file is saved. [EA] Getting Help in Eclipse Eclipse comes with a well designed and developed Help system. You can access the Help system in several ways. For example you can get help right from your source code by selecting a key word and pressing F1. The Help menu offers a number of choices. You can browse the content or you can search by keywords. If the Help system that comes with Eclipse is not enough to answer your questions there is another choice – ask Google :) What is CVS? CVS is a version control system. Using it, you can record the history of your source files. For example, bugs sometimes creep in when software is modified, and you might not detect the bug until a long time after you make the modification. With CVS, you can easily retrieve old versions to see exactly which change caused the bug. This can sometimes be a big help. [CVSNT] You could of course save every version of every file you have ever created. This would however waste an enormous amount of disk space. CVS stores all the versions of a file in a single file in a clever way that only stores the differences between versions. [CVSNT] CVS also helps you if you are part of a group of people working on the same project. It is all too easy to overwrite each others' changes unless you are extremely careful. Some editors, like gnu Emacs, try to make sure that the same file is never modified by two people at the same time. Unfortunately, if someone is using another editor, that safeguard will not work. CVS solves this problem by insulating the different developers from each other. Every developer works in his own directory, and CVS merges the work when each developer is done. [CVSNT] CVS can be deployed several ways. The simplest approach, called local access, is to put the repository on a disk that is shared by everybody on the team. The CVS client (which can be either a command-line or a GUI application) uses lock files to synchronize access to the files. No special server is required. This approach isn’t recommended, because nothing prevents users from damaging the repository—especially if they inadvertently read or write to the repository directly without using the CVS client. A much better way is to use a CVS server that prevents direct access to the repository. Officially, Eclipse only supports CVS version 1.11.1p1 or higher on UNIX and Linux. However, a port of CVS, CVSNT, is available for Windows NT/2000/XP; even though it isn’t officially supported, CVSNT version 1.11.1.1 and greater generally work well with Eclipse. If you must use Windows, another option is to install Cygwin, a UNIX emulator that runs on Windows platforms. If you will be using CVS for serious development, you should have a machine dedicated as a CVS server, and you should consider using UNIX or Linux on this machine. One major advantage of using CVS on UNIX or Linux is that you have a better choice of authentication methods—SSH in particular is recommended. [CVSNT] The Repository The CVS repository stores a complete copy of all the files and directories which are under version control. Normally, you never access any of the files in the repository directly. Instead, you use CVS commands to get your own copy of the files into a working directory, and then work on that copy. When you've finished a set of changes, you check (or commit) them back into the repository. The repository then contains the changes which you have made, as well as recording exactly what you changed, when you changed it, and other such information. Note that the repository is not a subdirectory of the working directory, or vice versa; they should be in separate locations. CVS can access a repository by a variety of means. It might be on the local computer, or it might be on a computer across the room or across the world. To distinguish various ways to access a repository, the repository name can start with an access method. For example, the access method :local: means to access a repository directory, so the repository :local:/usr/local/cvsroot means that the repository is in /usr/local/cvsroot on the computer running CVS. [CVSNT] Sharing a project with CVS Several steps are necessary to add a project to a CVS repository using Eclipse. The first step is to enter the information that Eclipse needs to connect to the CVS repository. This information is stored as an object called a repository location. After you create a repository location, you create a new module in CVS corresponding to your project and, finally, add your projects files to that module. [EA] Creating a repository location To create a repository location, you need to know the name of your CVS server, the path of the CVS repository on it, and the protocol it is using. You also must have a valid username and password for the server or the CVS repository. Follow these steps: 1. From the main menu, select Window→Open Perspective→Other. 2. A complete list of available perspectives appears. Select CVS Repository Exploring and click OK. (Eclipse will remember this selection, and this perspective will appear directly in the Open Perspective menu in the future.) 3. In the CVS Repositories view, right-click and select New→Repository Location. 4. Enter the name of the CVS server, the repository path, the username, and the password. Note that the repository path is the full path to where the CVS repository is located (for example, /usr/local/repository). 5. Choose the protocol. If you are using pserver, you obviously need to choose pserver. If you are using SSH, you need to choose extssh, which is Eclipse’s built-in support for SSH1. (The third choice, ext, lets you use an external program for remote access. You might need to use this option if your SSH server supports only SSH2 and doesn’t provide backward compatibility for SSH1, or if you are using an entirely different protocol. To set the external program to use, select Window→Preferences→Team→CVS→ Ext Connection Method.) 6. Unless you’ve changed the CVS port for some reason, leave Use Default Port checked. Also leave Validate Connection on Finish checked. 7. Click Finish. The information you entered is saved, and Eclipse connects to verify the information. Eclipse will notify you only if it is unable to connect to the server; otherwise, if everything goes OK, you’ll see this repository location as a new entry in the CVS Repositories view. [EA] Sharing the project Once you’ve entered the parameters you need to connect to your repository, you can add your project to the CVS repository by following these steps: 1. Change to the Java perspective, right-click on the project, and select Team→Share Project. 2. In the Share Project with CVS Repository dialog box that appears, make sure Use Existing Repository Location is checked and the repository location you entered earlier for cvsserver is selected. 3. By default, the CVS module name is the same as the Eclipse project name. If this is OK, click Finish. [EA] If your project name has spaces, you may want to consider using something different for the repository name, especially if other users will be using CVS from the command line; otherwise they’ll have to remember to enclose the repository name in quotes in commands. To use a different name, click Next instead of clicking Finish in the first Share Project dialog box. In the following dialog, check Use Specified Module Name, enter the new name, and click Finish. This step creates a module on the CVS server but doesn’t add any files to it. Notice that Eclipse opens a CVS Synchronize view below the editor pane. This view normally lets you compare your local version of files with those in the repository; but it isn’t a very interesting view when you first check in a project, because none of the files are in the repository. [EA] Adding and committing files It takes two steps to check a new file in to CVS: 1. Add the file to CVS. 2. Commit the file. Adding the file doesn’t actually cause the file to appear in CVS; it just sends a notification to CVS, which schedules the file for addition. The second step, committing the file, causes the file to appear in the CVS repository and be made available to other users. [EA] Checking a project out of CVS Let’s change our point of view for a moment and see how a co-worker would obtain the project you’ve just made available in CVS. (Although sharing source code with team members is the most typical use of CVS, you might also do this if you want to be able to work on the code on different machines or operating systems.) [EA] As before, the first step is to create a repository location; to do this, your co-worker switches to the Repository perspective and then follows these steps: 1. Right-click in the CVS Repository view. 2. Select New→Repository Location from the context menu. 3. Enter the host name, repository path, username, password, and connection type and click Finish. The new repository location appears in the Repository view. Expanding the Repository location displays several entries: HEAD, Branches, and Versions. You are interested in HEAD—the main branch of development. [EA] You can use CVS to maintain different branches of a project. Doing so is often necessary if you release a version of your project to the public, such as version 1.0. As you begin to work on adding new features for version 2.0, the code is not stable enough for release; so, if any serious bugs are discovered in version 1.0, they must be made to the original 1.0 code. CVS allows you to create a separate branch, starting with the original 1.0 code, so you can maintain this code separately from the new development continuing with the main branch, HEAD. [EA] Versions differ from branches. A version is a snapshot of a branch at a given point in time —in other words, it’s a particular set of file revisions. You need to mark versions that relate to official releases, obviously, but it’s also convenient to mark versions corresponding to project milestones such as feature completion and beta releases. We’ll examine versions, branches, and revisions in more detail in the sections that follow. To check out the current (and as it happens, only) Persistence project, do the following: 1. Expand the HEAD entry in the repository. Doing so shows the CVSROOT directory (CVS’s administration directory) and any modules that have been checked in to this CVS repository, such as the Persistence project. 2. Select the Persistence module, right-click on it, and select Check Out As from the context menu. 3. After a short pause while Eclipse talks to the CVS server, a dialog appearsthat allows you to define what type of project you are going to check out. This is useful if you added .project to .cvsignore, or if you’re checking out a project you know is of type Java and want to be able to use the Java perspective. Select Java and then Java Project. Click Next. 4. Enter the name of the project you wish to check the files in to. 5. Click Finish. [EA] Literature [EA] Gallardo D., Burnette E., McGovern R., Eclipse in Action, Manning 2003 [CVSNT] CVSNT Manual
© Copyright 2024