I am trying to get my head wrapped around java classpath and .jar files and am trying to put the logic in one class and reference that class from another.
My current directory structure is:
C:\TEMP\StringOps
C:\TEMP\StringOps\StringOperations.java
C:\TEMP\StringOps\StringOperationsDriver.java
I have two classes:
package StringOps;
import java.lang.StringBuilder;
// To compile: javac StringOps/StringOperations.java
public class StringOperations {
private String data;
public StringOperations(String input) {
data = input;
}
public String ReverseString() {
return new StringBuilder(data).reverse().toString();
}
}
and my second class looks like:
package StringOps;
class StringOperationsDriver {
public static void main(String[] args) {
StringOperations sop = new StringOperations("hello world");
System.out.println(sop.ReverseString());
}
}
I can compile the code correctly by:
C:\TEMP>javac StringOps\StringOperationsDriver.java
But when I try to run the code:
C:\TEMP\java -cp . StringOps.StringOperationsDriver
I'm trying to get my head wrapped around this, then to move on to manifest files after I understand this. I've tried looking around at:
Java classpath and package problems - referencing multiple jar files
which is similar to the problem I'm having, but the following command from that url isn't working for me. I also have a .jar file in the same directory C:\TEMP.
Ideally, what I'm looking for is a way to put code in StringOperations.java, compile the code and put it into a jar file. Then access the contents of the .jar file from StringOperationsDriver.java. But since the last url didn't work for me, I figured I would step back and just try this to see if it works.