16.Java WEB Project Environment Building

Source: Internet
Author: User

  • such as Gif demo, under Eclipse, the general project structure of small and medium-sized projects is basically this model, so we also here on the network an open source project Jsprun to explain.
  • : Http://pan.baidu.com/s/1i3zrSf7
Eclipse project configuration

  • As the arrows show, under IntelliJ idea it is supported to open the ECLIPSE project directly without importing it.
  • As shown in callout 1, select the project .project file to open.

  • As shown in callout 1, IntelliJ idea can automatically recognize a compiled src class directory, so the folder here is blue.
  • As shown in callout 2, the Java Web project WebRoot is the root directory of the entire project output, so this area is also very important, just without configuration.
  • As shown in callout 3, WEB-INF some of the following configuration files, as well as two directories classes and lib all are critical, in which classes is the red directory, which is excluded, because the compiled file is not very meaningful for development, so it was excluded. But this does not affect the container to use it.

  • As shown in callout 1, because this project is a single Module, we Project compiler output can select WEB-INF the compiled directory under the project classes .

  • As shown in the red circle, we can make these five types of catalog annotations based on any directory of the project, which is very important and must be.

    • SourcesTypically used for labeling similar src to such a compiled directory. Sometimes we don't just have src to compile the directory of the project, there are some other special directories that we might want to use as a compiled directory, and we need to label that directory. This Sources is the only kind of compiled catalog that can create new Java classes and packages, which you need to keep in mind.
    • TestsTypically used to label a compiled unit test catalog. In the canonical MAVEN project structure, the top-level directory is src , maven src We are not set to Sources , but in its subdirectory directory under the directory main java we will set as Sources . The directory where the unit tests are, we set the directory as a src - test - java java Tests compiled unit test directory. Generally this and the next few of us are configured under the MAVEN project, but I'll talk about it first. From this we can also see that IntelliJ idea's support for the MAVEN project is quite thorough.
    • ResourcesTypically used to label resource file directories. Under the MAVEN project, the resource directory is separate, and its directory is: src - main -resources , here's the resources directory we will set to Resources , indicating that the directory is as a resource directory. The files under the resource directory are compiled into the output directory.
    • Test ResourcesA directory of resource files typically used for labeling unit tests. Under the MAVEN project, the Resource directory for unit tests is separate, and the directory is: here we set the directory as the src - test -resources resources Test Resources Resource directory for unit tests. The files under the resource directory are compiled into the output directory.
    • ExcludedGenerally used to label exclude directories. Excluded directories are not indexed by IntelliJ idea, which is equivalent to being discarded by IntelliJ idea, which is a code file that does not have regular code features such as code checking and smart hints.
    • With the above introduction, we know that for non-MAVEN projects we just have to set it up src .
  • As the arrows show, the labeled directory will have a general summary on the right. classesAlthough it is a Excluded directory, but it has a special, can not be shown here.

  • As shown in callout 1, if you want to remove the tag meaning of the TOC, you can click the Fork button to delete it.

  • As shown in callout 1, this is a single-module project, and the module's compiled output directory can be the same as the project output directory, which is the WebRoot next classes directory.

  • As shown in the red circle, this shows all the dependencies of the project, where red indicates that IntelliJ idea is not recognized. IntelliJ idea supports a single import dependency package and also supports the direct import of all dependent packages under a single directory. This is a specific dependency package. Unless there is a dependency order relationship for each of your project dependencies, it is cumbersome to recommend one. So I'm going to get rid of all these scattered dependencies first and then introduce them by directory.
  • As shown in callout 1, the dependency package supports these five operations.
  • A plus sign indicates that a new dependency package can be introduced.
  • A minus sign that indicates that the corresponding dependency package can be removed.
  • The up arrow indicates that the dependent package can move up the position. The higher the upper representation of a dependency package takes precedence over the time the project loads, so the result may be quite different for the same dependent package, different versions, and dependent order.
  • The down arrow indicates that the dependent package can move down the position for the same reason.
  • A pen that represents the name and path of the dependent package that can be edited.

  • As shown, a dependency package support jar package and directory are introduced. And the dependent packages that have been imported into the project Libraries . Multi-module projects can also rely on other module.

  • Since we have just removed all the dependencies in the red circle, we now need to import the dependent packages as well. We first put the project lib as a total dependency package into the project before importing Libraries . A Gif demo is a way to lib convert a directory into a dependency package. The advantage of this is that when we have a new add-on package for our project, we simply place it in the lib directory and be automatically introduced to the project because we are citing a directory instead of a dependency package.

  • As shown in callout 1, introduce the Libraries next dependent package that you just placed lib .

  • For traditional Java Web projects, we typically also need to specify the configuration Web. XML location. As in Gif demo, this is typically Facts configured in. Factscan be understood as the framework area used to configure the project, where the framework configuration files used by the project are managed. This is a unique configuration point for IntelliJ idea.
  • In addition to Web. XML generally we want to configure the outside, some other frameworks, even if we do not configure here will not affect the operation of the project, but there are shortcomings. For example, we typically have a spring framework in our project, and spring has a lot of configuration files, and if we configure here, you will find that there will be a few more settings for the spring project at the bottom of the IntelliJ idea edit area, because you told IntelliJ Idea, your project uses the Spring framework, and that IntelliJ idea will appear with its corresponding configuration function for you. Hibernate and other frameworks have the same rationale.

  • ArtifactsAlso a concept unique to IntelliJ idea, we can understand that this is where the final output of the project is configured. For example, Java WEB projects we typically have a configuration that is configured as a way to deploy a war package so that the container can run the project. The Gif demonstrates an output structure that configures the deployment of a war package. Its structure is due to the previous configuration decisions, so if the previous Module configuration does not have much problem, there are some configuration steps that can be omitted. But there are times when we need to make some changes, and instead of the output directory of this project, the default is error, I changed to the directory in the project webRoot .
  • This Artifacts configuration, and so on, will also be referenced when you configure Tomcat, so here's a key point to note.
