Eclipse Quick Start Guide

Source: Internet
Author: User
Title Eclipse Quick Start GuideSelect blog from njchenyi
Keywords Eclipse Quick Start Guide
Source

Eclipse Quick Start Guide (1)

Author: asklxf

Eclipse is a very good open-source IDE and is very suitable for Java Development. Thanks to the plug-in technology, it is welcomed by more and more developers. The latest eclipse 3.0 not only greatly enhances the interface, but also addsCodeFold and many other excellent features, and the speed has also been significantly improved. With a variety of dazzling plug-ins, it can fully meet the needs of development from enterprise-level Java applications to mobile terminal JAVA games. This article will show you how to develop common JavaProgram, Web applications, J2EE applications, mobile Java programs, and how to perform unit tests, refactoring, and configuration of CVS. My development environment is jdk1.4.2 + eclipse3.0 + Windows XP SP2. If you have any questions on other platforms, please send me a letter.

1. Install jdk1.4

Eclipse is a development environment based on the Java platform. It must also run on the Java Virtual Machine and use the JDK compiler. Therefore, we must first install JDK. Jdk1.4 is currently the most stable version, and is also a required condition for eclipse operation. First download the jdk1.4 installation from Sun's official site http://java.sun.com, you can set the installation directory, I install it to the D: \ Software \ j2sdk1.4 directory. Next, configure the environment variables so that the Java program can find the installed JDK and other configuration information. Right-click "my computer" and select "properties". In the displayed dialog box, select "advanced" and "environment variable" to see the environment variable dialog box:

The preceding user variables are valid only for the current user. The following are system variables, which are valid for all users. If you want all users to use it, click "new" under the system variable and fill in:

Java_home is the JDK installation directory. Many development environments that depend on JDK depend on it to locate JDK. Therefore, it must be correct.

Next, find the system variable path, click "edit", and add the directory where the JDK executable file is located, namely % java_home % \ bin. My corresponding directory is D: \ Software \ j2sdk1.4 \ bin, which must be appended to the path. Separate them with semicolons:

NOTE: If multiple Java virtual machines are installed in the system (for example, if Oracle 9i is installed with jdk1.3), you must put the jdk1.4 path in front of other JVMs; otherwise, an error will be reported when eclipse is started.

The last system variable is classpath. the Java Virtual Machine searches for the directory where the class file is located based on the classpath settings. However, this is not required. You can specify classpath when running the Java program, for example, when running a written Java program in eclipse, it will automatically set classpath, but in order to run the Java program conveniently on the console, I suggest setting a classpath, set its value to ". ", note that it is a point". "indicates the current directory. Users who are familiar with windows may think that the Java Virtual Machine will search for the current directory during the search. In fact, this is a UNIX habit, out of security considerations. Many beginners of Java are eager to write hello and world programs in the book, but Java pops up. lang. noclassdeffounderror is actually not configured with classpath, as long as you add a current directory "..

2. Install eclipse 3.0

After the JDK is configured, the next step is to install eclipse 3.0, you can download from the official site of eclipse http://www.eclipse.org, you will see the following version:

● Eclipse SDK
● RCP runtime binary
● RCP SDK
● Platform runtime binary
● Platform SDK
● Jdt runtime binary

The eclipse SDK includes the eclipse development environment, Java development environment, and plug-in development environment.Source codeAnd documentation. If you need all the functions, you can download this version.

If you are just like me, just use eclipse to develop Java applications, instead of developing Eclipse plug-ins or studying eclipse code, downloading a platform runtime binary plus jdt runtime binary is the best choice.

When the slave node is running, the startup screen is displayed:

Wait a moment and the eclipse interface will pop up. If an error occurs and the startup fails, you can check the log file in the eclipse directory. I have encountered an xmlparser exception. Check carefully and find that there is an Oracle Java Virtual Machine in the original path, after removing it from the path, eclipse starts normally.

3. The first Java program

Run eclipse and select "file", "new", and "project" from the menu to create a Java project. I name it helloworld and create a new Java class:

I named it helloworld, filled in the package as example, hooked it with "public static void main (string [] ARGs)", and clicked "finish". Eclipse automatically generated the code framework, we only need to fill in the main method:

By default, eclipse automatically compiles data in the background. You only need to save the data and select "run", "Run as", and "Java application" to view the output on the eclipse console.

