eclipse FAQ

Eclipse usage summary

1. The Maven package cannot be found in Eclipse

    Symptoms: org.maven.ide.eclipse.MAVEN2_CLASSPATH_CONTAINER appears , and there is a problem that Maven's dependencies cannot be found
  Solution: Build Path - > Java Build Path - > Libraries - > Add Library - > Maven Managed Dependences - > Click Next - > Click 'Maven Project settings' and add " Maven Dependencies " in 'Active Maven Profiles (comma separated)' " to confirm. At this point, you will see the added 'Maven Dependencies' under the Libraries tab of the Classpath.
 

2. There may be the following errors in maven

In eclipse, the dependent jar package cannot be found, but the corresponding jar package can be found in 'Maven Dependencies'
Failure executing javac, but could not parse the error:
Error: read C:\Documents and Settings\keju.wangkj\.m2\repository\com\sun\jdmk\jmxtools\1.2.1\jmxtools
-1.2.1.jar Error; error in opening zip file
: Error reading C:\Documents and Settings\keju.wangkj\.m2\repository\com\sun\jmx\jmxri\1.2.1\jmxri-1.2.1.jar
; error in opening zip file
2 error

Solution: Since maven downloaded the empty jar package in the warehouse, only about 1k, let maven download it again after deletion
 
3. Shortcut keys
ctrl+shift+/: Comment [select the line that needs to be commented first], which is different from ctrl+/
ctrl+shift+\: uncomment
ctrl+shift+g: which is calling this method
 
4. The development of Java Web programs is the view of the Jar package
Navigator: You can see the Jar package
Package Explorer: normal development
 

5. Automatic prompting of XML file tags in Eclipse

   In files such as the related namespaces that are introduced into spring in the xml file, sometimes new tags cannot be automatically prompted.
Solution:
   (1) First close the xml file and then open it
   (2) When introducing "xsd", the trailing "">" needs to follow the xsd, and do not wrap
 
6. The Database view module in Eclipse fails to access the database
Modify -Duser.language =zh in eclipse.ini
 
7. Set the default open mode of files in eclipse
In Window -> Preferences -> General -> Editors -> File Associations , set which editor to open by default for various file types, you can use many automatic prompt functions

 8. Restricted class access

问题: "Access restriction: Class is not accessible due to restriction on required library"; error message may be shown while developing Java projects in Eclipse IDE. Error message is self-explanatory, some classes can not be loaded into the project sincerestriction rules are being imposed on those classes.
solution:
This error message can be removed by changing a setting inside Eclipse IDE. Open up the dialog box shown below, using any of the following paths.
  • Windows -> Preferences -> Java -> Compiler -> Errors/Warnings -> Deprecated and restricted API -> Forbidden reference(access rules), error修改为warning
  • (Project) Properties -> Java Compiler -> Errors/Warnings
Locate the "Forbidden reference (access rules)" option under "Deprecated and restricted API" section in the dialog box. This option decides how to handle accessrules defined inside Eclipse. By default it is set to "Error" which causes Eclipse to complain about references to any restricted classes. Choosing any other option (Warning or Ignore) will remove these error messages.

"Warning" or "Ignore" options will only hide the potential issue in the project, by allowing the project to use any classes ignoring predefined access rules. To completely resolve this issue,analyze the project and located the use of restricted classes and take necessary actions (either remove those references or accessrules).
 
 9. Add a warning sign to the Deprecated method in eclipse for easy identification
Windows -> Preferences ->  Java  -> Compiler -> Errors/Warnings -> Deprecated and restricted API -> Deprecated API, select the 2 Combo Boxes below, 'single use. . ' and 'Single overriding. . '

 10. Modify the jvm size of eclipse

Make modifications in the eclipse.ini file under the eclipse root directory. For further details, refer to the following link

 11. Classpath in Eclipse

Java Build Path -> Source Below, there is a detailed description of the directory structure of the files generated after compilation
 
 12. Eclipse cannot start the JVM terminated. Exit code=-1 solution
