how to use dropwizard for already developed web application - java

We have two web applications, which are already developed using Servlets and Jsp'.
generally we build them using ant and deploy on jetty server.
we would like to make build and deploying process easy. so how we can use dropwizard for our purpose or is there any other frame work we can use to make deployment and launching web applications easy.
thanks

in theory, nothing stops you from overwriting the ServerFactory and creating your own servlets there. You can then have that in DropWizard and things should work. (see DefaultServerFactory)
Problem with this is, that you are now using DW as a running container and you don't take any advantage of any features it offers you. So it really makes no sense to use that with your setup I think.
Alternatively, if you want to run and deploy into jetty, may I suggest you look into the maven jetty plugin? http://www.eclipse.org/jetty/documentation/current/jetty-maven-plugin.html
It is not my favourite way of running it, but I have seen a lot of people using it. You essentially configure your application to use this plugin and add configuration on how to set up the connectors for jetty. Afterwards, all you need to do for running is "mvn jetty:run".

Related

How to deploy java application on different server?

If i want to deploy one application on different servers like Open Source Glassfish or TomEE. How can I achieve that without having to include different libraries for each application server? As an example if would like to use Jersey as the rest framework and eclipselink as the persistence framework i have to make sure both support these frameworks. But in case of TomEE it's shipped with other implementations like OpenJPA.
Is it possible to ship the dependencies only with the project and not in combination of server libraries + project libraries?
What is a good way to achieve server compatibility?
Any information or link which describes a solution or help me understand why it's done this way would be great.
Thanks in advance
This is more of a application server classloading issue and usually all application servers have a provision for a configuration file which you can put in your application and instruct the server to load the libraries included in the web application instead of the one present in application server. For e.g., Weblogic has a weblogic.xml file which is put in WEB-INF of war application and where you can instruct server to prefer the application packaged libraries. For JBoss there is similar configuration file jboss-deployment-structure.xml. This way it is easier to have a self contained application which contains all dependencies even if the server has equivalent libraries. Also you can upgrade to higher version of libraries than supported by application server otherwise you have to resort to all sort of hacks.
Easy solution I can think of is using ant task to create war file for each servers. You can have at most 2-3 servers in reality like tomcat ee, jboss and glasfish. So create 3 ant tasks for each like tomcatWar, jbossWar and glassfishWar and each ant task makes sure required jars are shipped as well in the war. This is more easy and extendable solution, also easy to understand and modify for new requirements.

How to build desktop applications with Apache Karaf/OSGi?

Well im into building OSGi application for a while, but i can't really find some tutorials which show the way to build Desktop Application ( in any languages ) with OSGi/Karaf.
I want to use karaf because it can then wrap Felix/Equinox. Most of Tutorials i found are about Enteprise Application(WEB). So is there any tutorials, which talk about building desktop application based on OSGi/Karaf?
Here is an example of a GUI application project that uses Apache karaf:
https://bitbucket.org/lorainelab/igb-fx
Using karaf to run a gui-based desktop application decreases development time. A developer makes a change to a bundle, builds the bundle, and then uses karaf shell commands to reload just that one bundle into the running application. There is no need to restart the entire application to view the effects of the new code. This is why were are using it.
We are using OSGi because we want greater modularity in the code base and because we want to support dynamically loaded "Apps" developed by 3rd party developers who write against our genome browser API.
Sorry the main intend right now for Karaf is to be used as a Server, though it still should be possible to start some guis on top. As your already familiar with building such bundles I'm sure you most probably could use just the minor version of Karaf and place your bundles in it. I have to admit I never done this before, so I'm not really sure about it.
First of all OSGI is a component framework, it also leverages a feature missing in Java since its inception - runtime versioning. If you really need it (OSGI), it doesn't depend wether you develop a WEB or desktop application. In general I would recommend you to take a look at this documentation:
http://fusesource.com/docs/esb/4.2/deploy_osgi/Build-ModifyMaven.html
In that link you'll find how to convert an existing Maven project to bundle, check further chapters - there's info how-to deploy jars in e.g. Karaf (Karaf is an OSGI container)
Hope, this helps

Should I use Eclipse wizard to deploy web application?

