Deploying Web projects in Tomcat on a Linux server

Source: Internet
Author: User

First look at the following concepts, not quite accurate:
1. JVM
The JVM is the runtime environment for class and Jar (which is actually a lot of class compression), characterized by the Java and JAVAW commands, which allow you to execute class and jar files. You can specify the jar file you need to load with the-classpath parameter

2. JDK
The JDK is the Java command-line development environment with a built-in JVM, which is characterized by the javac command, which allows you to compile the. Java source files into a. class file in bulk or individually, which can be executed through the JVM's Java commands. At compile time you can specify the jar file to which your source code depends by using the-classpath parameter.

3. Tomcat and other JEE middleware
JEE Middleware is primarily designed to allow Java programs to provide HTTP services, to expose HTML and related resources to customers, and to prepare a running environment that typically includes the JDK (or Tomcat needs to configure the path where the JDK is located). This environment is characterized by the ability to deploy a war package that automatically loads the. class file under Web-inf/classes and the Web-inf/lib jar file under the operating environment. When the user accesses the path deployed by your war package in the middleware through a browser, the middleware can invoke the class and JSP pages in your war package according to the Java EE Standard and return the execution results to the browser. In this case you just need to compile your. java files and put them in the web-inf/classes directory.

And then talk about plain text Java Web Development, there are several types:
1, plain Text only JSP
If there is only JSP pages in the project, it is very common, you just need to create a new directory under Tomcat WebApps, and then create a new. jsp file inside it, you can execute the JSP file in a way similar to http://localhost:8080/app/a.jsp. The early Java Web projects were pretty much the same thing, and the IDE was really useless. Other technologies like ASP and PHP have been writing code in this plain text way for more than 10 of years, and there's not much difference between efficiency and IDE.

2, in addition to JSP and auxiliary Java class
If you need some Java classes to assist JSP pages in addition to JSPs, you must create a new. java file by hand, and then use the text editor (Notepad/vi/ue, etc.) to open it and manually write the code inside it. Once you've finished writing the code, you'll need to compile the. java file into a. Class before you can put it in the web-inf/classes and execute it.
There are two ways to complete the compilation action:
Mode one: jdk+ build tool (ant or maven) to compile your Java code into class and place it in your web-inf/classes directory by configuring ant to call the Javac command in the JDK
Way two: Ant is actually also converting your configuration to various parameters in the Javac command, so you can also output javac directly on the command line, and then Javac will tell you what parameters you need to provide and what kinds of parameters are used, You can call Javac to compile the. java file into a. class file as prompted.
Both approaches are somewhat inefficient, so you'll also need a. bat (or. sh) batch file to help you automatically compile the. java files in the specified directory every few 10 seconds.
The auxiliary Java classes you may need to write are:
A, global servletfilter (for example, for user rights checks)
Second, the complex output servlet (JSP is not suitable for dynamic to the browser to provide pictures and other resources, this time to write servlet)
Third, the tag class used in JSP, in order to reduce the large number of JSP <%%> code.
This kind of class will not be a lot, the general project can have twenty or thirty of the same, so the beginning of the painful period of writing auxiliary classes in the past, development efficiency and the use of the IDE is no different.

3, in addition to JSP and a large number of Java classes
Your system is huge, you need some framework for overall constraints, and then you write a large number of Java classes as required by the framework to complete the browser-side requests through these Java classes.
At this point your system status has been compared to the type of SSH, each page will have corresponding Action/controller, as well as Formbean/model, or there are specialized SERVICE/BL class and DAO class.
This way your system will have a large number of. java files that need to be compiled into a. class, and the number of jars to be referenced is also significantly increased, when you as a person without an IDE, the pain is coming:
A lot of time is spent waiting to compile, whether using the build tool's incremental compile feature or writing a more powerful batch file yourself to scan the changed classes, each compilation takes a little time and is not very reliable. In particular, "decrement compilation" is usually not supported and may have potential errors.
If you use the full recompile every time to get reliable compilation results, then the best way is to let you each Java class once the compilation succeeds, if a few more errors or modify several times, you will find that the compile time is significantly greater than the time you write code.
In this case, there is a significant difference between the development efficiency of plain text and the IDE.
If I had to work in this painful plain text condition, I would first write a Java class, let the Java class run a separate process, this process will automatically scan the corresponding directory of the Java file increment/change/delete,
The Sun.tools.javac.Main class is then called to compile, and if only new and modified, only a few classes are compiled separately, and if there are deletions, they are all recompiled.

So what does eclipse do?
1. Eclipse provides Web project engineering wizards to help you quickly create projects
2. Eclipse manages the jar files under your web-inf/lib and indexes the class classes, so that you can quickly see the location of related classes, inheritance relationships, and referential relationships.
3. Eclipse provides a complete incremental compiler, which is what you write. One important reason that Eclipse was able to win was in his compiler, where Eclipse's JDT implemented its own compiler (so eclipse doesn't even need a JDK, as long as it has a JVM), and can quickly and incrementally reflect your changes to the class file. This was the jbuilder of the time, at that time every change to finish the class have to recompile, that pain, when I introduced Eclipse in the company, in two months everyone abandoned JBuilder X (then spent money to buy a genuine).
4, provides the perfect debugging function, the IDE-based debugging efficiency will be much higher than the command line debugging.
5, provide the syntax highlighting, grammar hints, middleware management and other auxiliary tools.

1. First create a folder as the project name, such as Hello,
2. Create the Web-inf folder under Hello.
3. Build lib,classes two folders under the Web-inf folder, and the Web. xml file
4. Edit the content of Web. XML, with the ability to write directly to the bare hand, not afraid of an XML just, please with welcome file for index.jsp.
5. Create a new index.jsp under Hello and edit the content.



Put the whole hello copy into Tomcat's WebApps and launch Tomcat, a minimalist Web project.

Write Java classes, you know, not much to say. Let's say we create a Helloservlet.java with Notepad and have the ability to write the servlet directly in Notepad with the bare hands.
Compiling Java classes, Javac understand? If the class has multiple layers of package structure, you can manually create the package structure under classes, and then copy the class file Javac get into it.
Javac-d. Helloservlet.java
This command can automatically generate a class file containing the structure of the package and copy it to the Classes folder.
Then configure the servlet in Web. Xml.

So, if you have a lot of classes, are you tired? Very low productivity?
Please use ant, write a suitable build.xml and ant a bit, it is very convenient ah.


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.