Debugging Java programs is also very simple. The run menu contains standard Debugging commands, which can be used to conveniently debug applications in the IDE environment.

Version 1.4 supports:

Select "window", "Preferences", find "Java", "compiler", "compliance and classfiles" in the dialog box, and change the compilation option to 1.4, you can use the assert (assert) syntax of jdk1.4 to make the test more convenient:

EclipseQuick Start Guide(2)

Author: asklxf

4. Use JUnit in eclipse

Testing plays an important role in ensuring the quality of software development, and unit testing is essential. JUnit is a very powerful unit testing package, you can test one or more methods of one or more classes, and combine different testcase into testsuit to automate the test tasks. Eclipse also integrates JUnit, which makes it easy to compile testcase.

We create a Java project and add an example. Hello class. First, we add an ABS () method to the Hello class,

Returns the absolute value:

Next, we are going to test this method to ensure its functionality is normal. Select hello. Java, right-click, and choose new-> JUnit test case:

Eclipse will ask whether to add the JUnit. jar package and create a hellotest class to test the Hello class.

Select setup () and teardown (), and then click "Next ":

Select the method to be tested. We select the ABS (INT) method and enter the following in hellotest. Java:

JUnit performs the test in the following order: (rough code)

Try {

Hellotest test = new hellotest (); // create a test instance

Test. Setup (); // initialize the test environment

Test. testabs (); // Test A Method

Test. teardown (); // clear Resources

}

Catch...

Setup () is to create a test environment. Here we create a hello class instance; teardown () is used to clear resources, such as releasing open files. Methods Starting with test are considered as test methods. JUnit will execute the testxxx () method in sequence. In the testabs () method, we select positive, negative, and 0 for the ABS () test. If the return value of the method is the same as the expected result, assertequals will not generate an exception.

If there are multiple testxxx methods, JUnit will create multiple xxxtest instances. Each time a testxxx method is run, setup () and teardown () will be called before and after testxxx. Therefore, do not depend on testb () in a testa ().

Run-> Run as-> JUnit test directly to view the JUnit test results:

Green indicates that the test is successful. If one test fails, the red color is displayed and the method for failing the test is listed. You can try to change the ABS () code, intentionally return the error result (such as return n + 1;), and then run JUnit to report the error.

If the JUnit panel is not available, choose Window> show View> other to open the view of JUnit:

Through unit tests, JUnit can identify many bugs in the development phase. In addition, multiple test cases can be combined into test suite to automatically complete the test, which is especially suitable for the XP method. Each time you add a small new function or make minor changes to the Code, you can immediately run test suite to ensure that the newly added and modified code does not destroy the original function, this greatly enhances Software maintainability and avoids code corruption ".

EclipseQuick Start Guide(3)

Author: asklxf

5. Use ant in eclipse

Ant is a great batch processing command execution program on the Java platform. It can easily and automatically compile, test, package, and deploy a series of tasks, greatly improving the development efficiency. If you haven't started to use ant now, you need to learn how to use it to bring your development level to a new level.

Ant has been integrated in eclipse. We can directly run ant in eclipse.

The preceding Hello project is used as an example to create the following directory structure:

Create a new build. xml file and place it in the project root directory. Build. xml defines the batch processing command to be executed by ant. Although ant can also use other file names, compliance with standards makes development more standard and easy to communicate with others.

Generally, Src stores Java source files, classes stores compiled class files, lib stores all jar files used for compilation and running, and Web stores web files such as JSP files, dist stores the packaged JAR file and Doc stores the API documentation.

Create the build. xml file in the root directory and enter the following content:

<? XML version = "1.0"?>

<Project name = "Hello World" default = "Doc">

<! -- Properies -->

<Property name = "src. dir" value = "src"/>

<Property name = "report. dir" value = "report"/>

<Property name = "classes. dir" value = "classes"/>

<Property name = "Lib. dir" value = "lib"/>

<Property name = "Dist. dir" value = "Dist"/>

<Property name = "Doc. dir" value = "Doc"/>

<! -- Define classpath -->

<Path id = "Master-classpath">

<Fileset file = "$ {Lib. dir}/*. Jar"/>

<Pathelement Path = "$ {classes. dir}"/>

</Path>

