Created
August 28, 2012 20:14
-
-
Save sam/3503635 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package org.harbor; | |
| import java.io.File; | |
| import java.io.IOException; | |
| import java.io.PrintWriter; | |
| import java.util.Arrays; | |
| import java.util.List; | |
| import javax.servlet.ServletException; | |
| import javax.servlet.http.HttpServlet; | |
| import javax.servlet.http.HttpServletRequest; | |
| import javax.servlet.http.HttpServletResponse; | |
| import org.jruby.embed.PathType; | |
| import org.jruby.embed.ScriptingContainer; | |
| import org.jruby.javasupport.JavaEmbedUtils.EvalUnit; | |
| public class HarborServlet extends HttpServlet { | |
| private ScriptingContainer container; | |
| private HttpServlet servlet; | |
| @Override | |
| public void init() { | |
| String classpath = getServletContext().getRealPath("/WEB-INF/classes"); | |
| List<String> loadPaths = Arrays.asList(classpath.split(File.pathSeparator)); | |
| container = new ScriptingContainer(); | |
| container.getProvider().setLoadPaths(loadPaths); | |
| container.runScriptlet("require 'pathname'; p Pathname.pwd"); | |
| container.runScriptlet("require 'src/main/ruby/hello_world'"); | |
| servlet = (HttpServlet) container.runScriptlet("HelloWorld.new"); | |
| } | |
| protected void processRequest(HttpServletRequest request, HttpServletResponse response) | |
| throws ServletException, IOException { | |
| servlet.service(request, response); | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| java_import javax.servlet | |
| java_import javax.servlet.http | |
| class HelloWorld < HttpServlet | |
| def do_get(request, response) | |
| response.writer.println "Hello World!" | |
| end | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| [INFO] Started Jetty Server | |
| #<Pathname:/Users/sam/src/sam/servlet-hello-world> | |
| LoadError: no such file to load -- src/main/ruby/hello_world | |
| require at org/jruby/RubyKernel.java:1024 | |
| require at jar:file:/Users/sam/src/sam/servlet-hello-world/target/servlet-hello-world-1.0/WEB-INF/lib/jruby-complete-1.7.0.preview2.jar!/META-INF/jruby.home/lib/ruby/shared/rubygems/custom_require.rb:36 | |
| (root) at <script>:1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment