embedded-jetty

Serving static files with embedded Jetty

耗尽温柔 提交于 2019-11-27 03:42:38
I'm trying to build a simple demo app with embedded Jetty that serves static files from a "html" directory that's a subdirectory of the current working directory. The idea is that the directory with the demo jar and content can be moved to a new location and still work. I've tried variations of the following, but I keep getting 404s. ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS); context.setContextPath("/"); context.getInitParams().put( "org.eclipse.jetty.servlet.Default.resourceBase", "html"); context.addServlet(new ServletHolder(new DefaultServlet(

How to disable directory listing for Jetty's WebAppContext?

你说的曾经没有我的故事 提交于 2019-11-27 01:06:39
问题 I'm embedding Jetty (version 7.4.5.v20110725) into a java application. I'm serving JSP pages in ./webapps/jsp/ using Jetty's WebAppContext, but if I visit localhost:8080/jsp/ I get Jetty's directory listing for the entire contents of ./webapps/jsp/. I've tried setting the dirAllowed parameter to false on the WebAppContext and it does not change the directory listing behavior. Disabling the directory listing on a ResourceHandler is simply done be passing false to setDirectoriesListed, works as

Jetty: default servlet context path

邮差的信 提交于 2019-11-26 23:26:41
问题 I need to set Servlet (only servlet not handler because of some reasons) to work with files outside war. Here https://stackoverflow.com/a/28735121/5057736 I found the following solution: Server server = new Server(8080); ServletContextHandler ctx = new ServletContextHandler(); ctx.setContextPath("/"); DefaultServlet defaultServlet = new DefaultServlet(); ServletHolder holderPwd = new ServletHolder("default", defaultServlet); holderPwd.setInitParameter("resourceBase", "./src/webapp/"); ctx

create a executable jar using maven and jetty

流过昼夜 提交于 2019-11-26 20:33:39
问题 I want to start my application using jetty, so I have added the dependency mentioned below. and when I run the main method Jetty starts successfully.(I am working on a struts2+spring3+ hibernate maven project, i am able to deploy it in tomcat too) Now I want to create a executable jar from a war packaging pom. So i added maven-assembly-plugin to my pom. (I tried with maven jar plug-in but it was not adding the dependencies) Sources plugins <build> <plugins> <plugin> <artifactId>maven-war

How does OkHttp get Json string?

空扰寡人 提交于 2019-11-26 19:05:45
问题 Solution : It was a mistake on my side. The right way is response.body().string() other than response.body.toString() Im using Jetty servlet, the URL is http://172.16.10.126:8789/test/path/jsonpage , every time request this URL it will return {"employees":[ {"firstName":"John", "lastName":"Doe"}, {"firstName":"Anna", "lastName":"Smith"}, {"firstName":"Peter", "lastName":"Jones"} ]} It shows up when type the url into a browser, unfortunately it shows kind of memory address other than the json

Jersey fails when creating uber jar with maven-assembly-plugin

人盡茶涼 提交于 2019-11-26 18:00:36
I have created a maven jersey starter webapp. Also I have embedded jetty server in my app using jetty plugin. My project is working fine when I run my project using mvn jetty:run command. But when I package my project using mvn clean package command and run the jar file which has name jar-with-dependencies the project throws this exception while returning a json response from a jersey resource. SEVERE: MessageBodyWriter not found for media type=application/json, type=class com.nitish.freecharge.model.Count, genericType=class com.nitish.freecharge.model.Count. Here is my pom.xml file http:/

Serving static files with embedded Jetty

瘦欲@ 提交于 2019-11-26 10:41:00
问题 I\'m trying to build a simple demo app with embedded Jetty that serves static files from a \"html\" directory that\'s a subdirectory of the current working directory. The idea is that the directory with the demo jar and content can be moved to a new location and still work. I\'ve tried variations of the following, but I keep getting 404s. ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS); context.setContextPath(\"/\"); context.getInitParams().put( \"org

Jersey fails when creating uber jar with maven-assembly-plugin

假装没事ソ 提交于 2019-11-26 06:08:37
问题 I have created a maven jersey starter webapp. Also I have embedded jetty server in my app using jetty plugin. My project is working fine when I run my project using mvn jetty:run command. But when I package my project using mvn clean package command and run the jar file which has name jar-with-dependencies the project throws this exception while returning a json response from a jersey resource. SEVERE: MessageBodyWriter not found for media type=application/json, type=class com.nitish

Serving static files from alternate path in embedded Jetty

落爺英雄遲暮 提交于 2019-11-26 02:58:02
问题 I\'m trying to create an embedded jetty server with both a custom servlet that serves some dynamic data, and default servlet that will serve some images. I have the custom servlet working, but I can\'t figure out how to add a default servlet to serve the image files. This is what I have... private void setUpServer(ServerOptions options){ s = new Server(options.getPort()); this.options = options; context = new ServletContextHandler(ServletContextHandler.SESSIONS); context.setContextPath(\"/\")