I've been programming a simple webserver in Java, and though it works in Eclipse, I can't export it to a jar. I'm trying to package some files along with the binaries, and I know that I have to use InputStream to read from within the jar, but every time it seems to work, I access it from chrome and it says: "empty response". That probably means that the jar can't read itself, so I've decided to start over but don't really know how.
Here's the code for the problematic class:
package handlers;
import java.io.*;
import com.sun.net.httpserver.*;
public final class Greeter implements HttpHandler {
package handlers;
import java.io.*;
import com.sun.net.httpserver.*;
public final class Greeter implements HttpHandler {
static Headers h;
static File file;
static byte [] bytes;
static FileInputStream fis;
static BufferedInputStream bis;
static OutputStream os;
public void handle(HttpExchange t) throws IOException {
h = t.getResponseHeaders();
os = t.getResponseBody();
file = new File("GreetingText.html");
fis = new FileInputStream(file);
bis = new BufferedInputStream(fis);
bytes = new byte[(int) file.length()];
h.add("Content-Type", "text/html");
bis.read(bytes, 0, bytes.length);
t.sendResponseHeaders(200, file.length());
os.write(bytes, 0, bytes.length);
os.close();
}
}
this is not a duplicate, since i've already tried the solutions given in other, similar posts. Note that a jar without the resources works perfectly, but with, it doesn't.