Eclipse 出現的問題總結

 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 virtual 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進行還原。
總結:不要在環境上面花太多的時間,直接拷貝導入搞定。

參考:http://tianya23.blog.51cto.com/1081650/295940
發佈了51 篇原創文章 · 獲贊 8 · 訪問量 13萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章