Eclipse使用总结

简介:

1、Eclipse中出现无法找到Maven包

    症状:出现 org.maven.ide.eclipse.MAVEN2_CLASSPATH_CONTAINER, 且出现无法找到Maven的依赖的问题
  解决方案:Build Path -》 Java Build Path -》 Libraries -》Add Library -》Maven Managed Dependences -》点击Next -》点击‘Maven Project settings’ , 在‘Active Maven Profiles (comma separated)’中添加“ Maven Dependencies”确认即可。此时会在Classpath 的Libraries的标签栏下面看到添加的‘Maven Dependencies’。

2、在maven中可能存在如下的错误

在eclipse中表现为无法找到依赖的jar包,而‘Maven Dependencies中却能找到相应的jar包
Failure executing javac, but could not parse the error:
错误:读取 C:\Documents and Settings\keju.wangkj\.m2\repository\com\sun\jdmk\jmxtools\1.2.1\jmxtools
-1.2.1.jar 时出错;error in opening zip file
错误:读取 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 错误

解决方案:由于maven下载了空壳的jar包在仓库中,只有1k左右,删除之后让maven重新下载
 
3、快捷键
ctrl+shift+/:注释【先选中需要注释的行】, 与ctrl+/的方式有区别
ctrl+shift+\:取消注释
ctrl+shift+g:哪些在调用此方法
 
4、开发Java Web程序是Jar包的查看
Navigator:可以看到Jar包
Package Explorer:正常开发
 

5、Eclipse中的XML文件标签自动提示

   在xml文件中引入spring的相关的命名空间之类的文件中,有时出现不能自动提示新的标签的情况。
解决办法:
   (1)先关闭xml文件再打开
   (2)引入“xsd”的时,结尾的“">”需要紧随xsd之后,不要换行
 
6、Eclipse中的Database视图模块出现不上数据库的问题
修改eclipse.ini中修改 -Duser.language=zh即可
 
7、eclipse中设置文件的默认打开模式
Window -> Preferences ->General -> Editors -> File Associations中设置各种文件类型默认使用什么编辑器打开,则可以使用很多自动提示功能

 8、受限的类访问

问题: "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.
解决方案:
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、为eclipse中的Deprecated方法添加警告标示,方便识别
Windows -> Preferences -> Java -> Compiler -> Errors/Warnings -> Deprecated and restricted API ->Deprecated API, 选择上下面的2个Combo Box(组合框),‘single use 。。’和‘Single overriding。。’

 10、修改eclipse的jvm大小

在eclipse根目录下面的eclipse.ini文件中进行修改,进一步细节参考如下链接

 11、Eclipse中的classpath

Java Build Path -> Source 下面, 有关于编译之后生成的文件的目录结构的详细说明
 
 12、 eclipse 无法启动 JVM terminated. Exit code=-1 的解决办法
提示错误: JVM   terminated. Exit   code=-1。 

在网上找了一下,有人说是JAVA环境配置的问题,我想这不可能,因为以前一直用的好好的。有人说是JVM的问题,这个我刚刚换了一个,也不是这个问题,后来看来有人说是:eclipse.ini中内存设置过大的问题,虽然我不以为然,还是试了一下,以前我修改过内存设置,一直都好好的,之前 eclipse.ini的配置如下: 

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

现在修改了一下, -Xms256m改成-Xms128m,把Xmx512m  改为 Xmx256m,结果还真的好了,没想到居然是这样的小问题引起来的。 
 

13、设置maven调试端口

set MAVEN_OPTS=-Xdebug -Xnoagent -Djava.compiler=NONE -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000
 
调试的过程中,在eclipse的左下角处将“ Expressions”调出来,可以观察自己想看的操作,比较有用。
 

14、Eclipse 中 drop to frame 的调试技巧

 
前些天和同事交流调试技巧时,知道了 Eclipse debug 时有个 drop to frame 的技巧。这是我以前不知道的,自己又查了一下这个功能的含义。官方的解释是:
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.
就是说,这个功能可以重新跳到当前方法的开始处重新执行,并且所有上下文变量的值也回到那个时候。不一定是当前方法,可以点击当前调用栈中的任何一个frame跳到那里(除了最开始的那个frame)。 主要用途是所有变量状态快速恢复到方法开始时候的样子重新执行一遍,即可以一遍又一遍地在那个你关注的上下文中进行多次调试(结合改变变量值等其它功能),而不用重来一遍调试到哪里了。当然,原来执行过程中产生的副作用是不可逆的(比如你往数据库中插入了一条记录)。
 
这里也说了如何使用这个功能:http://www.javalobby.org/forums/thread.jspa?threadID=15271&tstart=0
其实这个功能早就有了,就是一般人不知道或很少使用。
 
15、 剪切活动代码
Display 视图允许您以剪切类型的方式处理活动代码(参见图 8)。要处理一个变量,在  Display 视图中输入变量名即可,视图会提示您一个熟悉的内容助手。ctrl+shift+d即可查看内容,更多内容参考:
 System.identityHashCode(this):查看对象的唯一id号
 
16、Java 远程Debug官方指导文档
 -Xdebug -Xrunjdwp:transport=dt_socket,address=8000,server=y,suspend=n
 
17、远程调试tomcat中的程序
第一种是采用 Eclipse 中的远程 Debug 功能  
修改Tomcat的bin\catalina.bat,在里面加入set   JAVA_OPTS=-Xdebug   -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=7777    
然后在 Eclipse 中选择 debug ,新建”Remote   Java   Application,在port上写入7777,然后再启动Tomcat,打上断点就OK了。  

第二种方法是安装Eclipse的Tomcat插件,网上很多地方可以下载,在Eclipse中使用Tomcat插件启动Tomcat,就可以直接打断点Debug  
18、统计工程或文件的代码行数
使用Eclipse可以方便的统计工程或文件的代码行数。
方法如下:
1.在菜单栏点击Search,然后点击File...
2.选中正则表达式(Regular expression),并在搜索文本框输入\n
3.在文件名中输入*或*.java
4.在范围里选中Enclosing projects
5.在Search窗口就会显示出项目或文件的代码行数 
或者使用小插件: http://zhwj184.iteye.com/blog/687296
19、清除eclipse中的SVN记录,修改用户名和密码

删除掉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的图标消失
在网上找了半天,没有找到正确的解决方案。直接拷贝其他的eclipse启动,导入相应的config进行还原。
总结:不要在环境上面花太多的时间,直接拷贝导入搞定。
 
 本文转自 tianya23 51CTO博客,原文链接:http://blog.51cto.com/tianya23/295940,如需转载请自行联系原作者
相关文章
|
程序员 Android开发 C++
在使用体验上,VS远远不如Eclipse
在使用体验上,VS远远不如Eclipse
77 0
|
XML SQL Oracle
MyEclipse使用手册(详细版)2
MyEclipse使用手册(详细版)
260 0
|
XML Oracle Java
MyEclipse使用手册(详细版)
MyEclipse使用手册(详细版)
203 0
|
Java 开发工具 Android开发
|
Java 应用服务中间件 Android开发