views:

1147

answers:

5

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.

A: 

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

Jerrish Varghese
A: 

MyEclipse provides this plugin:

http://www.myeclipseide.com/module-htmlpages-display-pid-11.html

As to whether it will be Spring tag aware is another matter though...

Jon
+1  A: 

You shouldn't have to rebuild at all to see the results.

The latest Enterprise version of eclipse actually does hot code replacement of JSPs. I add the web project to Tomcat (or Glassfish or JBoss...) and any change I make in a JSP is reflected after I refresh my browser window. Obviously, when I change a Java file, I need to restart Tomcat, but that only takes 2 seconds at most.

geowa4
A: 

JBoss Tools (http://jboss.org/tools) has a visual page editor that supports JSP, HTML and even JSF.

If a tag is not supported you can right click it and add a template for it OR you can extend the supported tags by implementing the extension points.

Examples of users extending the set of supported tags are http://relation.to/Bloggers/HowToCreateAVisualDocBookEditorIn10Minutes and http://planetjbpm.wordpress.com/2009/02/25/xforms-editor-with-jboss-vpe-and-some-jbpm/

Max Rydahl Andersen
A: 

There's the Oracle Workshop for WebLogic 10g R3 which gives you the closest thing to WYSIWYG JSP editing. Despite the fact that it comes from Oracle/BEA, it works with many app servers, not just WebLogic. It is the best tool I know for JSPs and it's free. I don't about Spring tags, but it can be customized to give design time representation of tags. I'm not sure if they support Eclipse 3.4 though.

There's also JBoss Developer Studio which has good JSP visual tools.

zvikico