Prompt error: JVM terminated. Exit code=-1. 

I found it on the Internet, and some people said that it is a problem of JAVA environment configuration. I think this is impossible, because it has been used well before. Some people say that it is a JVM problem. I just replaced this one, and it is not this problem. Later, it seems that some people say that it is the problem of too large memory settings in eclipse.ini. Although I don't think so, I still try it. The memory settings have always been good. The previous eclipse.ini configuration is as follows: 

-showsplash 
com.genuitec.myeclipse.product 
--launcher.XXMaxPermSize 
512m 
-vmargs 
-Xms256m 
-Xmx512m 
-Duser.language=en 
-XX:PermSize=256M 
- XX:MaxPermSize=512M 

is now modified, -Xms256m is changed to -Xms128m, Xmx512m is changed to Xmx256m, the result is really good, I didn't expect it to be caused by such a small problem. 
 

13. Set the maven debug port

set MAVEN_OPTS=-Xdebug -Xnoagent -Djava.compiler=NONE -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000
 
During the debugging process, you can call out " Expressions " in the lower left corner of eclipse , you can observe the operation you want to see, which is more useful.
 

14. Debugging skills of drop to frame in Eclipse

 
When I was exchanging debugging skills with my colleagues a few days ago, I learned that there is a drop to frame skill in Eclipse debug. This is something I didn't know before, and I checked the meaning of this function again. The official explanation is:
Select the  Drop to Frame  command [  Drop  ] to re-enter the selected stack frame in the  Debug View .
Note this command is only available if the current VM supports drop to frame and the selected stackframe is not the top frame or a frame in a native method.
That is, the function can re-jump to the beginning of the current method and re-execute, and the values ​​of all context variables are returned to that time. Not necessarily the current method, you can click any frame in the current call stack to jump there (except the first frame). The main purpose is to quickly restore the state of all variables to the way they were at the beginning of the method and execute it again, that is, you can debug multiple times in the context you care about (combined with other functions such as changing variable values) over and over again without having to repeat it Where is the debugging. Of course, the side effects of the original execution process are irreversible (for example, you insert a record into the database).
 
Here is also how to use this function: http://www.javalobby.org/forums/thread.jspa?threadID=15271&tstart=0
In fact, this function has been around for a long time, but most people do not know or rarely use it.
 
15、 Cut active code
The Display  view allows you to work with active code in a cut-type fashion (see Figure 8). To work with a variable, simply enter the variable name in the  Display  view and the view will prompt you with a familiar content helper. ctrl+shift+d to view the content, more content reference:
 System.identityHashCode(this): View the unique id number of the object
 
16. Java Remote Debug Official Guidance Document
-Xdebug -Xrunjdwp:transport=dt_socket,address=8000,server=y,suspend=n
 
17. Remotely debug programs in tomcat
The first is to use the remote Debug function in Eclipse to modify Tomcat's bin\catalina.bat, add set JAVA_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=7777   and then in Eclipse Select debug , create a new "Remote Java Application", write 7777 on the port, then start Tomcat, hit a breakpoint and it's OK.  
 
 

The second method is to install the Tomcat plug-in of Eclipse , which can be downloaded from many places on the Internet . Use the Tomcat plug-in to start Tomcat in Eclipse , and you can directly interrupt the Debug point .  
18. Count the number of lines of code in a project or file
Using Eclipse can easily count the number of lines of code in a project or file.
Methods as below:
1. Click Search in the menu bar, then click File...
2. Select Regular expression and enter \n in the search text box
3. Enter * or *.java in the file name
4. Select Enclosing projects in the scope
5. The number of lines of code of the project or file will be displayed in the Search window 
Or use a small plugin: http://zhwj184.iteye.com/blog/687296
19. Clear the SVN record in eclipse, modify the user name and password
 

删除掉C:\Documents and Settings\用户名\Application Data\Subversion\auth\svn.simple文件夹下的文件即可.    

