资料1:
主要是配置文件的路径问题。打开终端,输入vi /etc/profile添加如下代码即可。
set JAVA_HOME=/usr/java/jdk1.7.0-05
export JAVA_HOME
set PATH=$JAVA_HOME/bin:$PATH
export PATH
set CLASSPATH=.:$JAVA_HOME/lib/dt.jar:JAVA_HOME/lib/tools.jar
export CLASSPATH
注意上面緑色的地方是点(代表当前路径)和一个冒号。
另外即使代码文件放在中文目录也是可以正常运行的,我自己的就是在/home/bkd/workspace/2基础语法/src/org/object_orient目录下。
资料2:
Eclipse “cannot be resolved to a type” error
引言:
eclipse新导入的项目经常可以看到“XX cannot be resolved to a type”的报错信息。本文将做以简单总结。
正文:
(1)jdk不匹配(或不存在)
项目指定的jdk为“jdk1.6.0_18”,而当前eclipse使用的是“jdk1.6.0_22”。需要在BuildPath | Libraries,中做简单调整。
(2)jar包缺失或冲突
当找不到“XX”所在的jar包时,会报这个错。解决只需要找到(ctrl+点击,可能能看到jar包名称)对应jar包导入项目即可。
另外,出现相同的XX时也会报此错。可能需要调包、解包、选删。
(3)eclipse查找项目类型策略所致
eclipse下,上述两条都对比过了,没有任何问题,可偏偏还报这错。这时,需要操作一下 Project | Clean... ,问题即可解决。原因是,机制所致。因为某些特殊原因,eclipse没能自动编译源代码到build/classes(或其他classes目录),导致类型查找不到。
Based on the comments here, I started checking how I could make sure that my Ant build
wouldn’t interfere with my Eclipse build.
I found an option in Eclipse that clears up the problem (and is possibly more efficient than
changing the 2 build system’s output folders).
Windows–>Preferences–>Java–>Compiler–>Building–>Output folder–>
”Rebuild class files modified by others”. This exists in Eclipse 3.5; I’m not sure about earlier versions.
Checking this seems to have fixed my problems.
资料3:
MyEclipse中删除class文件后可以自动编译。
1、设置自动编译方法:
设置路径:eclipse—》Project —》Build Automatically,该选项必选打勾,如果没有打勾则打勾后就行。如图:
注意:
1、如果该文件中没有引用到该错误library,我们也可以通过其他设置编译忽略这些错误的存在进行编译。
2、这里有工程也有全局的,必须两个都设置对了才可以编译。
我的解决方法就是上面红色部分!!!感谢!!