Tomcat Configuration

  • As shown in Gif, a Tomcat configuration process for the project as a whole, some of which need to be specifically explained, we will decompose below.

  • As shown in the pop-up layer, IntelliJ idea supports the current mainstream application container on the market, so basically a IntelliJ idea is enough for us to develop common projects. But here's a little bit of a reminder that IntelliJ idea supports these containers but not the same as the files that bring us these containers, so the Gif demo above originally introduced Tomcat 7, but for this project I introduced Tomcat 6 and the introduction of Tomcat 6 I just specified the directory location where it was stored IntelliJ idea will automatically be recognized.

    • As shown in callout 1, we can switch between different containers at any time for the project.
    • As shown in callout 2, we can specify the VM parameters for the running container.
    • As shown in callout 3, this is the event that is triggered under both commands. This is IntelliJ idea unique, but also the focus.
  • On Update actionWhen we press the Ctrl + F10 container update, we can update the container according to the event content we configured. The events I chose Update classes and resources are the most commonly used, which means we Ctrl + F10 trigger updates to the compiled class and resource files into the container when we press for container updates. In Debug mode, this is called HotSwap . This is a hot deployment without the JRebel plug-in as well.
  • On frame deactivationWhen we switch IntelliJ idea to the browser for the specified event update, this is generally because of the Web development, we need to switch back and forth between IntelliJ idea and each browser, so we have this requirement. IntelliJ idea is to help us do some specific things when we're doing this kind of boring switch. Of course, if the switch is too frequent, this feature is very resource-intensive, so I set the Do nothing switch is to do nothing.
  • As shown in callout 4, the default Tomcat HTTP port is 8080, if you need to change its port can be set here.
  • As shown in callout 5, this knowledge point has already been mentioned in the previous article. This indicates what to do before the Tomcat container is run, here are the: make and Build artifacts operations. As shown in the Gif demo above, this Build Artifacts is what Deployment happens automatically after we add Artifact to the tab.
Tomcat Boot
  • With the above configuration, the IntelliJ idea environment configuration is configured and is now configured for the project-related.
  • Open your Mysql, execute the following script, create a new database and user:
DATABASE 'SET UTF8;  USER 'jsprun ' @' localhost' jsprun';  On Jsprun. ' Jsprun '@' localhost'; FLUSH privileges;          
  • Switch to the above new jsprun database in the Execute project in this data script, file location: JspRun\WebRoot\install\jsprun_zh_CN.sql .
  • Modify JspRun\WebRoot\config.properties Several properties in the file to the following:
  • dbuser = jsprun
  • dbpw = jsprun

  • As with the Gif demo, we lack the dependency package that introduced Tomcat.

  • As in Gif demo, after we introduce the Tomcat dependency package, we can run the project.

  • As shown, run for the final project.
Tomcat stop

  • As shown, the Stop button is to be pressed two times, and the first click of a skull is not stopped and needs to be clicked again.
  • Sometimes even if you point two times, the Tomcat container may not be able to completely stop, it is very easy to get the port occupied operation, this time you need to open the system's resource manager, manually kill all Java processes on the system.
Output War Compressed package

  • As shown in Gif, in addition to the need for configuration in the artifacts, you also need to configure it in the container, so that when the container is started, a war compressed package will be output.
  • Through configuration, we also know that the nature of the war's compression packet is compressed according to the expanded war output package.

16.Java WEB Project Environment Building

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.