再次访问时,会弹出要求输入用户名和密码 , Application Data是一个隐藏的文件夹
 
 
20、找不到src/main/java等
修改pom关系,扩展了子模块的情况下,可能在eclipse中报找不到src/main/java、src/main/resources等的情况。 是由于mvn eclipse:clean插件没有清理干净造成的。细节原因: 将<packaging>jar</packaging>修改为<packaging>pom</packaging>, 此时mvn eclipse:clean不会清理根下面的.classpath和.project文件。
解决方案:删除工程,svn出全新的内容进行mvn eclipse:eclipse或者手动删除根下面的.classpath和.project2个文件。
21、同一设置工程下面各模块的字符集
Window-> Preference->General->Workspace,右侧的Text File encoding设置为UTF-8,则以后建立的工程及各模块默认为UTF-8了。 
 
22、Eclipse中的Maven Dependencies消失了
使用m2e,先Disable Maven Management,再 Enable Maven Management即可找回消失的Maven Dependencies
 
23、删除了的workspace

删除Eclipse的workspace,

找到 eclipse\configuration\.settings\org.eclipse.ui.ide.prefs 文件
用记事本打开,找到
RECENT_WORKSPACES=D\:\\workspaces\\workspace7\nC\:\\Documents and Settings\\keju.wangkj\\workspace

将不用的workspace目录删掉就可以了

24、查看eclipse的版本
进入到eclipse安装目录下,有一个.eclipseproduct文件,用记事本打开,就可以知道版本了。
 
25、eclipse启动时,failed to create the java virtu al machine
 
  1. -startup 
  2. plugins/org.eclipse.equinox.launcher_1.1.1.R36x_v20101122_1400.jar 
  3. --launcher.library 
  4. plugins/org.eclipse.equinox.launcher.win32.win32.x86_1.1.2.R36x_v20101222 
  5. -product 
  6. org.eclipse.epp.package.rcp.product 
  7. --launcher.defaultAction 
  8. openFile 
  9. --launcher.XXMaxPermSize 
  10. 256M 
  11. -showsplash 
  12. org.eclipse.platform 
  13. --launcher.XXMaxPermSize 
  14. 256m 
  15. --launcher.defaultAction 
  16. openFile 
  17. -vmargs 
  18. -Dosgi.requiredJavaVersion=1.5 
  19. -Xms40m 
  20. -Xmx512m 
 将上面的替换为:
  1. -startup 
  2. plugins/org.eclipse.equinox.launcher_1.1.1.R36x_v20101122_1400.jar 
  3. --launcher.library 
  4. plugins/org.eclipse.equinox.launcher.win32.win32.x86_1.1.2.R36x_v20101222 
  5. -product 
  6. org.eclipse.epp.package.rcp.product 
  7. --launcher.defaultAction 
  8. openFile 
  9. --launcher.XXMaxPermSize 
  10. 128M 
  11. -showsplash 
  12. org.eclipse.platform 
  13. --launcher.XXMaxPermSize 
  14. 128m 
  15. --launcher.defaultAction 
  16. openFile 
  17. -vmargs 
  18. -Dosgi.requiredJavaVersion=1.6 
  19. -Xms40m 
  20. -Xmx256m 
 
26、开发和运行eclipse plugin的eclipse ide
可以使用的ide有: eclipse-rcp-helios-SR2-win32
不可以使用的ide有:
 
27、启动eclipse时,building workspace卡住
1. 取消 project -> build automatically 的选择 
2. 重启 
3. 删掉多余项目 
4。 再将项目拷贝进来 
 
28、调试中,条件断点的设置
即满足条件时在断点暂停下来,否则直接pass。【注意】 设置条件的时候,需要在获取到结果的下面设置断点,并进行设置条件,否则不生效(因为断点的意思是:在接触到行就暂停,即最开始就暂停,还没到判断条件)
 

