OK. Something is strange here. I am trying to follow the instructions in Chapter 2. I am using Eclipse standard x86-64, "Kepler" version .
I downloaded the example code and extracted that, yielding (among other things) the "examples-eclipse.zip" file. I tried installing and found that it puts a "LearningJava" directory in my "Learning Java" directory in the workspace. This new directory has its own "src" and "bin" directories. This is clearly not working.
So, I extracted the contents of examples-eclipse.zip and re-zipped them but without the "LearningJava" directory (the root of the zip file has the src directory). That worked MUCH BETTER, as I can now run some of the examples. However, Eclipse still screams about over a hundred errors and warnings (including examples from chapters 15, 21, 23, and 24). I am assuming that these errors are not expected.
In short, it took some hacking to get the examples properly installed, and even then, it is not all smooth sailing. I hope that this can get fixed soon.
Help get this topic noticed by sharing it on Twitter, Facebook, or email.
I have forwarded your question on to our Book Tech staff, so they can help you find a solution. If you ever have any questions or issues with the content of a title, you can also contact them directly at email@example.com or call them at:
1-707-827-7019 (outside the USA)
7:30 am to 5:00 PST
Customer Service Representative
Once I was able to find the source for the example files - not at "http://oreil.ly/Java_4E" as indicated in the book - I had a similar problem getting the first example to work. I should also add that I'm using Eclipse Juno on a Macbook Pro running OS-X 10.8.4.
I think I'm following the instructions step by step, but I get a sub directory created on my computer called "LearningJava" under my "Learning Java" project folder. The LearningJava sub directory has its own src and bin folders - these show up in the Eclipse project under the LearningJava folder.
Eclipse seems happy enough with this until I try to run the first HelloJava example. Then I get a message that there is no main function in the editor.
Daryl: As I stated, the "archive" is really just a .zip file. Extract it. Go into the created directory and add all of those files back to a new .zip file (you are really just removing the top-level containing folder). Import this new .zip file as the archive, and things will be MUCH better.
I got a note back from the author about this problem, which has been corrected.
This problem was due to the inconsistent instructions between ch2 and appa and will go away if readers download the correct zip now.
So, just go here - https://github.com/patniemeyer/learni...
and click on Download Zip to download the latest code.
O'Reilly Book Support
ok, finally got this working..kinda.. what i did....
1. Go to https://github.com/patniemeyer/learni...
2. Click the download link on the right side of the page
3. unzip the downloaded file
4. in eclipse, go to file > import > general > archived file (check overwrite existing files option and )
5. choose the examples-eclipse-ch2.zip from the unzipped directory
6. all the files are imported as "src/ch..." subfolders of the Learning Java project that was created per the book instructions.
The example src/ch.. files are riddled with warnings and errors (warnings ch 2-14, 16-20, 22 errors ch 15, 21, 23-24) but I am unsure whether these are addressed in the book as i haven't been able to work through chapter 2 yet because of the underlying issue here...
I have noticed some errors myself after importing the files. These errors are in Chapters 15, 21, 23, and 24
However, this is NORMAL!!! Please refer to Appendix A, figure A-2. You can see that there are warnings/errors are there too. Apparently those are expected and/or intentional. If you see errors there, all seems to be OK.
If you are getting errors in Chapter 2, you are still in some trouble.
PROBLEM SOLVED, FIX BELOW!
The archive you need is IN the archive that you download from the main page.
When you click "Download Zip" you get a file names "learningjava-master.zip".
Unzip that file, then open the folder and navigate to:
learningjava-master -> examples -> eclipse project -> examples-eclipse-ch2.zip
Even though it has a "ch2" on the end, it has the complete project. (I think they just put it there so that any reasonable person would NOT think to look at it...)
To get the examples working, follow these steps.
(Ignore the steps in the book--they are wrong, wrong, wrong!) This works with the latest version of Eclipse: Kepler.
1) Go to http://oreil.ly/Java_4E, click on Download Sample Code, which takes you to a github page, then click Download Zip and save the file to your Desktop (or other convenient place.
2) The file you downloaded is named "learningjava-master.zip", extract that and you will get a directory named "learningjava-master". The zip file you really need is buried deep in there...
3) Open Eclipse
4) Go to File -> Import (don't create a project--you are importing one)
5) Expand General and select "Existing Projects into Workspace" and click "Next"
6) Choose "Select Archive File" and browse to learningjava-master -> examples -> eclipse project -> examples-eclipse-ch2.zip; select OK
7) Click Finish
Your project with example code has been imported to Eclipse and the examples run!
So, if you remember the instructions are wrong, the file name is wrong and the code is not where you expect it to be and the name makes no sense... you will do just fine!
Hi, I am Pat Niemeyer, the author of Learning Java. I apologize for the trouble many of you have had in installing the example code. The problem is that the book contains two competing sets of directions for importing the examples into Eclipse -- One set of instructions in chapter 2 and another set of instructions in Appendix A. (The difference is that one set expects a zip file containing a top level source directory and one does not.)
To resolve this, shortly after the book was published I updated github with *two* zip downloads -- one named examples-eclipse-ch2.zip for readers using the instructions in chapter 2 and one named examples-eclipse-appa.zip for readers following the instructions in appendix A. If you choose the appropriate zip file it will work with the instructions provided in the respective chapter.
Both zip files contain all of the example code used in the book. The only difference is the packaging. I am updating the README file to clarify this.
Alternately, you may wish to read through the Eclipse tutorial in Appendix A first to learn how to create a project and then simply browser the source on github and copy & paste individual examples into files as needed.
Again, I apologize for any frustration this has caused and the problem will be resolved in the next edition.
Here is the README.txt in the examples-eclipse directory on github.
This directory contains two identical copies of the full Learning Java source code, packaged for eclipse in different ways. If you are following the instructions in Chapter 2 please choose the "examples-eclipse-ch2.zip" file. If you are following the instructions in Appendix A please choose "examples-eclipse-appa.zip".
The difference is that the Appendix A version contains a top level "Learning Java" folder and the Chapter 2 version has the contents at the top level of the zip file. We apologize for the necessity of the two versions; the loading instructions in each chapter are slightly different and will be reconciled in a future update.
examples-eclipse-ch2.zip -- Full source code for the book Learning Java. Use this file if following the installation instructions in Chapter 2.
examples-eclipse-appa.zip -- Full source code for the book Learning Java. Use this file if following the installation instructions in Appendix A.
Who turns to the appendix to install the examples? Why have a different file name than the instructions? Why the heck call it "examples-eclipse-ch2.zip" which sounds like it's just examples from one chapter--and not the whole book?
It's still confusing and it won't lead the reader to the right solution.
You have instructions in the text of the book, Chapter 2, page 28. People are going to try that way--and probably never find this page or look at the appendix.
Why don't you change the file name on Github--or the link redirect from http://oreil.ly/Java_4E to point to a file named the same as the book, and unpacks and installs to Eclipse, the way it says you should install IN THE BOOK!
It's a hell of a lot easier to change a linked file to match the book than it is to change the book (you can't once it's printed on paper or downloaded....) and the natural instincts of the people who buy the book. (Their habits are justly founded: you start reading, you get to an example (Ch2, P28) and you follow the directions.)
This is still not a reasonable solution. It's just one more bad solution to a simple problem.
see the change log
I can't agree more with John Berns - why would you not change the linked file to match what is described in the book? Even the updated readme doesn't help when it's three levels down from the URL listed in the book (which redirects the user, leading one to wonder if maybe you're in the wrong place).
In addition, I don't seem to be able to unzip just the ch2.zip file - I've downloaded it from multiple browsers, tried using both the Mac Archive Utility and StuffIt (both of which just converted the .zip to a .cpgz), unzipped from the command line (which gave me an "end-of-central-directory signature not found" error), and finally just downloaded the master example file. That unzipped just fine, leading me to believe that something is wrong with the ch2.zip file itself.
I'll follow the instructions upthread for using the master example file, but I'm already frustrated, and I just started. Not an inspiring start. I mean, I'm here - I found this thread, I downloaded the master example file, I followed John's instructions, and I finally have the source code in eclipse, but the book instructions were useless, the READMEs on the github site were useless, and the author's post here was useless. What am I supposed to infer about the rest of the book contents?
I've just gone through this myself and cracked it through a little trial and error:
Download the learningjava-master.zip - use the link at the RHS of the catalogue page then the link on the RHS of the github page.
Next extract the zip file you have just downloaded
Look in learningjava-master\learningjava-master\examples\eclipse-project where there are 2 zip files examples-eclipse-ch2.zip and examples-eclipse-appa.zip
Follow the instructions in Chapter 2, i.e. create your own empty project Learning Java then import the archive into it BUT import examples-eclipse-ch2.zip not learningjava-master.zip
That worked for me.
see the change log
see the change log