PDA

View Full Version : Java, Junit problem



Spunky Alven
April 12th, 2007, 11:12 AM
Hi trying to get Junit to work on Ubuntu Feisty with no results. I have installed Junit but when i try to compile my test, the package doesn't exist.


package junitfaq;
import org.junit.*;
import static org.junit.Assert.*;
import java.util.*;


Test.java:2: package org.junit does not exist
import org.junit.*;
^
Test.java:3: package org.junit does not exist
import static org.junit.Assert.*;


So how do i get the java compiler to find the junit packages?

smokey edgy
April 13th, 2007, 05:17 AM
How are you compiling this? Do you have the junit.jar included in your classpath?

phossal
April 13th, 2007, 06:08 AM
The easiest way to drop .jar files into your classpath is to stick them in the "extensions" folder within the JRE. You'll need to restart your IDE; restart eclipse if you use it. The folder is something like <path_to_jdk>/jre/bin/ext/

amohanty
April 13th, 2007, 06:14 AM
Another easy way is to:
- download junit binary distribution
- untar in /usr/local
- link to jars in /usr/local/junit.../lib in /usr/share/java

javac should pick it up automatically.
Or else set the CLASSPATH env variable to be a list of colon separated jars. If you need I can post a script I use to do that for me.

HTH
AM

smokey edgy
April 13th, 2007, 05:48 PM
I agree with both of approaches you guys suggested. But I probably wouldn't make it a habit of sticking every jar in those directories as that would mean every project you have would include them in the classpath. JUnit is probably a good exception to this rule, as it probably applies across projects. But certain jars may be more project specific.

amohanty
April 13th, 2007, 06:35 PM
I agree with both of approaches you guys suggested. But I probably wouldn't make it a habit of sticking every jar in those directories as that would mean every project you have would include them in the classpath. JUnit is probably a good exception to this rule, as it probably applies across projects. But certain jars may be more project specific.

Well including everything in the classpath is not necessarily a bad thing. with JIT not all jars/classes will be loaded at app startup. On the plus side, it may make things easier for noobs.

Just my 0.02

AM

phossal
April 13th, 2007, 11:59 PM
I agree with both of approaches you guys suggested. But I probably wouldn't make it a habit of sticking every jar in those directories as that would mean every project you have would include them in the classpath. JUnit is probably a good exception to this rule, as it probably applies across projects. But certain jars may be more project specific.

Many third-party .jar files suggest using the /ext folder. For example, you're not supposed to import while using MySQL's .jar. itext, looks, javamail, etc... They're updated and used often enough that making them separate from your project is often helpful. For the record, I do make it a habit of putting whatever I can in the /ext folder.