Question

I think I'm making a simple mistake, but perhaps you guys can help me out. I have a Jetty webserver. I have deployed a servlet under:

{Jetty-Folder}/webapps/BotServlet/WEB-INF
                                 --------/lib/Server_BotServlet.jar
                                 --------/web.xml

So the servlet inside of Server_BotServlet starts up appropriate and I can access it through the appropriate url. My problem is now the manifest file inside of Server_BotServlet.jar.

Server_BotServlet.jar
----> /META-INF/MANIFEST.MF

The Manifest file is added using an ANT script in eclipse and forms:

Manifest-Version: 1.0
Ant-Version: Apache Ant 1.8.4
Built-Date: 2014-04-01 18:53:54
Built-Version: 2014-04-01 18:53:54

Problem: I am unable to read the manifest file using the following code in the webserver:

    InputStream inputStream = getServletConfig().getServletContext().getResourceAsStream("/META-INF/MANIFEST.MF");
    if(inputStream == null) {System.out.println("Input stream is null1");}
    try {
        Manifest manifest = new Manifest(inputStream);
        Attributes attributes = manifest.getMainAttributes();
        versionString = attributes.getValue("Built-Version");
    }
    catch(Exception e) {
        e.printStackTrace();
        versionString = "N/A";
    }

What happens is the InputStream always ends up equaling null. In another case, I had it print out getServletContext().getContextPath and it shows me "/BotServlet/" as it should. Correct me if I am wrong, but when a jar is loaded at runtime, it gets "run" from the contextpath? Or am I going about deploying these jar's incorrectly as the getResourceAsStream() does not seem to see the jar file appropriately.

I am using the method as described here.

Was it helpful?

Solution

The Servlet context is /BotServlet/ not into the /BotServlet/WEB-INF/lib/Server_BotServlet.jar file. You could put a file you want to read in /WEB-INF/lib/myfile.txt and access that - or you could open the jar (/BotServlet/WEB-INF/lib/Server_BotServlet.jar) and read your MANIFEST. Really it depends on what your ultimate objectives are.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top