H
hiwa
To simplify the presentation of the problem, suppose we have the following
directory structure:
current directory ... TestApp.class file
SupportClass subir ... ReadRes.class file
Resources subdir ... Message.txt file
Here are the code:
--TestApp.java--
import java.io.*;
public class TestApp{
public static void main(String[] args) throws IOException{
ReadRes rs = new ReadRes();
System.out.println(rs.getStr());
}
}
--ReadRes.java--
import java.io.*;
public class ReadRes{
public String getStr() throws IOException{
InputStream is = TestApp.class.getResourceAsStream
("/Resources/Message.txt");
BufferedReader br = new BufferedReader(new InputStreamReader(is));
return(br.readLine());
}
}
--Message.txt--
Hello World!
This application runs with an ordinary command line as follows:
(use ; instead of : on Windows)
java -cp .:SupportClass TestApp
Now we have made a jar file with the following command:
jar mvf manifest TestApp.class SupportClass Resources
--manifest--
Manifest-Version: 1.0
Main-Class: TestApp
Class-Path: ?????
Then, the problem is: what should be the correct Class-Path entry in our
manifest file?
If you kindly test these jar-archived files, please beware that there
shoud be no original class/resource files around your testing directories.
And, note that there is no package issue nor multiple jar files issue
involved. Here we only see a plain old directory structure.
Thanks in advance.
directory structure:
current directory ... TestApp.class file
SupportClass subir ... ReadRes.class file
Resources subdir ... Message.txt file
Here are the code:
--TestApp.java--
import java.io.*;
public class TestApp{
public static void main(String[] args) throws IOException{
ReadRes rs = new ReadRes();
System.out.println(rs.getStr());
}
}
--ReadRes.java--
import java.io.*;
public class ReadRes{
public String getStr() throws IOException{
InputStream is = TestApp.class.getResourceAsStream
("/Resources/Message.txt");
BufferedReader br = new BufferedReader(new InputStreamReader(is));
return(br.readLine());
}
}
--Message.txt--
Hello World!
This application runs with an ordinary command line as follows:
(use ; instead of : on Windows)
java -cp .:SupportClass TestApp
Now we have made a jar file with the following command:
jar mvf manifest TestApp.class SupportClass Resources
--manifest--
Manifest-Version: 1.0
Main-Class: TestApp
Class-Path: ?????
Then, the problem is: what should be the correct Class-Path entry in our
manifest file?
If you kindly test these jar-archived files, please beware that there
shoud be no original class/resource files around your testing directories.
And, note that there is no package issue nor multiple jar files issue
involved. Here we only see a plain old directory structure.
Thanks in advance.