>>Hi,
>>
>>In Eclipse, using version 2.1.0, I'm trying to use some
>>utility classes which I have in a folder outside of my
>>Eclipse directory. These classes are not in a jar, they are
>>just .class files. Is there a way that I can get Eclipse to
>>find and use those classes, perhaps reminiscent of the
>>classpath environment variable I am used to setting for the JDK?
>>
>>I keep finding ways that Eclipse offers to copy ("import")
>>the files into the Eclipse project folder. But I want to
>>keep just one copy of these utility classes.Ken Auer wrote:
I'm not exactly sure what you are trying to do per your description, but I'd guess you should make a separate project (call it "MyUtilities") and stick the classes in there. Then your other projects can include this project in its build path (see the properties of the project, and select "Java Build Path"). This will include these classes in your build path.
Thank you, Ken,
I tried this before and I think I had it working once, but not any more. Should have taken more notes.
So just now, trying again, I have a project tryUtility, with a package main, with a class:
package main;
import IntegerFormatter;
public class HelloInt { public static void main(String[] args) {
System.out.println(IntegerFormatter.format(334928,14));
}
}In the properties of tryUtility, Java Build Path, Projects, I have selected the project myUtilities.
In that other project, myUtilities, I have a (default package) which contains one class IntegerFormatter:
public class IntegerFormatter{
/* Can right justify and/or insert commas.
Takes long integers, in spite of its name.
Right justifies i in width. Leading zeros are dropped. Inserts commas
by default, if so constructed. If the input integer is too big to be formatted
into width, then this returns a true representation
longer than width. As a consequence, this can also be used to insert commas
into left justified ints, by giving it too small a width, 1 for instance.
*/
int width;
boolean withCommas;
public IntegerFormatter(int width, boolean withCommas){
if (width <= 0)
throw new IllegalArgumentException("specified width must be greater than 0");
this.width = width;
this.withCommas = withCommas;
}
public IntegerFormatter(int width){
this(width, true);
}
public static String format(long me, int inWidth){
IntegerFormatter iffy = new IntegerFormatter(inWidth);
return iffy.rightJustify(me);
} public String rightJustify(long i){
StringBuffer workingBuff = new StringBuffer();
workingBuff.append(i);
int rawIntLength = workingBuff.length();
if (rawIntLength > 3 && withCommas)
{ /* The first character of workingBuff might be a '-', so we allow
for that with firstDigitIndex. */
int firstDigitIndex = (i < 0) ? 1 : 0 ;
for(int commaInsertPoint = rawIntLength - 3;
commaInsertPoint > firstDigitIndex;
commaInsertPoint -= 3)
workingBuff.insert(commaInsertPoint, ',');
}
while (workingBuff.length() < width)
workingBuff.insert(0, ' ');
return workingBuff.toString();
}}
In the Java Build Path of this myUtilities project I specify the first project, tryUtility, not necessarily because it makes sense but because I have already exhausted all options which make sense to me, and now I am trying others.
Both of these two classes, in their two respective projects, compile up without complaint. Indeed, if I remove the line:
import IntegerFormatter;
from HelloInt.java, then of course it seems unhappy about IntegerFormatter being unresolvable, till I Organize Imports, in which case it reinserts the line (above deleted), and again it appears happy and ready to go.
But when I run HelloInt as Java Application the console produces:
java.lang.Error: Unresolved compilation problem:
IntegerFormatter cannot be resolvedat sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
at java.lang.reflect.Constructor.newInstance(Constructor.java:274)
at main.HelloInt.main(HelloInt.java:6)
Exception in thread "main"
Does that make any sense? Rich
_______________________________________________ Juglist mailing list [EMAIL PROTECTED] http://trijug.org/mailman/listinfo/juglist_trijug.org
