开发者

Any use for a configureless java server?

I love Java. It's great. In fact, I think Java code is just down right sexy! But, there are several things I hate about writing Java web apps:

  1. So many configuration files. I have yet to find a server/container/framework/etc that allows me not to have to create a web.xml. And frameworks only ever add to this complexity.

  2. I love the way PHP works. You drop files 开发者_如何学JAVAinto a directory, and you can immediately browse them. Why can't Java do this? Java has perfectly fine reflection abilities to handle this. So why can't I drop a couple .class files into a directory, and then be able to immediately browse them? (I know tomcat can deploy from a directory, but that leads to....)

  3. And like PHP, why do I have to restart the server every time I want to redeploy an app? (Glassfish can do hot deploys, but I still have to package it into a .war file)

So, my question is: Is there any use, or and existing solution, for a Java server; that allows you to drop simple POJOs into a directory, and be able to immediately browse them? In essence, I want every thing PHP has, just in Java. Any thoughts?


Grails may address some of your needs. It favours convention over configuration (like RoR). I think the hot deploy issue is not as sealess as you'd like, however.

If your major concern is writing web.xmls and similar, you can always embed a web container (say, Jetty) into your application and configure it programatically. But (I suspect) that's probably not how you're thinking.


1 So many configuration files. I have yet to find a server/container/framework/etc that allows me not to have to create a web.xml. And frameworks only ever add to this complexity.

Since the new Java EE 6 annotations there's no need for web.xml anymore. Give it a look. As Java EE 6 is relatively new (released 10 Dec 2009), existing frameworks are yet to be upgraded to comply this.

2 I love the way PHP works. You drop files into a directory, and you can immediately browse them. Why can't Java do this? Java has perfectly fine reflection abilities to handle this. So why can't I drop a couple .class files into a directory, and then be able to immediately browse them? (I know tomcat can deploy from a directory, but that leads to....)

You need to enable hotdeploy/autodeploy of the server in question. You'll need to elaborate more about "but that leads to..." so that it can be fixed.

3 And like PHP, why do I have to restart the server every time I want to redeploy an app? (Glassfish can do hot deploys, but I still have to package it into a .war file)

You need an IDE with a good server plugin. In Eclipse with the Glassfish plugin, I really didn't have any need to restart the server for any hiccup.


From more traditional Java web frameworks Wicket requires the least amount of external configuration. In fact here's the full web.xml content for running Wicket-based web application in deployment mode (taken from here and slightly modified):

<web-app>
    <display-name>Wicket Examples</display-name>
    <filter>
        <filter-name>HelloWorldApplication</filter-name>
        <filter-class>org.apache.wicket.protocol.http.WicketFilter</filter-class>
        <init-param>
          <param-name>applicationClassName</param-name>
          <param-value>org.apache.wicket.examples.helloworld.HelloWorldApplication</param-value>
        </init-param>
        <init-param>
          <param-name>configuration</param-name>
          <param-value>deployment</param-value>
        </init-param>
    </filter>
    <filter-mapping>
        <filter-name>HelloWorldApplication</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>
</web-app>

If you enjoy Spring, you can actually make your Wicket application Spring applicationcontext aware which means your web.xml configuration would then have only the configs for Spring's listener which is just couple of lines.


When you develop inside an IDE in debug mode like Eclipse, just saving the file will recompile it and update the definition inside the JVM (if possible) giving you what you want.

I believe Resin can hot update changes in classes/ but haven't tried lately.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