<! -- Initialize the task -->

<Target name = "init">

</Target>

<! -- Compile -->

<Target name = "compile" depends = "init" Description = "compile the source files">

<Mkdir dir = "$ {classes. dir}"/>

<Javac srcdir = "$ {SRC. dir}" destdir = "$ {classes. dir}" target = "1.4">

<Classpath refID = "Master-classpath"/>

</Javac>

</Target>

<! -- Test -->

<Target name = "test" depends = "compile" Description = "Run JUnit test">

<Mkdir dir = "$ {report. dir}"/>

<JUnit printsummary = "on"

Haltonfailure = "false"

Failureproperty = "tests. Failed"

Showoutput = "true">

<Classpath refID = "Master-classpath"/>

<Formatter type = "plain"/>

<Batchtest todir = "$ {report. dir}">

<Fileset dir = "$ {classes. dir}">

<Include name = "**/* test. *"/>

</Fileset>

</Batchtest>

</JUnit>

<Fail if = "tests. Failed">

**************************************** *******************

* *** One or more tests failed! Check the output ...****

**************************************** *******************

</Fail>

</Target>

<! -- Package it into jar -->

<Target name = "pack" depends = "test" Description = "make. jar file">

<Mkdir dir = "$ {Dist. dir}"/>

<Jar destfile = "$ {Dist. dir}/Hello. Jar" basedir = "$ {classes. dir}">

<Exclude name = "**/* test. *"/>

<Exclude name = "**/test *. *"/>

</Jar>

</Target>

<! -- Output API documentation -->

<Target name = "Doc" depends = "pack" Description = "create API Doc">

<Mkdir dir = "$ {Doc. dir}"/>

<Javadoc destdir = "$ {Doc. dir }"

Author = "true"

Version = "true"

Use = "true"

Windowtitle = "test API">

<Packageset dir = "$ {SRC. dir}" defaultexcludes = "yes">

<Include name = "example/**"/>

</Packageset>

