Can you assign per web app jetty-rewrite.xml files in Jetty? - jetty

Is there a way per web app / context to specify a rewrite file just for that particular webapp? The only way I see this currently working is via the command line when you start it. I was thinking perhaps a setting in the override.xml file or even in the context xml file.

If you use context.xml deployables you can integrate the RewriteHandler rules into the app specific context xml.
Example: this is a replacement context.xml of the ${jetty.home}/contexts/test.xml found in the jetty-distribution. It adds a rule that simply adds a cookie (visited=yes) on the response for all requests.
<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" "http://www.eclipse.org/jetty/configure.dtd">
<Configure class="org.eclipse.jetty.server.handler.ContextHandler">
<Set name="contextPath">/</Set>
<Set name="handler">
<New id="Rewrite" class="org.eclipse.jetty.rewrite.handler.RewriteHandler">
<Set name="handler">
<New class="org.eclipse.jetty.webapp.WebAppContext">
<Set name="contextPath">/</Set>
<Set name="war"><SystemProperty name="jetty.home" default="."/>/webapps/test.war</Set>
<Set name="extractWAR">true</Set>
<Set name="copyWebDir">false</Set>
<Set name="defaultsDescriptor"><SystemProperty name="jetty.home" default="."/>/etc/webdefault.xml</Set>
<Set name="overrideDescriptor"><SystemProperty name="jetty.home" default="."/>/contexts/test.d/override-web.xml</Set>
</New>
</Set>
<Set name="rewriteRequestURI">true</Set>
<Set name="rewritePathInfo">false</Set>
<Set name="originalPathAttribute">requestedPath</Set>
<!-- add a cookie to each path visited -->
<Call name="addRule">
<Arg>
<New class="org.eclipse.jetty.rewrite.handler.CookiePatternRule">
<Set name="pattern">/*</Set>
<Set name="name">visited</Set>
<Set name="value">yes</Set>
</New>
</Arg>
</Call>
</New>
</Set>
</Configure>
To verify that this rule works, start jetty, goto http://localhost:8080/ and then use the "Sessions" test component, you'll see that visited=true will be visible as a cookie at the top.

Related

Serving large-size static files with Jetty

I have a Jetty server, which I want to use to server a large-size static files.
I have edited "jetty.xml" adding the following:
<Set name="handler">
<New id="Handlers" class="org.eclipse.jetty.server.handler.HandlerCollection">
<Set name="handlers">
<Array type="org.eclipse.jetty.server.Handler">
<Item>
<New id="Contexts" class="org.eclipse.jetty.server.handler.ContextHandlerCollection">
<Set name="handlers">
<Array type="org.eclipse.jetty.server.handler.ContextHandler">
<Item>
<New class="org.eclipse.jetty.server.handler.ContextHandler">
<Set name="contextPath">/files</Set>
<Set name="handler">
<New class="org.eclipse.jetty.server.handler.ResourceHandler">
<Set name="directoriesListed">false</Set>
<Set name="resourceBase">/path/to/my/files</Set>
</New>
</Set>
</New>
</Item>
</Array>
</Set>
</New>
</Item>
<Item>
<New id="DefaultHandler" class="org.eclipse.jetty.server.handler.DefaultHandler"/>
</Item>
</Array>
</Set>
</New>
</Set>
It works pretty fine with small files, but with large files the download is too slow and in many times doesn't complete. I'm using Jetty version 9.2.13, and a web browser as the client.
According to "Do not use ResourceHandler to serve static files, use DefaultServlet":
https://github.com/perwendel/spark/issues/316
I want to use DefaultServlet in my xml instead of ResourceHandler, but I don't know how?
Any help?

How to start OSGi bundle in different port in karaf with jetty

I have multiple OSGi bundles and would like to expose those bundles from different port. Basically bundles has REST API and I would like to run API's in different ports.
My REST API bundle jars is having jaxrs:server configuration.
<jaxrs:server id="services" address="/logger">
</jaxrs:server>
I can start the multiple connectors with configuration provided below.
<Call name="addConnector">
<Arg>
<New class="org.eclipse.jetty.server.nio.SelectChannelConnector">
<Set name="host">
<Property name="jetty.host" />
</Set>
<Set name="port">
<Property name="jetty.port" default="8282" />
</Set>
<Set name="maxIdleTime">300000</Set>
<Set name="Acceptors">2</Set>
<Set name="statsOn">false</Set>
<Set name="confidentialPort">8443</Set>
<Set name="lowResourcesConnections">20000</Set>
<Set name="lowResourcesMaxIdleTime">5000</Set>
<Set name="name">jettyConn2</Set>
</New>
</Arg>
</Call>
Yes, as long as your jaxrs is served by different servlets, which are configured in different web application bundles (WABs).
You need to make sure all of your application bundles contain the required Headers:
WebContext-Path: /logger
Web-Connectors: jettyConn2
Unless your jaxrs framework has a central servlet that registers with its own WebContext-Path this should work for you.

Serve files from folder outside web application in Jetty

I have a Java web application (Eclipse/OSGI) on a Jetty server. I want to be able to serve static files to my web application from a folder outside of the web root. In my web application, I don't yet know the file name of the file I want to be served, so I want to take the filename (and/or path) as a VM parameter when I start my web application. For example:
I have an image - myImg.jpg - that I have put in a folder on the server file system, for example root/images/myImg.jpg. I want to take this as a VM parameter, e.g. "-DmyImg=/images/myImg.jpg/" so that I can get the image and display it on my web page. How can I accomplish this? Can I do this without creating a new Servlet?
Thanks in advance for any help!
Solved it!
This is what I added to my jetty.xml file:
<Set name="handler">
<New id="Handlers" class="org.eclipse.jetty.server.handler.HandlerCollection">
<Set name="handlers">
<Array type="org.eclipse.jetty.server.Handler">
<Item>
<New class="org.eclipse.jetty.server.handler.ContextHandler">
<Set name="contextPath">/myContextPath</Set>
<Set name="handler">
<New class="org.eclipse.jetty.server.handler.ResourceHandler">
<Set name="directoriesListed">false</Set>
<Set name="resourceBase">/actual/folder/on/file/system</Set>
</New>
</Set>
</New>
</Item>
[...other handlers...]
</Array>
</Set>
</New>
</Set>
#Farna: In your answer I am not able to understand how you are passing the file name as VM parameter. This is what I did.
I created testparvez.xml file in jetty webapps directory.
<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE Configure PUBLIC "-//Mort Bay Consulting//DTD Configure//EN" "http://jetty.eclipse.org/configure.dtd">
<Configure class="org.eclipse.jetty.server.handler.ContextHandler">
<Set name="contextPath">/testparvez</Set>
<Set name="resourceBase"><SystemProperty name="mydir"/></Set>
<Set name="handler">
<New class="org.eclipse.jetty.server.handler.ResourceHandler">
<Set name="welcomeFiles">
<Array type="String">
<Item><SystemProperty name="myfile"/></Item>
</Array>
</Set>
<Set name="cacheControl">max-age=3600,public</Set>
</New>
</Set>
</Configure>
Then I start jetty as
java -jar start.jar jetty.port=8082 -Dmydir=C:/test/javadoc/ -Dmyfile=index.html
And finally I access from url http://localhost:8082/testparvez/

My Jetty server will dead after a long time, why?

Recently, I host a website in Amazon EC2, and I use Jetty 7.4 as my server.
I test it in my machine and EC2, and it works properly.
But after a few weeks, it suddenly can't be accessed. Checking the log, it just said "/WEB-INF/view/index.jsp" not found. And then the whole site can't be used any more until restarting the Jetty server.
BTW: in my project I used Spring Framework, Spring MVC, Ehcache, Shiro, Hibernate, Google Web Toolkit, etc.
Why?
I almost use the default configuration file for Jetty:
Jetty configuration file:
<!-- =========================================================== -->
<!-- Server Thread Pool -->
<!-- =========================================================== -->
<Set name="ThreadPool">
<!-- Default queued blocking threadpool -->
<New class="org.eclipse.jetty.util.thread.QueuedThreadPool">
<Set name="minThreads">10</Set>
<Set name="maxThreads">200</Set>
<Set name="detailedDump">false</Set>
</New>
</Set>
<!-- =========================================================== -->
<!-- Set connectors -->
<!-- =========================================================== -->
<Call name="addConnector">
<Arg>
<New class="org.eclipse.jetty.server.nio.SelectChannelConnector">
<Set name="host"><Property name="jetty.host" /></Set>
<Set name="port"><Property name="jetty.port" default="8080"/></Set>
<Set name="maxIdleTime">300000</Set>
<Set name="Acceptors">2</Set>
<Set name="statsOn">false</Set>
<Set name="confidentialPort">8443</Set>
<Set name="lowResourcesConnections">20000</Set>
<Set name="lowResourcesMaxIdleTime">5000</Set>
</New>
</Arg>
</Call>
<!-- =========================================================== -->
<!-- Set handler Collection Structure -->
<!-- =========================================================== -->
<Set name="handler">
<New id="Handlers" class="org.eclipse.jetty.server.handler.HandlerCollection">
<Set name="handlers">
<Array type="org.eclipse.jetty.server.Handler">
<Item>
<New id="Contexts" class="org.eclipse.jetty.server.handler.ContextHandlerCollection"/>
</Item>
<Item>
<New id="DefaultHandler" class="org.eclipse.jetty.server.handler.DefaultHandler"/>
</Item>
</Array>
</Set>
</New>
</Set>
<New id="ServerLog" class="java.io.PrintStream">
<Arg>
<New class="org.eclipse.jetty.util.RolloverFileOutputStream">
<Arg><Property name="jetty.logs" default="./logs"/>/yyyy_mm_dd.stderrout.log</Arg>
<Arg type="boolean">false</Arg>
<Arg type="int">90</Arg>
<Arg><Call class="java.util.TimeZone" name="getTimeZone"><Arg>GMT</Arg></Call></Arg>
<Get id="ServerLogName" name="datedFilename"/>
</New>
</Arg>
</New>
<Call class="org.eclipse.jetty.util.log.Log" name="info"><Arg>Redirecting stderr/stdout to <Ref id="ServerLogName"/></Arg></Call>
<Call class="java.lang.System" name="setErr"><Arg><Ref id="ServerLog"/></Arg></Call>
<Call class="java.lang.System" name="setOut"><Arg><Ref id="ServerLog"/></Arg></Call>
<!-- =========================================================== -->
<!-- extra options -->
<!-- =========================================================== -->
<Set name="stopAtShutdown">true</Set>
<Set name="sendServerVersion">true</Set>
<Set name="sendDateHeader">true</Set>
<Set name="gracefulShutdown">1000</Set>
<Set name="dumpAfterStart">false</Set>
<Set name="dumpBeforeStop">false</Set>
Error details:
org.apache.jasper.JasperException: PWC6117: File "/WEB-INF/view/index.jsp" not found
at org.apache.jasper.compiler.DefaultErrorHandler.jspError(DefaultErrorHandler.java:89)
at org.apache.jasper.compiler.ErrorDispatcher.dispatch(ErrorDispatcher.java:375)
at org.apache.jasper.compiler.ErrorDispatcher.jspError(ErrorDispatcher.java:169)
at org.apache.jasper.compiler.JspUtil.getInputStream(JspUtil.java:910)
at org.apache.jasper.xmlparser.XMLEncodingDetector.getEncoding(XMLEncodingDetector.java:143)
at org.apache.jasper.compiler.ParserController.determineSyntaxAndEncoding(ParserController.java:376)
at org.apache.jasper.compiler.ParserController.doParse(ParserController.java:210)
at org.apache.jasper.compiler.ParserController.parse(ParserController.java:140)
at org.apache.jasper.compiler.Compiler.generateJava(Compiler.java:199)
at org.apache.jasper.compiler.Compiler.compile(Compiler.java:435)
at org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:608)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:360)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:486)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:380)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:820)
at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:538)
at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:478)
at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:119)
at org.eclipse.jetty.security.SecurityHandler.handle(SecurityHandler.java:517)
at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:225)
at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:937)
at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:406)
at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:183)
at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:871)
at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:117)
at org.eclipse.jetty.server.Dispatcher.forward(Dispatcher.java:284)
at org.eclipse.jetty.server.Dispatcher.forward(Dispatcher.java:115)
at org.springframework.web.servlet.view.InternalResourceView.renderMergedOutputModel(InternalResourceView.java:238)
at org.springframework.web.servlet.view.AbstractView.render(AbstractView.java:250)
at org.springframework.web.servlet.DispatcherServlet.render(DispatcherServlet.java:1047)
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:817)
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:719)
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:644)
at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:549)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:707)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:820)
at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:538)
at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1352)
at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:88)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)
at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1323)
at org.springframework.orm.hibernate3.support.OpenSessionInViewFilter.doFilterInternal(OpenSessionInViewFilter.java:198)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)
at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1323)
at org.apache.shiro.web.servlet.AbstractShiroFilter.executeChain(AbstractShiroFilter.java:359)
at org.apache.shiro.web.servlet.AbstractShiroFilter$1.call(AbstractShiroFilter.java:275)
at org.apache.shiro.subject.support.SubjectCallable.doCall(SubjectCallable.java:90)
at org.apache.shiro.subject.support.SubjectCallable.call(SubjectCallable.java:83)
at org.apache.shiro.subject.support.DelegatingSubject.execute(DelegatingSubject.java:344)
at org.apache.shiro.web.servlet.AbstractShiroFilter.doFilterInternal(AbstractShiroFilter.java:272)
at org.apache.shiro.web.servlet.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:81)
at org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:237)
at org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:167)
at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1323)
at org.apache.shiro.web.servlet.AbstractShiroFilter.executeChain(AbstractShiroFilter.java:359)
at org.apache.shiro.web.servlet.AbstractShiroFilter$1.call(AbstractShiroFilter.java:275)
at org.apache.shiro.subject.support.SubjectCallable.doCall(SubjectCallable.java:90)
at org.apache.shiro.subject.support.SubjectCallable.call(SubjectCallable.java:83)
at org.apache.shiro.subject.support.DelegatingSubject.execute(DelegatingSubject.java:344)
at org.apache.shiro.web.servlet.AbstractShiroFilter.doFilterInternal(AbstractShiroFilter.java:272)
at org.apache.shiro.web.servlet.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:81)
at org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:237)
at org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:167)
at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1323)
at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:476)
at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:119)
at org.eclipse.jetty.security.SecurityHandler.handle(SecurityHandler.java:480)
at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:225)
at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:937)
at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:406)
at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:183)
at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:871)
at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:117)
at org.eclipse.jetty.server.handler.ContextHandlerCollection.handle(ContextHandlerCollection.java:247)
at org.eclipse.jetty.server.handler.HandlerCollection.handle(HandlerCollection.java:149)
at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:110)
at org.eclipse.jetty.server.Server.handle(Server.java:346)
at org.eclipse.jetty.server.HttpConnection.handleRequest(HttpConnection.java:589)
at org.eclipse.jetty.server.HttpConnection$RequestHandler.headerComplete(HttpConnection.java:1048)
at org.eclipse.jetty.http.HttpParser.parseNext(HttpParser.java:601)
at org.eclipse.jetty.http.HttpParser.parseAvailable(HttpParser.java:214)
at org.eclipse.jetty.server.HttpConnection.handle(HttpConnection.java:411)
at org.eclipse.jetty.io.nio.SelectChannelEndPoint.handle(SelectChannelEndPoint.java:535)
at org.eclipse.jetty.io.nio.SelectChannelEndPoint$1.run(SelectChannelEndPoint.java:40)
at org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:529)
at java.lang.Thread.run(Thread.java:636)
Run
bin/jetty.sh check
You may find
-Djava.io.tmpdir=/tmp
Change it to some other folder since the OS will delete files in /tmp after a period of time.
Why is your index.jsp in WEB-INF? That folder is made for classes, JAR files, web server files, etc. Your JSP page should just not be there at all.
See JSP do not work in Embedded Jetty.
Review you web.xml and other configuration files.

How to configure JNDI for Jetty 7.0pre5

I am getting this error when starting up Jetty that uses Mysql Connection Pool. Could someone help me out please?
[root#localhost test]# java -DOPTIONS=plus,ext.default -classpath %CLASSPATH% -jar /usr/src/jetty7/start.jar myjetty.xml
2008-12-20 18:24:08.138::INFO: Logging to STDERR via org.mortbay.log.StdErrLog
2008-12-20 18:24:08.307::WARN: Config error at <New id="dev" class="org.mortbay.jetty.plus.naming.Resource"><Arg>jdbc/mysql</Arg><Arg>
<New class="com.mysql.jdbc.jdbc2.optional.MysqlConnectionPoolDataSource"><Set name="User">root</Set><Set name="URL">jdbc:mysql://192.168.1.105/app</Set><Set name="Password">sqlpass</Set></New>
</Arg></New>
2008-12-20 18:24:08.307::WARN: EXCEPTION
java.lang.reflect.InvocationTargetException
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
at org.mortbay.xml.XmlConfiguration.newObj(XmlConfiguration.java:608)
at org.mortbay.xml.XmlConfiguration.configure(XmlConfiguration.java:256)
at org.mortbay.xml.XmlConfiguration.configure(XmlConfiguration.java:214)
at org.mortbay.xml.XmlConfiguration.main(XmlConfiguration.java:974)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.mortbay.start.Main.invokeMain(Main.java:218)
at org.mortbay.start.Main.start(Main.java:564)
at org.mortbay.start.Main.main(Main.java:136)
Caused by: javax.naming.NoInitialContextException: Need to specify class name in environment or system property, or as an applet parameter, or in an application resource file: java.naming.factory.initial
at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:645)
at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:288)
at javax.naming.InitialContext.getURLOrDefaultInitCtx(InitialContext.java:325)
at javax.naming.InitialContext.getNameParser(InitialContext.java:480)
at org.mortbay.jetty.plus.naming.NamingEntry.save(NamingEntry.java:182)
at org.mortbay.jetty.plus.naming.NamingEntry.<init>(NamingEntry.java:58)
at org.mortbay.jetty.plus.naming.NamingEntry.<init>(NamingEntry.java:76)
at org.mortbay.jetty.plus.naming.Resource.<init>(Resource.java:44)
... 15 more
2008-12-20 18:24:08.308::WARN: Nested in java.lang.reflect.InvocationTargetException:
javax.naming.NoInitialContextException: Need to specify class name in environment or system property, or as an applet parameter, or in an application resource file: java.naming.factory.initial
at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:645)
at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:288)
at javax.naming.InitialContext.getURLOrDefaultInitCtx(InitialContext.java:325)
at javax.naming.InitialContext.getNameParser(InitialContext.java:480)
at org.mortbay.jetty.plus.naming.NamingEntry.save(NamingEntry.java:182)
at org.mortbay.jetty.plus.naming.NamingEntry.<init>(NamingEntry.java:58)
at org.mortbay.jetty.plus.naming.NamingEntry.<init>(NamingEntry.java:76)
at org.mortbay.jetty.plus.naming.Resource.<init>(Resource.java:44)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
at org.mortbay.xml.XmlConfiguration.newObj(XmlConfiguration.java:608)
at org.mortbay.xml.XmlConfiguration.configure(XmlConfiguration.java:256)
at org.mortbay.xml.XmlConfiguration.configure(XmlConfiguration.java:214)
at org.mortbay.xml.XmlConfiguration.main(XmlConfiguration.java:974)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.mortbay.start.Main.invokeMain(Main.java:218)
at org.mortbay.start.Main.start(Main.java:564)
at org.mortbay.start.Main.main(Main.java:136)
[root#localhost test]#
Here is my Jetty.xml
<?xml version="1.0"?>
<!DOCTYPE Configure PUBLIC "-//Mort Bay Consulting//DTD Configure//EN"
"http://jetty.mortbay.org/configure.dtd">
<Configure id="Server" class="org.mortbay.jetty.Server">
<Call name="addConnector">
<Arg>
<New class="org.mortbay.jetty.nio.SelectChannelConnector">
<!-- the ip address or domain to bind -->
<Set name="host"><SystemProperty name="jetty.host" /></Set>
<!-- the port to use/bind, defaults to 8080 if property not set -->
<Set name="port"><SystemProperty name="jetty.port" default="8090"/></Set>
<!-- the time in milliseconds when a connection is considered idle -->
<Set name="maxIdleTime">300000</Set>
<!-- the number of acceptors (their job is to accept the connection and dispatch to thread pool) -->
<Set name="Acceptors">2</Set>
<!-- should the connection statistics be turned on? (Not advisable in production) -->
<Set name="statsOn">false</Set>
<!-- the confidential port -->
<Set name="confidentialPort">8443</Set>
<!-- indicates the minimum number of connections when the server is considered low on resources -->
<Set name="lowResourcesConnections">20000</Set>
<!-- when low on resources, this indicates the maximum time (milliseconds) a connection must be idle to not be closed -->
<Set name="lowResourcesMaxIdleTime">5000</Set>
</New>
</Arg>
</Call>
<Set name="handler">
<New id="Handlers" class="org.mortbay.jetty.handler.HandlerCollection">
<Set name="handlers">
<Array type="org.mortbay.jetty.Handler">
<Item>
<New id="Contexts" class="org.mortbay.jetty.handler.ContextHandlerCollection"/>
</Item>
<Item>
<New id="DefaultHandler" class="org.mortbay.jetty.handler.DefaultHandler"/>
</Item>
<Item>
<New id="RequestLog" class="org.mortbay.jetty.handler.RequestLogHandler"/>
</Item>
</Array>
</Set>
</New>
</Set>
<Array id="plusConfig" type="java.lang.String">
<Item>org.mortbay.jetty.webapp.WebInfConfiguration</Item>
<Item>org.mortbay.jetty.plus.webapp.EnvConfiguration</Item>
<Item>org.mortbay.jetty.plus.webapp.Configuration</Item>
<Item>org.mortbay.jetty.webapp.JettyWebXmlConfiguration</Item>
<Item>org.mortbay.jetty.webapp.TagLibConfiguration</Item>
</Array>
<New id="dev" class="org.mortbay.jetty.plus.naming.Resource">
<Arg>jdbc/mysql</Arg>
<Arg>
<New class="com.mysql.jdbc.jdbc2.optional.MysqlConnectionPoolDataSource">
<Set name="User">root</Set>
<Set name="URL">jdbc:mysql://192.168.1.105/app</Set>
<Set name="Password">sqlpass</Set>
</New>
</Arg>
</New>
<Call name="addLifeCycle">
<Arg>
<New class="org.mortbay.jetty.deployer.WebAppDeployer">
<Set name="ConfigurationClasses"><Ref id="plusConfig"/></Set>
<Set name="contexts"><Ref id="Contexts"/></Set>
<Set name="configurationDir"><SystemProperty name="jetty.home" default="/root/test"/>/contexts</Set>
<Set name="scanInterval">5</Set>
</New>
</Arg>
</Call>
<Ref id="RequestLog">
<Set name="requestLog">
<New id="RequestLogImpl" class="org.mortbay.jetty.NCSARequestLog">
<Set name="filename"><SystemProperty name="jetty.logs" default="./logs"/>/yyyy_mm_dd.request.log</Set>
<Set name="filenameDateFormat">yyyy_MM_dd</Set>
<Set name="retainDays">90</Set>
<Set name="append">true</Set>
<Set name="extended">true</Set>
<Set name="logCookies">false</Set>
<Set name="LogTimeZone">GMT</Set>
</New>
</Set>
</Ref>
</Configure>
Ensure that the jetty-plus.jar file is on your classpath, and also that the configuration file etc/jetty-plus.xml is included on the command line:
java -DOPTIONS=plus,ext.default -classpath %CLASSPATH% -jar /usr/src/jetty7/start.jar /path/to/etc/jetty-plus.xml myjetty.xml
OPTIONS should be set in start.ini:
OPTIONS=Server,jsp,jmx,resources,websocket,ext,plus
Then InitialContext is available.