Java, moving from desktop app to web app?

You should definitely use a framework as otherwise sooner or later you'll end up writing your own.

You should definitely use a framework as otherwise sooner or later you'll end up writing your own. If you use maven then simply typing mvn archetype:generate will give you a huge list of frameworks to choose from and it'll set up all of the scaffolding for you so you can just play with a few frameworks until you find the one that works for you. Spring has good documentation and is surprisingly easy to get started with.

Don't be put off by the pages of documentation! You could use JPA to store stuff in the database. You should (in theory) just be able to annotate your existing POJO's to denote primary keys and so on and it should just work.

You can also use JSP's within Spring if that makes life easier.

Thanks a lot. +1 – Dhaivat Pandya Jun 1 at 23:48 Any good resources for learning Spring? – Dhaivat Pandya Jun 2 at 1:46.

You will need: a web framework. Since you have Swing background, JSF 2 will be your best bet (everything will be painful, of course, but JSF will get you up and going quickly and will help you avoid the most tragic mistakes). Also, wrapping business pojos into web guis is the main use-case for JSF and it's biggest focus.

A "glue framework". One thing that is much different with web applications as opposed to desktop ones is that you cannot create view components by yourself - they must be created when browser requests a page. So you have to find a way to create the view objects and deliver all the references to the pojos that represent logic, some of which may have very different lifecycles (this is not a problem on desktop, but on web you have to distinguish between pojos that live along with the whole application, along with a single user session, along with a single request, and so on).

The "glue framework" could also provide the additional benefit of managing transactions. You have three choices: Spring. It's not half as complex as you thing; you only need to learn some basic stuff.EJB.

You would need a real application server, like Glassfish or JBoss bare JSF has good support for dependency injection, the only drawback is the lack of automatic transaction management. If I were in your position, I would go with bare JSF 2.0 - this way you only need to learn one new technology. At first, try to avoid libraries like PrimeFaces - they usually work worse than advertised.

Edit - and addendum or - what is "dependency injection"(abridged and simplified) When request comes to a web application, a new task starts in a new thread (well, the thread is probably recycled, but that's not important). The application has already been running for some time and most of the objects you are going to need are already built and should not get created again: you have your database connection pool, maybe some parts of business layer; it is also possible that the request is just one of many request made during one session, and you already have a bunch of POJOs that the user is working on. The question is - how to get references to those objects?

You could arrange your application so that resources are available through some static fields. They may be singletons themselves, or they could be acquired through a singleton locator. This tends to work, but is out of fashion (hard to test, hard to refactor, hard to reuse, lifecycles are hard coded in application).

The real code could look like this: public void doSomething() { Customer Service cs = AppManager.getInstance(). GetCustomerService(); System.out. Println(cs.getVersion()); } if you need clustering and session management, you could build a special kind of broker that would know and provide to anyone all kinds of needed objects.

Each type of object would be registered as a factory under a different name. This also works and is implemented in Java as JNDI. The actual client code would look like this: public void doSomething() throws Exception { CustomerService cs = (CustomerService)new InitialContext().

Lookup("some_fancy_looking_name_in_reality_just_string"); System.out. Println(cs.getVersion()); } The last way is the nicest. Since your initial object is not created by you but by the server just after http request arrives (details depend on the technology you choose, but your entry point might be a JSF managed bean or some kind of action controller), you can just advertise which references you need and let the server take care of finding them for you.

This is called "Dependency Injection". Your acts as if everything is taken care of before your code is ever launched. Spring or EJB container, or CDI, or JSF take care of the rest.

The code would look like this (just an example): @EJB CustomerService cs; public void doSomething() { System.out. Println(cs.getVersion()); } Note: when you use DI, it really uses one of the two former methods under the hood. The good thing is: you do not have to know which one and in some cases you can even switch them without altering your code; the exact means of registering components for injection differs from framework to framework.It might be a piece of Java code (like in Guice), an XML file (classic Spring) or an annotation (classic EJB 3).

Most of the mentioned technologies support different kinds of configuration.

– Dhaivat Pandya Jun 1 at 23:48 aaargh. This question is, delicately speaking, much too broad. I'll try to edit the answer a bit, but you will have to read up on DI much more than that if you want to understand it (if you just want to use it - don't bother).

– fdreger Jun 2 at 13:43.

... I a bunch of POJOs and they communicate with a single class that, right now, uses a flat file as a "database", of course, in production, I would use a legitimate database and just change that single class. Is this a good idea? Will I be able to go from POJOs to a web app?

Qualified yes. If the pojo's are sane you should not have many problems. Many people use hiberbate.

Should I use a framework? I would like to have this app written pretty soon, seeing that all the buisness logic is there, I just need to wrap it so its usable, so, I don't want to spend an extreme amount of time learning, say, Spring (which AFAIK is huge), but, I don't want to keep reinventing the wheel throughout my app either. I can always just use JSP and scriptlets... probably.

Spring is huge, but things like grails or roo can help. If you want to have a responsive web app, you will need to do some kind of rich client (AJAX). This may require a lot of your code to run on the client.

This means writing a lot of javascript or using gwt. This will be a pain. It probably will not be so easy to just "wrap it".

If you have written a swing app, then basically that code will need to run on the client. If you said yes to the above, what framework(s) do you suggest? Please note that I would like a framework that I can start using in maybe 3-4 weeks of learning.

I like groovy and grails - grails uses spring-mvc, spring, hibernate. But there is roo, play and others. Will I have to start from scratch with the POJOs that I have written?

They're well over 30k LOC, so, if it is like that, I'll be hesitant. The code that will run on the server can probably be mostly left alone. The code that has to run on the client needs to be rewritten in javascript or maybe you can get some reuse out of that code by using gwt.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions