0

I've been trying to learn Java on my own and using http://algs4.cs.princeton.edu/code/ as my resource.

Unfortunately, I haven't been able to figure out how to set drjava so that it can properly reference algs4.jar.

So when I tried to compile the following code,

public class TestStdDraw1 {
       public static void main(String[] args) {
           StdDraw.setPenRadius(0.05);
           StdDraw.setPenColor(StdDraw.BLUE);
           StdDraw.point(0.5, 0.5);
           StdDraw.setPenColor(StdDraw.MAGENTA);
           StdDraw.line(0.2, 0.2, 0.8, 0.2);
       }
   }

it doesnt compile.

I know that it's not referencing the jar file because if i just download StdDraw.java in the folder my java script is in, it compiles just fine.

The website above says the following:

Mac OS X (automatic). The Mac OS X installer downloads algs4.jar to the /Users/username/algs4 folder; adds it to the DrJava classpath; and provides the wrapper scripts javac-algs4 and java-algs4, which classpath in algs4.jar, for use in the Terminal.

I did add algs4.jar to the Drjava classpath by clicking on edit->preferences->resource locations -> extra classpath -> then clicking on the algs4.jar file.

(I'm trying to do this on both windows and ubuntu. I have been having the same issue on both.)

I have done echo $PATH on ubuntu to make sure that the path is indeed set to the folder that contains algs4.jar.

I have checked Environmental Variables -> PATH and confirmed that it was set to the folder that contains algs4.jar.

This must be quite trivial, so I apologize in advance

stratofortress
  • 453
  • 1
  • 9
  • 21
  • try adding the jar location to the system environment CLASSPATH (before running your java IDE) – thedrs Feb 29 '16 at 07:27
  • Your question is really about DrJava, and you should thus tag it as such. Unfortunately, despite doing Java development professionally for 18 years, I've never seen anyone, ever, use DrJava. Why don't you use a more "standard" IDE like IntelliJ IDEA or Eclipse? Or even just the command line, the JDK tools and/or a build tool like Gradle? – JB Nizet Feb 29 '16 at 07:28

1 Answers1

0

You can add a jar in Eclipse by right-clicking on the Project → Build Path → Configure Build Path. Under Libraries tab, click Add Jars or Add External JARs and give the Jar.

If you are using command line then you can pass jar in javac:

javac -cp $CLASSPATH:/Users/path/jar1.jar MyClass.java
FallAndLearn
  • 4,035
  • 1
  • 18
  • 24