Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where do I put my jetty.xml file with Jetty embedded?

I am just getting started with Jetty (Jetty 6 w/ Java 6). Using the example files with Jetty 6, I place my xml configuration file. in the same directory as my java file. But when I run the project I get this error.

Exception in thread "main" java.lang.NullPointerException at net.test.FileServerXml.main(FileServerXml.java:13

Here is the example code:

`package net.test;


import org.mortbay.jetty.Server;
import org.mortbay.resource.Resource;
import org.mortbay.xml.XmlConfiguration;

public class FileServerXml
{
    public static void main(String[] args) throws Exception
    {
        Resource fileserver_xml = Resource.newSystemResource("fileserver.xml");
        XmlConfiguration configuration = new XmlConfiguration(fileserver_xml.getInputStream());
        Server server = (Server)configuration.configure();
        server.start();
        server.join();

    }
 }

What is the proper way to structure the file system so that my xml file is found?

like image 598
Norm Avatar asked May 21 '10 01:05

Norm


People also ask

Where is Jetty XML located?

jetty. xml is the default configuration file for Jetty, typically located at $JETTY_HOME/etc/jetty.

What is Jetty XML file?

The Jetty XML syntax is a straightforward mapping of XML elements to a Java API so that POJOs can be instantiated and getters, setters and methods called. It is very similar to Inversion Of Control (IOC) or Dependency Injection (DI) frameworks like Spring or Plexus (but it predates all of them).

How do you set a Jetty home window?

JETTY_HOME implies the path where jetty is installed and defined as JETTY_HOME on your environment variables. Too see the varible (path of the directory); based on your OS run echo %JETTY_HOME% for Windows; or echo $JETTY_HOME for Unix on your command line / terminal.


1 Answers

After doing some experimentation and heavy soul searching in the API for I changed:

Resource fileserver_xml = Resource.newSystemResource("fileserver.xml");  

To this

Resource fileserver_xml = Resource.newResource("fileserver.xml");  

Then placed the fileserver.xml outside of the "src" directory, which is the project root. Then it worked.

like image 98
Norm Avatar answered Sep 17 '22 17:09

Norm