<Doctitle> <! [CDATA [

<Bottom> <! [CDATA [<I> All Rights Reserved. </I>]> </bottom>

<Tag name = "Todo" Scope = "all" Description = "to do:"/>

</Javadoc>

</Target>

</Project>

The preceding XML defines Init (initialization), compile (Compilation), test (test), DOC (generate document), and pack (Package) Tasks in sequence and can be used as templates.

Select the hello project, and then select "project", "properties", "builders", "New ...", Select "ant build ":

Enter name: ant_builder; buildfile: build. XML; base Directory: $ {workspace_loc:/Hello} (Press "Browse workspace" to select the project root directory), because JUnit is used. jar package, search for the eclipse directory, and find JUnit. jar, copy it to the Hello/lib directory, and add it to the classpath of ant:

Then hook ant_build In the builder panel and remove Java builder:

Compile again to view the ant output in the console:

Buildfile: F: \ eclipse-Projects \ Hello \ build. xml

Init:

Compile:

[Mkdir] created dir: F: \ eclipse-Projects \ Hello \ Classes

[Javac] compiling 2 source files to F: \ eclipse-Projects \ Hello \ Classes

Test:

[Mkdir] created dir: F: \ eclipse-Projects \ Hello \ report

[JUnit] running example. hellotest

[JUnit] tests run: 1, failures: 0, errors: 0, time elapsed: 0.02 Sec

Pack:

[Mkdir] created dir: F: \ eclipse-Projects \ Hello \ Dist

[Jar] building jar: F: \ eclipse-Projects \ Hello \ Dist \ hello. Jar

DOC:

[Mkdir] created dir: F: \ eclipse-Projects \ Hello \ doc

[Javadoc] generating javadoc

[Javadoc] javadoc execution

[Javadoc] loading source files for Package example...

[Javadoc] constructing javadoc information...

[Javadoc] standard doclet version 1.4.2 _ 04

[Javadoc] building tree for all the packages and classes...

[Javadoc] building index for all the packages and classes...

[Javadoc] building index for all classes...

[Javadoc] generating F: \ eclipse-Projects \ Hello \ doc \ stylesheet.css...

[Javadoc] Note: Custom tags that cocould override future standard tags: @ todo. To avoid potential overrides, use at least one period character (.) In custom tag names.

[Javadoc] Note: Custom tags that were not seen: @ todo

Build successful

Total time: 11 seconds

Ant executes initialization, compilation, testing, packaging, and generation of a series of API documentation tasks in turn, greatly improving the development efficiency. You can also add deployment and other tasks when developing a J2EE project in the future. In addition, even if you are out of the eclipse environment, you only need to correctly install ant and configure the environment variable ant_home = <Ant Extract directory>, Path = ...; % Ant_home % \ bin, switch to the hello directory at the command line prompt, and simply type ant.

EclipsePlatformJ2EEIntegration of Development

Author: crayon knives

(I have promised mingjava to introduce how to integrate the vendor's SDK on the eclipse platform. I am in a bad mood when I encounter some minor problems for a few days. But it's not a way to be depressed. If you write something, You can dispatch it :)

It is better to integrate the simulators of some common manufacturers when using eclipse to develop j2s, which is convenient. This article briefly introduces how to integrate Nokia, Sony Ericsson, and Samsung simulators into the eclipse environment. Note that the eclipseme version I use is 0.4.3, and the new version may change a bit. I hope someone can make some corrections.

The vendor provides three forms of Development Kits:

One is to provide a vendor version of wtk, such as Sony Ericsson. This wtk contains the SDK and simulator. developers can directly use this wtk for development (the root is the same as the standard wtk provided by Sun );

Second, it provides development tools that work with wtk, such as Nokia. You need to install wtk first, and the installation of the Nokia development tool will allow you to select the wtk path.

The third is to provide an independent development environment, but it is not in the form of wtk, such as Moto. On the development tool of Moto, there is a simulator Startup Program with sdks corresponding to various simulators and compiled batch processing files.

I have met these three types, and I have never heard of them. For Sony Ericsson, the Simulator Based on wtk is easier to integrate into eclipse, because eclipseme also relies on wtk. If you integrate these manufacturers' simulators into a wtk, you can use them in eclipse.

1. Nokia Simulator

Nokia's simulators are installed by the installer. In fact, you can find an installed simulator and copy the entire folder to the wtk wtklib \ devices folder. I often use simulators 7210,3300 and s60beta0.1. Among them, 7210 supports Chinese characters and the startup speed is fast. It is the first choice for 40 developers. The 60 simulator is relatively slow. It is generally used only for porting.

2. Sony Ericsson k700 simulator with Samsung SGH-S100, s200, C100

Both Sony Ericsson and Samsung provide development kits in the form of wtk, And the simulator folder is in the devices of their wtk. Copy them to your wtk. However, you need to change the location, otherwise it will not be available in eclipse. Take Sony Ericsson k700 as an example. Open the configuration file "sonyericsson_k700.properties" in the simulator folder and search for the keyboard. handler = com. sun. kvem. MIDP. configurablekeyboardhandler, which calls the # annotation and changes it to the keyboard. handler = com. sun. kvem. MIDP. defaultkeyboardhandler, which can be used in eclipse. However, Samsung's simulators can only be used under wtk2.2. If you do not want to replace the current wtk, You have to install another wtk2.2. eclipseme supports multiple wtk at the same time, if you select the wtk2.2 configuration when creating the project, you can select the Samsung simulator from the run simulator menu. But there is still a problem, at least for the eclipseme of my version, you need to open the Properties window of the project, delete all content in the Connection Library (originally the default wtk2.2 Lib) and manually add the required Lib, such as cldc1.1, midp2.0, and mmapi.

3. Moto Simulator

I still cannot integrate them into eclipse. I found that the moto simulator is not the standard wtk format, and its configuration file format is not compatible with the wtk simulator. This configuration file is used by launch.exe in the motodevelopment tool. Which of the following statements can be explained.

Note: This article mainly describes the simulators of Nokia and midp2.0. The midp2.0 simulator basically only has one configuration file and several images, while the Nokia simulator also has lib and so on. The situation may be different for simulators with manufacturers' APIs. This requires specific models, but eclipse can specify external jar, which may be the solution.

Author's blog:Http://blog.csdn.net/njchenyi/RelatedArticle

Eclipse Quick Start Guide
Implement the Extensible directory tree treelist in
Use j2meunit for unit testing
Two Methods for instance Analysis of Network Programming
Solutions to the NTFS file system supported by Fedora Core 4.0
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.