0

I have done Android and C development in my copy of Eclipse, but have never actually done Java strictly. When I add code that compiles using "javac codename.java" to an eclipse project, eclipse gives me errors and can't recognize statements like import java.io.* . I believe this is due to a problem with my class path and I have tried adding some paths like library/system/java but have not had any success. Any ideas for a solution?

Matt P.
  • 193
  • 3
  • 9

4 Answers4

1

If Eclipse is having troubles with classes delivered by JDK, I would suggest checking out if it (thus - JDK) is properly installed. You may do that by going to menu Window > Preferences and started typing "jdk" in search input. It should point You to Java > Installed JREs. Check if there is proper JDK installed (if not - You may add it there). After that try to clean Your project - menu Project > Clean....

Hope this helps, regards.

ŁukaszBachman
  • 33,595
  • 11
  • 64
  • 74
  • I looked in Installed JREs and see nothing, however I am confused as of where to get the proper jdk for os x – Matt P. Mar 19 '11 at 21:04
  • You can always go to http://www.oracle.com/technetwork/java/javase/downloads/index.html and choose proper JDK for your Operating System. – ŁukaszBachman Mar 19 '11 at 21:09
  • Sorry, I haven't been using Mac. It appears that Mac OS ships with JDK already installed. Please visit http://stackoverflow.com/questions/1577014/how-install-a-specific-jdk-on-mac-os-x to get more information. But probably you have JDK installed already, you just need to locate it and point Eclipse where to find it. – ŁukaszBachman Mar 19 '11 at 21:12
0

If you go into the preferences dialog and go to Java/Installed JREs, make sure those paths are correct.

MeBigFatGuy
  • 28,272
  • 7
  • 61
  • 66
  • I frankly am not sure what the paths should be, I found this website, are these correct (I am running 10.5) http://www.mattfitz.info/library/article/113 – Matt P. Mar 19 '11 at 20:45
  • So the solution to my problem was that I had eclipse Galileo for C/C++ development, that I had originally added the Android SDK to, so I was able to compile for Android, but not for Java. I have fixed this by having two different installs of eclipse, one for C/C++/Android (Galileo) and one for Java (Helios) – Matt P. May 03 '11 at 02:24
0

In order for Eclipse to recognize source files as Java and compile them, your project has to be a Java project. Putting a .java file in a project that wasn't created via New / Java Project won't work.

Please try creating a Java project and put your .java file in it.

ChrisJ
  • 5,161
  • 25
  • 20
  • Yea I didn't do this, just to be sure I just created a new Java project and tried to import java.io.* and it didn't recognize the class at all – Matt P. Mar 19 '11 at 20:51
  • Too bad :-( In the *Package Explorer*, if you unfold *JRE System Library*, can you see anything? The main packages/classes should be in `classes.jar`. – ChrisJ Mar 19 '11 at 21:04
0

On os x the default location (right now anyway) is /System/Library/Java/JavaVirtualMachines/[VERSION].jdk/Contents/Home
The default location is available from /usr/libexec/java_home.
That said, I've never had any problems with eclipse not finding the jdk, usually it's all automatic.

Erik
  • 2,013
  • 11
  • 17
  • I realized that my issue was that I had a c/c++ build of eclipse, it would let me create a new java project but wasn't equipped to handle it, downloading eclipse classic fixed all problems – Matt P. Mar 21 '11 at 04:17