breakpoint

 Hit count:可以设置 第几次满足条件的时候在断点处暂停下来, 在调试循环中特别有用
以上方式经过本人在eclipse中测试通过,可放心使用。
 
例子:判断条件为fileName当等于"run/intl_rfq/buyRequest/buyRequest_run.js"时停在断点:fileName.endsWith("run/intl_rfq/buyRequest/buyRequest_run.js")
 
29、搜索时,出现 problems encountered during search
点击详细信息时显示:Resource is out of sync with the file system
 
解决方案:  Window->Preferences menu, then in the Preferences dialog box, select General > Workspace. Check the “Refresh automatically” box.
 
30、java.lang.NoClassDefFoundError: org.junit.runner.Runner
  1. java.lang.NoClassDefFoundError: org.junit.runner.Runner 
  2.     at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:59
  3.     at org.junit.internal.requests.ClassRequest.getRunner(ClassRequest.java:24
  4.     at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.<init>(JUnit4TestReference.java:32
  5.     at org.eclipse.jdt.internal.junit4.runner.JUnit4TestClassReference.<init>(JUnit4TestClassReference.java:25
  6.     at org.eclipse.jdt.internal.junit4.runner.JUnit4TestLoader.createTest(JUnit4TestLoader.java:41
  7.     at org.eclipse.jdt.internal.junit4.runner.JUnit4TestLoader.loadTests(JUnit4TestLoader.java:31
  8.     at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:452
  9.     at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683
  10.     at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390
  11.     at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197
 
java.lang.NoClassDefFoundError: org/junit/runner/notification/RunListener 
这个异常是一个项目中存在多个Junit的jar,你需要检查当前项目下是否有两个junit. 
[一般情况下只有一个] 
还有一个重要的地方是,当前项目所依赖的项目中是否也存在Junit,如果依赖的项目Junit版本和当前项目的Junit版本不一致,那么恭喜你,你悲剧了,会发生如上错误。 
 

31、 打开过个Eclipse工作空间后,在切换工作空间时常常无法区分是那个工作空间

 

可以通过在eclipse启动是加上 -showlocation 这个参数显示工作空间信息

如:eclipse.exe -showlocation

标题栏上会显示当前工作空间信息。这时我们可以区分正在使用的是哪一个Eclipse

参考:http://blog.csdn.net/zeuskaaba/archive/2009/07/25/4380026.aspx

31、干掉已经完成的todo

在eclipse中,ide会产生大量的// TODO,用于提醒程序员那些未完成的事情,通过Tasks视图可以查看到那些未完成的内容。代码已经完成,请删除之,这个写代码的好习惯。

32、定位行、列
行:ctrl+l,或者在编辑框的左侧有:show line numbers
列:暂没有查到快捷键,但 eclipse的底部,使用java editor打开时,在smart insert的右边会现在当前光标所在的行和列 
 
33、Please enter the secure storage password ???
在unbuntu下面,启动eclipse的时候总是报:Please enter the secure storage password ???
解决方案:  delete the .eclipse folder that is inside your home directory. 删除或重命名.eclipse,再重启则ok
 
34、文本字体设置
Windows-> Preferences->General->Appearance->Basic->Text Font->Edit->设置如下:
字体:Courier New
字形:常规
大小:10
35、导出eclipse所有的配置,方便以后的配置

Eclipse的 File -> Export(导出),在窗口中展开 General(常规) -> Perferences(首选项)-->Export all(全部导出)然后点击 NEXT。然后点击"Browse(浏览)"选择任意的一个路径,保存配置文件,然后点击"Finish"。

  选择File->export->preferences.里面就有具体的到处选项了,到了其他的eclipse里选择import就可以了,顺序是对应的
 
36、eclipse的svn plugin的图标消失
Searched online for a long time and couldn't find the correct solution. Directly copy other eclipse startups, import the corresponding config to restore.
Summary: Don't spend too much time on the environment, just copy and import it.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326154211&siteId=291194637