Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Eclipse JSP preview

Is there an Eclipse plugin or feature that allows previewing of JSP files? Ideally such a feature would be aware of Spring tags. It's a major pain to edit the JSP in Eclipse, then build and deploy to see the results.

like image 287
Steve Kuo Avatar asked Apr 15 '09 00:04

Steve Kuo


1 Answers

I haven't seen any good plugin which will satisfy your requirement.

As an alternative you can put the jetty server's jar to your class path (I am using jetty-6.1.5.jar and jetty-util-6.1.5.jar) and write a class like the following.

package net.eduportal.jetty;

import javax.servlet.ServletContext;

import org.mortbay.jetty.Server;
import org.mortbay.jetty.security.UserRealm;
import org.mortbay.jetty.webapp.WebAppContext;

public class JettyRunner {
    public static final int PORT = 8080;
    public static final String BASE_URL = "http://localhost:" + PORT;

    private static final JettyRunner _instance = new JettyRunner();

    public static JettyRunner getInstance() {
        return _instance;
    }

    // ///////////////////////////////////////////////////////////////
    // Singleton
    // /////////////

    private Server server = null;
    private WebAppContext wac = null;

    private JettyRunner() {
    }

    public interface WebApplicationInitializer {

        public void init(WebAppContext wac);

    }

    public ServletContext getServletContext() {
        return wac.getServletContext();
    }

    public void start() throws Exception {
        if (server == null) {
            server = new Server(PORT);
            server.setStopAtShutdown(true);
            wac = new WebAppContext();
            wac.setContextPath("/test");
            wac.setResourceBase("war");
            wac.setClassLoader(this.getClass().getClassLoader());
            server.addHandler(wac);
            server.start();
        }
    }

    public void stop() throws Exception {
        if (server != null) {
            server.stop();
            server = null;
        }
    }

    public static void main(String argv[]) throws Exception {
        JettyRunner.getInstance().start();
    }

}

The above code assumes there is a folder called "war" in the class path which contains the same WEB-INF/* folders. When you run the code from eclipse the server will start and you can view the jsps by accessing the location localhost:8080/test/*

See http://jetty.mortbay.org/jetty5/tut/Server.html

like image 146
Jerrish Varghese Avatar answered Sep 28 '22 05:09

Jerrish Varghese