开发者

what are the steps in order to run java enterprise application

Sorry for this simple questions but i am too much confused with how to run java application. Whenever i ask some each one tells his own tools to proceed and i have learn that thing.

So provided i have simple basic eclipse with no plugin and i have downloaded the sample web application which uses spring , hibernate , mysql ,

The folder structure of app is

.setting
src--main,test
target
.classpath
.project

Now i want to run this using localhost in browser

what thing i need to do. i will tell from my knowledge and u guys can correct it i don't want to use STS or install any plugin in eclipse.

  1. I imported the project from eclipse menu and i appeared on left window
  2. As it uses spring do i have to add the spring jar files in build path of spring. or anything else
  3. Same for hibernate jar files
  4. Fior simple java app i used to compile the class which contain the void main function but i have no idea which file to compile to run this app
  5. I added the mysql connector in build path to connect with mysql in simple java app. will same thing work here?
  6. I knoow we need web server for that. so if i want to install glass fish server then how will i connect it to eclispe or that app. will tomcat be ok than glass fish??? i know tthere is eclispe ide with embedded glass fish but i want integrate evrything myself
  7. IN browser i which url i need to use to see that app

I don't know how did maven , appfuse fit in here. Can i run app without maven if yes then what does maven really do , i mean does it compile the java files or what. If i require maven then

  1. Do i need to install it separately i mean exe file or jar file
  2. how to link with eclipse
  3. I have read about building with maven , what will ahppen after building i mean what is the result of building , will i see browser after building or after building there are some steps further. do maven needs to link with w开发者_运维知识库eb server installed

sorry for basics questions but i am confused with all new trminology


Building a webapp is complicated. I will try and address your specific questions.

Utimately you don't need Maven or Appfuse, both can be very helpful.

Maven is a build tool. Maven and Eclipse do some similar tasks. Both can compile your code and manage a classpath. Maven handles a lot of things out of the box that Eclipse can't do by default. Maven can manage dependencies (i.e. download the spring jars for you) and create complex build processes.

If you are unfamiliar with Maven and creating a build file from scratch then it probably won't be much help. If you have a pom.xml (Maven build file) from somewhere else then Maven can be a big help. The result of Maven depends on how your build file is structured. The result is most often either a .war file (described below as step 5) or that your application is deployed directly to your web server (described below as step 6).

Appfuse is also not mandatory but can be useful. Appfuse will create a skeleton project for you. When it does this it will create a pom.xml (Maven build file) to automatically build your project. Appfuse by itself doesn't do anything other than help get projects started. Most people don't start building web apps from scratch anymore since getting the directory structure right and creating the build file can be a lot of work and it's easy to make mistakes. A tool similar to Appfuse is Spring Roo.

Tomcat, Glassfish, Jetty, and JBoss are web servers. They are also often called Servlet Containers which is just another name for a web server that hosts servlets in a certain fashion. Any of them will work for your project, they all have different learning curves. Integrating them into Eclipse may work for you, when I got started I found it was easier (although a little slower) to keep them separate.

In the JDK there is an interface named javax.servlet.Servlet. This is the interface that the entry class of your web application must implement. In particular the method service(ServletRequest req, ServletResponse res) is called every time there is a request for a URL. If you want your web application to respond to HTTP it may be simpler to extend the abstract class HttpServlet (which implements Servlet) instead. Most libraries (i.e. Spring web framework) have their own implementations of Servlet that are the entry point to the library.

I will now describe the basic process for building a web application. This is a complicated process and most people eventually automate it with Maven. I do not suggest trying to manually walk through the process yourself it can be very complicated but you can if you want. I am going to assume that you are placing all of your built files in a folder named $BUILD

  1. Compile your source code. The compiled classes need to end up in a folder called $BUILD/WEB-INF/classes
  2. Place all your jar files (external libraries) in a folder named $BUILD/WEB-INF/lib
  3. Create a deployment descriptor, this is a file that tells your web server how to deploy your code. The most important thing in this file is a mapping from URLs to Java classes that implement Servlet. It should be named web.xml and put in $BUILD/WEB-INF
  4. jar up the all this code with the root of the jar being at $BUILD. You could call this code application.jar
  5. Rename the jar file extension to war. A war file is simply a jar file that has the required WEB-INF directory inside of it.
  6. Deploy this war file to your web server (Tomcat/JBoss/Jetty/Glassfish/etc.), the process for doing this is different for each web server

That is the basics of web application deployment. Your web server will extract the war file and load all of the jars in the lib folder into the classpath. It will then take any URL requests it receives and send them to the appropriate Servlet implementations declared in your deployment descriptor.

As you can see this is not a simple process. This is the reason tools like Appfuse and Roo exist. They try and give you a starting point which does all of this basic stuff for you. If you are having trouble I would suggest trying again from scratch with Appfuse/Roo. As you start to get the hang of things I would also suggest learning more about Maven (or Ivy+Ant) to handle dependencies for you.


You should download the Java EE edition of Eclipse - it contains the code needed to work with enterprise applications.

You will also need an enterprise server (like JBoss or Glassfish) and the corresponding server adapter, which is a bit much for a beginner.

The easiest way to get started is to download Netbeans with Glassfish and use that instead - at least for now - as everything is configured correctly and it is very fast to get started! When you are more familiar with the way things work, you can switch back to Eclipse if you want to.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