Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8508045
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T03:02:46+00:00 2026-06-11T03:02:46+00:00

I have a Java Swing application that embeds Tomcat. The embedded Tomcat is configured

  • 0

I have a Java Swing application that embeds Tomcat. The embedded Tomcat is configured programmatically; no xml. Tomcat is also configured using Groovy Servlets:

StandardWrapper gspWrapper = new StandardWrapper();
gspWrapper.setName("groovy");
gspWrapper.setServletName("groovy");
gspWrapper.setServletClass(GroovyServlet.class.getName());
gspWrapper.addInitParameter("fork", "false");
gspWrapper.setLoadOnStartup(2);

I want Ruby support (jRuby 1.7), too. So I want to configure it same same way as the Groovy support:

StandardWrapper rubyWrapper = new StandardWrapper();
rubyWrapper.setName("rb");
rubyWrapper.setServletName("rb");
rubyWrapper.setServletClass(JRubyServlet.class.getName());
rubyWrapper.addInitParameter("fork", "false");
rubyWrapper.setLoadOnStartup(2);

I tried to write the JRubyServlet class, but I don’t know how to execute a script an write the output into the response. Here’s my current code:

import java.io.IOException;
import java.util.ArrayList;

import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.jruby.Ruby;
import org.jruby.javasupport.JavaEmbedUtils;

public class JRubyServlet extends HttpServlet {

    private static final long serialVersionUID = -6913887886084787803L;
    private Ruby ruby;

  @Override public void init(ServletConfig config) throws ServletException {
      super.init(config);
      ruby = JavaEmbedUtils.initialize(new ArrayList<String> ());
  }

  @Override public void destroy() {
      JavaEmbedUtils.terminate(ruby);
      super.destroy();
  }

  @Override protected void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {
      //How do you execute the script here?
  }

  @Override protected void doPost(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {
      doGet(req, res);
  }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T03:02:47+00:00Added an answer on June 11, 2026 at 3:02 am

    Here is a way of doing this using JavaEmbedUtils as per your example.

    You can first create a servlet written in JRuby (here in src/main/ruby/ruby_servlet.rb), for instance:

    require 'java'
    
    java_import 'javax.servlet.http.HttpServlet'
    
    class RubyServlet < HttpServlet
      def init(config)
        puts "Configuring RubyServlet..."
      end
    
      def service(request, response)
        response.content_type = "text/html"
        out = response.writer
    
        out.println("Hi from JRuby.")
      end
    end
    

    You can then use your JRubyServlet to call this JRuby script:

    public class JRubyServlet extends HttpServlet {
    
        private static final long serialVersionUID = -6913887886084787803L;
        private Ruby ruby;
        private Servlet rubyServlet;
    
      @Override public void init(ServletConfig config) throws ServletException {
          super.init(config);
          // Add location of the script to load path
          ruby = JavaEmbedUtils.initialize(asList("src/main/ruby"));
    
          // Instantiate ruby servlet, and store it into instance variable rubyServlet
          rubyServlet = (Servlet)JavaEmbedUtils.rubyToJava(ruby.evalScriptlet("require 'ruby_servlet'; RubyServlet.new"));
          rubyServlet.init(config);
      }
    
      @Override public void destroy() {
          JavaEmbedUtils.terminate(ruby);
          super.destroy();
      }
    
      @Override protected void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {
    
          // Call JRuby servlet's service method!
          rubyServlet.service(req, res);
      }
    
      @Override protected void doPost(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {
          doGet(req, res);
      }
    

    Have a look also at https://github.com/jruby/jruby/wiki/RedBridge; using JRuby Embed provides ways of controlling concurrency model, etc.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a java application that will run on Windows 7 (using Swing, App
I have implemented an Java Swing application that uses an embedded JavaDB database. The
I have a Java Swing application that is being used as a cluster application.
So I have a strange problem, I have a java swing application that has
I have a Java swing application with a button that produces a popup window
I have a simple Swing Java application that performs searches, and the results are
I've creating a Java Swing application and I realized that I have many many
We have a client side application (Java/Swing) that we need an HTML rendering control
I have a Java Swing application client that I want to use to consume
I have a small Java Swing application that I want to rewrite in WPF

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.