Ask your own question, for FREE!
Computer Science 8 Online
OpenStudy (javk):

I downloaded a file 'element.jar' from http://www.mhhe.com/javaelements. Now I am supposed to use it in my java project. How can I use it? Where should I put it to begin with?

OpenStudy (e.mccormick):

Well, did you get the library? Because that would be class files... though this was all done against the JDK 1.1, so you might just want the source files so you can complie against the newer JDK.

OpenStudy (e.mccormick):

Oh, and to use a library in general, it needs to be inside the class path and imported. How you will go about that depends on what you are doing to compile things. javac from the command line? An IDE? What?

OpenStudy (e.mccormick):

If you go to the source files, you can add them to your project and then they will be available to compile in as they are needed. The standard import statments work then. Just need to pay attantion to the package lines at the top of the files.

OpenStudy (javk):

Reader beware, you're in for a scare! I understand that you might be compelled to potentially bang you head on the wall a couple of times upon reading this, I reeaally appreciate the help though. I'm so sorry I still don't quite get it... So if I understand correctly, what you are saying is that I need to first import the folder and then set the CLASSPATH, right? I still don't understand the CLASSPATH though, I know that the CLASSPATH will tell the compiler where to look for user defined classes, but what then? Do I have to set the CLASSPATH for each project separately, since they are all in slightly different locations? If so, how? Do I have to go to Control Panel for every one? it just feels wrong to have to enter the administrative password each time. Previously I didn't set the CLASSPATH because I was only doing the really babyish stuff like the "Hello World" program. Now that I am trying to understand the slightly less babyish stuff, I am stuck. It didn't 'seem' to make a difference before, though for all I know, it probably did and I just didn't notice. You mentioned the library in your reply, could you please explain how that ties into any of this. I've been stuck on this problem since over a week now. Yesterday I finally did something that 'seemed' to have worked - but it didn't really. I am using Eclipse, so what I did was, I went to File, went to Import, selected file system and then imported the unzipped folder into my project's source files. At this point I am assuming that the JDK handled the CLASSPATH issue, am I right in doing so? This is the program I am supposed to be running... import element.*; public class One { public static void main(String[] args) { DrawingWindow d = new DrawingWindow(500,500); d.moveTo(100,100); d.lineTo(100,150); } } However, here I'm recieving an error at line 6, the DrawingWindow part; so i went back to the unzipped Element folder and tried to open the DrawingWindow's class file. That gave me a message saying "Source not found", so this must be the part you were saying about needing the source files because it's done against JDK 1.1. @e.mccormick. So what should I do now? Is there any way around this glitch, or do I have find the complete folder? Thank you. Again.

OpenStudy (javk):

I'm so sorry you had to go through all of the above. It's just I'm feeling really lost atm

OpenStudy (kainui):

Since I understand how frustrating this can be, here's a work around that should work for you. In eclipse create a new Java Project and name it whatever you like, probably "JavaElements" is a good choice. Within this there will be a "src" which is your source folder. Inside this create two packages, "element" and "structure" and fill them with new Class and Interface files with identical names from here and copy and paste them all. http://dept.cs.williams.edu/~bailey/JavaElements/source/ You'll have to peek inside to make sure that they're Classes or Interfaces or whatever before you make them and copy them in, otherwise you'll have an error, and there might be a couple things to fiddle around with. Then be sure that you're importing from these packages when you compile and run your code, which in Eclipse has a nice shortcut, Ctrl + F11. I'll be back later today to see if it worked out for you or not. If it's still not working send me a message on Skype and I'll help you figure it out in real time with a more robust solution with shared screens.

OpenStudy (e.mccormick):

You do not need to change the system CLASSPATH. You need to have libraries available inside the class path. There is usually a folder for adding things. "You mentioned the library in your reply, could you please explain how that ties into any of this." This is a library. Any time you use the work of someone else, it is a library of some sort. So you either need to tell Eclipse where the files are, or you need to import the files into the project. It looks like you did the second. The source files were on that web site. https://wiki.eclipse.org/FAQ_How_do_I_add_an_extra_library_to_my_project%27s_classpath%3F http://www.wikihow.com/Add-JARs-to-Project-Build-Paths-in-Eclipse-%28Java%29

OpenStudy (javk):

Thank you so much, I tried Googling it but I didn't quite know what to Google...I guess 'Library' was the key word. So I've been trying to solve this problem all day and what I did previously was I used the option to 'Download the element library for use with JDK 1.1' but now that I finally understand that I am not using JDK 1.1. (Thankyou@e.mccormick) I downloaded and attempted to use the source files directly from the element kit after unzipping it. Well that didn't workout. So I went to 'java elements' extracted the files from 'element-src.zip', took the file named 'source' and renamed it 'element' and imported it into my project, along with the files from the folder 'element', from the 'element library' that i had downloaded earlier on. At this point most of the CLASS files are working but I think the original zip file was missing a few files because I am getting some errors. For instance I can't find 'java.awt' or 'java.awt.event' or 'java.io' I don't know whether I should give up or not. I don't know if I'm doing something wrong, or if it was the authors fault for asking us to use a file that was created over a decade ago, or the uploaders fault for not uploading the complete thing. I don't know...it's probabaly just me, afterall it must have worked all these years, otherwise nobody would refer to it. I'll see if i can attach my project files, so if any of you can take a look and tell me where I'm going wrong I'd really appreciate it. I'm sorry if my mumbo jumbo has become un-understandable (I don't think that's even a word). Its really late and a sign for me to go to bed. Let me know if I caused any confusion and I can attempt to clarify it in the morning

OpenStudy (e.mccormick):

'java.awt' or 'java.awt.event' or 'java.io' <-- Those are part of Java. Use import. For example, here is code taken from: https://docs.oracle.com/javase/tutorial/essential/io/scanning.html ``` import java.io.*; import java.util.Scanner; public class ScanXan { public static void main(String[] args) throws IOException { Scanner s = null; try { s = new Scanner(new BufferedReader(new FileReader("xanadu.txt"))); while (s.hasNext()) { System.out.println(s.next()); } } finally { if (s != null) { s.close(); } } } } ``` See that `import java.io.*;` at the top? That is how you get it to use those. If you still get errors, check to make sure that Eclipse knws where your Java SDK is.

OpenStudy (e.mccormick):

And if I play with what is in your zip... ``` import java.awt.*; import java.io.*; public class one { public static void main(String[] args) { // TODO Auto-generated method stub } } ```

OpenStudy (javk):

Thank you so much ALL of you. All these little details that you guys are sharing, like what a library is, are actually helping a lot. Every morning when I wake up and take a look at my work; I feel a "tad" bit less stupid. And believe me this was not in the book. I would know. I read it cover-to-cover. So now that I've imported the library successfully (I think), I find that some of the CLASS files are riddled with errors and those yellow triangular boxes encapsulating an exclamation mark (I'm sorry I don't know what it's called). Does that mean I'm doing something wrong, or is it just a genuine bug?

OpenStudy (e.mccormick):

Yellow can just be "Not used" As opposed to red, which can be serious.

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!