Reputation: 11236
I have the following directory structure.
src|
|pack|
|Test.java
data|
|data.txt
classes|
|pack|
|Test.class
manifest.txt
It compiled and ran fine.
\project>javac -d classes src\pack\Test.java
\project>java -cp classes pack.Test
Contents of Test.java
package pack;
import java.io.*;
class Test {
public static void main(String[] args) {
String line = null;
BufferedReader br = null;
try {
br = new BufferedReader(new FileReader("data\\data.txt"));
while((line=br.readLine())!=null) {
System.out.println(line);
}
br.close();
}catch(IOException e){System.out.println("FileNotFound");}
}
}
Contents of manifest.txt
Main-Class: pack.Test
How to create the jar file? and from where should I execute it?
Upvotes: 0
Views: 102
Reputation: 32391
If you want to manually create a jar then take a look at the jar command. Something like this, in your case:
jar -cvfm name.jar manifest.txt -C classes .
However, please note that the name of the manifest file should be MANIFEST.MF.
Also, I suggest you start learning a build tool like ant or maven or gradle such as you can do this automatically.
Upvotes: 1