Everything I download seems hellbent on using all of Java EE. I need to build a single page to handle requests to it and do a tiny bit of processing based on parameters. This is to hook into another framework that will routinely call this URL.
I want a quick and easy way to create a page with some processing. Is there an easy way to do this using Java? I am using Java because I am comfortable with Java. I used SE for years and did some work in EE but I don't want all the stuff that comes with EE.
Should I maybe just avoid Java altogether and use something else. This needs to be deployed in a linux environment.
I used SE for years and did some work in EE but I don't want all the stuff that comes with EE.
Then just use a Servlet and that's all. Nothing, I repeat NOTHING, forces you to use "all that stuff" and your question is either a free rant or shows some deep misunderstanding.
You need Tomcat (or jetty, or any servlet container - jetty has an embeddable version btw)
You need a .jsp file and optionally an HttpServlet
Generally, it's not a good practice to put any processing code in a JSP, but if it is really simple and won't be extended, simply put the logic there - it is translated to a Servlet anyway.
yes, all the servlet based solutions are quite chubby.
jetty is all right, but the download is 20MB. that is ridiculous.
currently, the best choice is probably com.sun.net.httpserver which is bundled in JDK 6. you can easily implement your service.
It sounds like you could use PHP to do your processing. Call the page and POST the parameters to it, compute, and return the result.
If you are not very particular about using java and are willing to experiment, you should look at nodejs. It runs on V8 javascript engine and runs on linux.
There are a couple of fraemworks for nodejs for web apps:
Expressjs and spludo
as mentioned, you can do this very simply with jetty and a servlet, you don't even need a JSP if you just need a URL that does some processing based on request parameters and returns a response.
For development, it's really easy to create a dynamic web project in eclipse, just follow the steps in this article.
That said, I don't think java is a great choice for really lightweight stuff. PHP is probably the easiest thing to use if you just want to get it working yesterday.
You can use Java with FastCGI. This is very flexible, but also a bit low-level for most Java programmers.
If you aren't afraid of servlets (they are only a very small part of Java EE!), I can recommend JAX-RS, it is quite easy to get started with. If you client-side is JavaScript based, you can avoid using JSP (which I would recommend you to avoid).
For example, see backbone-jax-cellar. The Java source is here. For a Java app, this is light-weight. He is rolling his own DAO, but that's the price you pay for using Java and SQL and no dependencies (other than JDBC). The code is reminiscent of object-oriented PHP if you ask me. The point is, that if you have a JavaScript client, you don't need template rendering or all that cruft and a REST interface should be enough.
If you are afraid of the heavy build systems too, I made an example REST Todo app backend (which uses an existing frontend) that only requires a POSIX system, the JDK and sqlite3, and gets its own other dependencies (including webserver). I did not use a DAO. The repository front page has a README.
Another possibility is the Play Framework which does not use Java EE. It is rather heavy-weight, though. Full featured though. You would definitely need to use an IDE for this, you don't need that for developing JAX-RS/FastCGI apps.
I would reccomend Sinatra it is a very light-weight ruby web framework.
Related
I have an enterprise Java web application deployed in tomcat.
I am looking for ways to integrate a HTML & JS UI with the mid tier java code. So far, from looking around I have read that there are two ways to do this which fit my requirements :
1) DWR - Direct web remoting
2) Use REST web services.
I am not sure which approach to use.
Edit: What is the advantage of using DWR over a rest WS design?
Is there a better approach available? Some people asked me to have a look at GWT, but I am not sure if these are scalable.
Edit 2: I will most likely be using dojo for the UI development(Works well with REST/DWR??), and I want to keep the java code chages minimal. I understand that by using web services, I would have to write an additional WS client layer on top of the existing java code.
Also, the usual enterprise needs, performance, scalability, etc.
Ok so you're building a web client frontend to your java backend, there are a few ways to go about this:
You want to use java standards as much as possible, preferably living in the java EE world: JSF. You will need some knowledge of HTML, XML and perhaps even javascript (though limited). Personally I have had a pretty buggy experience with JSF+richfaces to the extent that I don't use it anymore.
You are very well acquainted with java desktop application development but don't know much about javascript: vaadin: it allows you to write plain java using desktop application terminology which will be compiled to javascript. Currently I am working on a big vaadin project and it is very nice to be working with pure java in eclipse, the downside is however that you are far removed from the actual frontend, so tweaking can be tricky. Additionally everything is stored in sessions (afaik) and scales poorly.
You are primarily a frontend person with unrivaled javascript skills: use a REST interface in java and a pure js/html/css frontend. Personally I think this is the cleanest design and I have designed a few of my own applications like this. The downside is that managing large javascript projects tends to be hard because...well...javascript sucks. The upside is that this will always be the fastest most lightweight option available to you.
Ideologically I would definitely suggest the last approach but this can be hard for large projects. If you have the hardware to throw at it, vaadin is a nice option. My JSF 2 experience was a bit disappointing due to the bugs in (necessary) third party libraries like richfaces.
PS: I have never heard of DWR but the last stable release seems 2 years old and all it seems to do is expose java code as javascript methods which can be better handled with a REST interface.
Open interface standards like REST and SOAP make it easy to build code to consume these services if you are using frameworks to build a REST Client and a SOAP client code respectively. But the point is that you need to have this client code to make calls to these services.
DWR on the other hand, generates this client code. Your java classes are ready to be called (like you would do in Java).
The circumstances force me to start writing a java based server and I am looking for a REST framework for Java. I really like the way OpenRasta works - a REST framework for .NET, so my question - does anyone know a REST framework for Java which works similarly to OpenRasta?
Thanks.
EDIT
Unfortunately, I am not in a position to be an early adaptor, so well established frameworks have preference over emerging ones.
You want to use one of the implementations of the JAX-RS specification, one of the main ones being Jersey. The specification and it's implementations have been around for a long time and are tried and tested (as opposed to Play! which you don't seem to like due to it being a newer framework).
I used OpenRasta and then worked on Java projects using JAX-RS. It will feel very familiar and you will get the benefits of POJOs like you get from OpenRasta's use of POCOs. I feel it's a great choice for creating RESTful services. In fact, I would probably chose it over OpenRasta now but this is more due the benefits of working within a Unix environment than the frameworks themselves.
The play framework is a popular new choice for Scala and the JVM:
http://www.playframework.org/documentation/1.2/routes
One option is Play!, which is basically framework based off Ruby on Rails.
Second option you might be interested in is Lift, which also has really cool features like comet, AJAXy snippets, etc. But it is a little bit different than Play!.
As part of this project, I would recommend Restlet which is the first and most comprehensive REST framework for Java. It works on both client and server side and is indeed resource centric, not just a MVC framework adapted to REST.
Is it possible to build a Java web application which has a PHP front end ?
I want all my web pages to be coded in PHP. Most of them will be forms.
I want all the data submitted by a form to go to a Java Code.
I want to do all manipulation in back end and all rendering of web content on the front end.
This is just a general question as I was probing for different options for my java web application.
You might also want to take a look at php-java bridge
A web application, by definition is already a frontend (or at least includes it).
If you meant a PHP webapp built on top of a Java backend, sure, that's possible. If you use SOAP or REST for communication between the layers, it's actually relatively easy. The only drawback compared to a pure Java (or pure PHP) app would be the overhead of those protocols, so you have to be careful to avoid too fine-grained service interfaces.
It depends on where the two meet. You could have, for example, have Java backend and PHP frontend communicating via web services. I however see no benefit in such a combination.
You can use Quercus, a Java implementation of PHP, to run PHP from within Java (and thus have easy access to Java classes).
According to your edition, it looks like you don't need PHP at all. You confused it with HTML.
Yes. You can build a java web-application which has php front end.
it is possible even with C++ backend. but why?
At the moment, I have lot's of Java which does all kind of nifty stuff and I'm happy with it. The code is command line driven which have been great so far, but I recently decided I want to make the functionality available through web-services. Since my is complex and I'm happy with the way it's written , I don't want go through the pain of porting it to other languages. So I set out on a google journey to find out what web servers exist (on a Linux machine, though it's interesting to hear the answer without that limitation).
From what I could find, it seems that there are two viable options: Apache Tomcat and Sun Java Server.
What are the reason to choose one on top of the other? what are the strength of each and what are the weaknesses? Or, perhaps, there is a third one which is much easier, flexible and less cumbersome.
Anyone?
Easy, flexible and not cumbersome, that would be Jetty, but also Simpleweb might be useful. You dont say much about your software so i'm not really sure, but for a command line program, I don't think you need all the JavaEE stuff.
The mainstream servers are these.
I think the Apache Tomcat vs Glassfish (Sun Java Server) discussion is irrelevant for your needs, any would do.
There are many containers for Java web applications, they all have their own strengths and weaknesses. If you're looking for a container to support a business application, you should probably take a look at how they differ and work out which suits your business and IT drivers.
The key thing is that they all support the servlet specification - your webapps can run in any of them - which means you can change your mind easily. Some of them will also support more of the Java Enterprise Edition specs, so may be too heavy for your needs.
If you're just getting started, I'd suggest Tomcat. It's basic, but it's reliable, quick to run and start up, and it's got a really easy web-based webapp deployment interface.
Your question is actually a bit too ambiguous and wide. You can in fact run Java code at any machine you like, regardless of the language you programmed the webbased interface in. You can for example create a PHP based website which interacts with a "backend" Java application (the "command line application" as you call it). The only requirement is to have a JRE at the server machine. Then basically everything as web interface suffices: CGI, PHP, ASP, Python, etcetera, you name it. As long as it has access to the underlying commandline runtime, which is in the PHP example to be done by exec().
But Java, actually Java EE, also provides a web application programming interface: the JSP/Servlet API, the web component of the large Java EE API. This make integration with the "commandline Java application" much more seamless. You can basically just put your application in the classpath and import/access/use it in a Servlet class the real Java way:
YourApplication app = new YourApplication();
Result result = app.doStuff();
// ...
To be able to run JSP/Servlet (JSP is at end actually also a Servlet), you need a concrete implementation of the Servlet API (the whole Java EE is just an abstract specification). Apache Tomcat is good to start with, the other popular alternative being Eclipse Jetty. Those are 'simple' servletcontainers which implements the Servlet API, with Jetty being a more embedded approach of it (you can configure and run it as a "plain vanilla" Java Application). But if you need to support/cover the other aspects of the Java EE API as well, then you need an application server, such as Sun Glassfish or JBoss AS (both which by the way uses Tomcat as the servletcontainer part).
To learn more about JSP/Servlet, I can recommend the Coreservlets.com tutorials.
Apache Tomcat should do good.
The standard concept for running code inside a web server is the "Servlet API" from Sun.
Essentially it provides a few interfaces which the web server uses to invoke your code, and defines how the web server should behave. This allows you to write very generic code that can run in a variety of web containers which implement the Servlet API. See the Wikipedia article for details - http://en.wikipedia.org/wiki/Java_Servlet.
They come in all sizes too, depending on your needs. Some small enough for embedding in your own application, some very big. The servlet API allows you not to care.
For a beginner, the quickest way to get up and running, is to download the full version of Netbeans which includes full support for doing this kind of work, and has a built in servlet container.
Im porting a project from php to java. The project is a web-app based on php and ajax techniques with a javascript front-end. What java-frameworks would you use for something like this?
Does the result have to be written in Java, or does it just have to run on the JVM? In the latter case, you might want to consider Grails, which uses Groovy, a Java-based dynamic language that compiles to Java byte code and has full access to the Java standard API.
How well do you know Java?
Why are you porting it?
I can't really tell based on your description, but there are lots of Java web frameworks out there. Pick one. I prefer Spring.
I fear that you're about to be very disappointed. I anticipate a lot of questions like "Why can't I do X in Java? It's easy in PHP!"
Apache Wicket is a possible java based web framework you might consider. The default would be the java servlet and jsp frameworks.
without seeing the source code - you will need a complete rewrite. just "porting" will probably not work.
out of all available frameworks i'd recommend two: wicket if you want clean lightweight technology. with ajax. jsf/seam if you are in a corporate environment where it it easy to get tons of experienced developers.
I really like Stripes.
There's a really good book out on it too. Stripes ... and Java Web Development is Fun Again.
This question seems to come up alot. Related:
What Web Application Framework for Java is Recommended?
Best java mvc framework implementation for web apps
Does it make sense to use a framework for a simple java web app?
What language/platform to choose for a new web application?
In my opinion you would still do the same but generate the html with JSP and javabeans instead of php. javascripts and ajax will still work without a problem if the outputed html is the same.
It depends by the size of your project, the features and your resources.
If the project have'nt a lot of particular needs you can use Struts. Thsi is a stable framework, not really advanced but simple and powerfull for the development.
Another frameworks more recent and advanced are Spring and Wicket.
Before you start, I recommend you to do a check-list of your need:
Do you must porting a O/R mapping too?
Have you a stable developer knowing Java/J2EE?
Do you think to add some feature during the porting or in short-run?
etc etc
good luck! :)
I would port it to GWT
Google Web Toolkit (GWT) is a development toolkit for building and optimizing complex browser-based applications. Its goal is to enable productive development of high-performance web applications without the developer having to be an expert in browser quirks, XMLHttpRequest, and JavaScript. GWT is used by many products at Google, including Google Wave and the new version of AdWords. It's open source, completely free, and used by thousands of developers around the world.