I use Eclipse "Dynamic Web Project" to create and test web application. It will publish my application on application server in convenient way. I don't need to write script, just wizard.
However, I am wondering it is a decent way to deploy a web application. What's your opinion? Thanks!
(I used to use Ant script to deploy my application, it's standard way.)
plus: Dynamic Web Project uses its specific directory layout which is different with Maven standard directory layout.
This is fine for deploying to a dev or test server. Its a convenient way to quickly deploy to have a look at changes you've made and to do tests.
I would definitely not allow this for any other environment, eg live, pre-production etc. You should have an established process (eg documented change control) to deploy to these environments.
I have heard it's still recommended to cold deploy and restart the server for not having a trouble with memory leaks, dynamic class loaders. For myself I think comfortable to deploy from Eclipse to most environments. Basically Eclipse WTP server adapter can run the same deploy command as the other processes. When I use clouds like GAE or Beanstalk I do deploy from Eclipse plugin, it is the same like command line.

where we put ejb program in tomcat 6.0 and how to deploy?

I do not have eclipse. and I am having Tomcat 6.0.I write the programs in notepad. and I was successfully run the servlet programs. but I am not know about EJB. that is "where we put the .class files(In which directory)?". and "how to run and how to deploy the EJB programs?" please give sample example. please help me.
Tomcat 6.0 is not an EJB container. EJB's are a rather advanced topic. Do not haste into it. You can jump a mighty long way with servlets without ever needing EJB's or EJB containers.
If you need more services to base your app on, look at Spring, which offers (almost) everything an EJB capable container offers and allows your programs to run on Tomcat 6.
Also Java is a bit verbose to use notepad for non trivial projects. You might consider to upgrade to an environment which gives better support. I am partial to IntelliJ myself, but netbeans and eclipse are nice too for that kind of development.
If you like to stick to notepad approach, you might take a look at grails. It offers all the services but uses groovy as the programming language which makes things a lot more compact allowing to develop JVM based web apps using a lean editor.
You can run only web applications with Tomcat . For application s developed using EJB Use JBOSS. But JBOSS may be very slow. So while development use glassfish. Tomcat is only for jsp and servlets. When it comes to EJB its enterprise application and have to use EJB container like JBOSS or some other EJB container.

What framework + application server + development environment to use for Java services?

I'm trying to write a Java service which runs 24/7, scrapes content from the web, and stores it into a database. What is the best framework to use for this given that I'd like to...
1.) Have an application server that I can deploy my code to (and have it run automatically). This application server should sit on a separate box from the machine that my development environment will run on.
2.) Have a development platform (I would prefer something based on eclipse) which allows me to deploy my code directly to the application server (so I don't have to ftp everything over to test).
3.) Utilize a framework like Spring.
In effect, I'd like to know what to choose for my...
1.) application server
2.) development environment (ide) -- if eclipse, what server adapter to use
3.) framework
So far, I've tried using Virgo with SpringSource STS, but was unable to configure the web server adapter for a non-localhost-residing server. I don't want to have to install Virgo on my development box, and I don't want to have to ftp hop my code over to my production server in order to deploy.
Why don't you just use Tomcat or some other web container, but it may be better to split this into two applications.
Have one that goes out and does the scraping, as a standalone application, for this you can pick anything, I would go with Groovy (http://groovy.codehaus.org/), as ease of development and maintenance is important here, and you can use the Groovy plugin for Eclipse.
The other would be the web service and for this I would think Scala (http://www.scala-lang.org/) would be nice, if you have time to learn it, but Grails (a groovy framework) would be beneficial, so you can write a REST or SOAP web service.
By separating them then you can pick the best solution for that particular aspect, since the web server shouldn't be involved in scraping, but the web server will want to read from the database.
These two languages run on the JVM and can use regular java classes/libraries, but there are improvements over plain Java in them.
Turns out there are some maven plugins that will remotely deploy my app for me. The most notable is Cargo. This way, I can keep all of my initial tools/services the same (Virgo, STS, Maven).
I've actually build something similar quite recently. My application could run without a servlet container or an application server. The reason I choose to run my app in a Tomcat servlet engine is so that I can add a REST API to it to easily retrieve server status information, but I digress.
The plain vanilla Eclipse J2EE installation has decent Tomcat support so without knowing more about your tastes and specifics I'd go with that.
To make your application self starting you need to implement the ServletContextListener interface:
public class ServerClass extends HttpServlet implements ServletContextListener {
public void contextInitialized( ServletContextEvent event ) {
// create and start a thread here.
}
public void contextDestroyed( ServletContextEvent event ) {
}
}
Add the following to your web.xml:
<listener>
<listener-class>com.my.ServerClass</listener-class>
</listener>
Which framework you want to use, only you can decide. Your question is to generic to give a decent answer on that. Read up on a few and pick one. Plain old Java will also do just fine and otherwise Scala might be a good substitute choice.
So, to answer your questions:
Tomcat servlet engine
Vanilla J2EE Eclipse version
Plain old Java

Categories

Resources