Summary of Eclipse's first Java Development-1

Source: Internet
Author: User
Tags svn client

Project needs to be developed using eclipse for the first time in Java. Many problems may occur during the process, and some problems may be very low-level. Here is a simple summary, for fear of forgetting:

1. the dyanamic web project references classes of common Java projects, and noclassdeffounderror may occur.

A simple Java project and a servlet sample program call the static method of the test class in the test project.Test ():

Obviously, the testdw project needs to reference the test project in some way. At the beginning, my method was: Right-click the testdw (Dynamic Web project) project.->Select buid path->Projects->Add the test project:

In this way, I tried to reference a common Java project before, but there will be problems in the dynamic Web project. Although there will be no errors during compilation, it will be reportedJava. Lang. noclassdeffounderroR exception:

Solution:

Right-click the testdw (Dynamic Web project) project->Select properties->Deployment assembly->Add->Project->Select the test project.

 

2. Server Runtime Environment configuration problems

To debug or run the servlet program in eclipse, you need to create a new server. However, you cannot create a new server becauseServer Runtime EnvironmentNo configuration issues.

Click window->Preferences->Server->Runtime Environment->Add->Select the tomcat installation path as needed:

In fact, this configuration is incorrect and cannot be used.HttpservletRelated class.

 

3. Chinese garbled characters in text editing:

Right-click the project->Properties->Text File Encoding->Other->UTF-8.

 

4. Smart notification

Switching from vs to eclipse is still very uncomfortable. The biggest thing is smart prompts. Eclipse's default settings are inconvenient for new users, but the simple settings are quite good:

Window->Properties->Java->Editor->Content assist: Set auto activation delay to a shorter value, for example, 20 ms. Fill in auto activation triggers for Java from A-Za-Z and:

In addition, some shortcut keys found in the use process are also very practical:

CTRL + Shift + F automatically beautify the code format

CTRL + Shift + O automatically import the required package/delete unnecessary packages.

Another problem with Ctrl + Shift + F is that this hot key conflicts with the "simplified and traditional shortcuts" of sogou's input method:

 

5. Problems with referencing third-party class libraries

You can select Add external jars in the buid path, but the referenced jar package uses an absolute path. copying a project to another user's computer may cause problems, I am using the following method: Create a lib directory under the project and put the required third-party jar package, and then select Add jars in the buid path to add the jar package under the project directory, in this way, the relative path is used.

In addition, I found that third-party jar packages required by the dynamic Web project need to be placed inWebcontent web-INFUnder the lib directory.

 

6. Source Code not found

When debugging or F3, the system prompts that the source code cannot be found:

Simple clickAttach SourceUnzip the src.zip file under the JDK installation directory.

 

7. xstream serialization underline Problem

In the project, xstream is used for serialization. However, a strange problem is that a field in deserialization contains an underscore (for exampleBiz_result), But the actual returned serialization result isBiz _ result, With an extra underline. To solve this problem, use xstream:

@SuppressWarnings("deprecation")XmlFriendlyReplacer replacer = new XmlFriendlyReplacer("__", "_");@SuppressWarnings("deprecation")HierarchicalStreamDriver hierarchicalStreamDriver = new XppDriver(replacer);XStream xStream = new XStream(hierarchicalStreamDriver);

 

For more use of xstream, see the official documentation: http://xstream.codehaus.org/alias-tutorial.html

 

8. Code Synchronization Problems

Another headache encountered during development is the issue of code synchronization, because SVN has been used before, and the project code developed by C # is relatively simple to synchronize. vs handles many dependencies, we don't need to worry about it. At first, I uploaded the entire Java workspace to SVN, and other colleagues checked the issues, I guess it is because I uploaded some files with dependencies between projects (for example. classpath ,. settings and so on, the specific file is gradually studied later), and at last there is no way to submit only the Java file at a time, but it is a headache if there are more than one file and more than one package level. The SVN client plug-in exists in vs, And I think there must also be in eclipse. As a result, a search on the Internet is as expected, that is, subclipse.

Installing subeclipse in eclipse as a plug-in is very simple:

Help->Install new software, just enter the installation of subeclipse.

After installation, you can see the svn configuration in WINDOW> preferences> Team:

If the code in the workspace is checked from SVN, right-click the project and choose team.->Share Project->SVN->...... Then you can see the related version control operations in the team:

Similar to the project share in Vs, there are also various shapes of icons indicating different meanings. For example, the black and white star represents that the Code is not synchronized to SVN and the Red Square in vs indicates that:

 

 

8. Split special characters

1. If ". ", must be written as follows: string. split ("\\. "), in this way, the correct separation is not allowed using string. split (". ");
2. If "|" is used as the separator, it must be written as follows: string. split ("\ |"), in order to correctly separate, cannot use string. split ("| ");
"." And "|" are escape characters and must be added "\\";
3. If a string contains multiple separators, you can use "|" as a hyphen, for example, "A = 1 and B = 2 or C = 3 ", you can use string to separate all three. split ("and | or ");

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.