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?
jetty. xml is the default configuration file for Jetty, typically located at $JETTY_HOME/etc/jetty.
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).
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With