What is a classpath and how do I set it?

When programming in Java, you make other classes available to the class you are writing by putting something like this at the top of your source file: import org.javaguy.coolframework.MyClass; Or sometimes you ‘bulk import’ stuff by saying: import org.javaguy.coolframework.*; So later in your program when you say: MyClass mine = new MyClass(); The Java Virtual … Read more

Problems with setting the classpath in ant

I think the problem is with your classpath path declaration. The build directory should be a <pathelement> <path id=”classpath”> <fileset dir=”${lib}”> <include name=”**/*.jar” /> </fileset> <pathelement location=”${build}” /> </path> Also, I would only include 3-rd party jars in your classpath refid. So the whole block looks like. <path id=”3rd-party-classpath”> <fileset dir=”${lib}”> <include name=”**/*.jar” /> </fileset> </path> <target name=”build”> <javac srcdir=”${src}” destdir=”${build}”> <classpath … Read more

How to really read text file from classpath in Java

With the directory on the classpath, from a class loaded by the same classloader, you should be able to use either of: // From ClassLoader, all paths are “absolute” already – there’s no context // from which they could be relative. Therefore you don’t need a leading slash. InputStream in = this.getClass().getClassLoader() .getResourceAsStream(“SomeTextFile.txt”); // From … Read more