IDEA publishes web projects through Artifacts

Today , when I run a Java Web project with IDEA , I suddenly get an error java.lang.ClassNotFoundException: com.mysql.jdbc.Driver , but I added a jdbc connection jar package in the lib directory of my project, and there is no error when compiling in IDEA , And the two jar packages I added later could not be found, but IDEA automatically prompts normally, indicating that the jar package was indeed introduced in the project, but there was a problem when publishing the project.

After investigation, IDEA released the project to an out folder, but there is no lib directory in this folder. This involves the issue of IDEA publishing projects through Artifacts. Before, I created a Java web project through IDEA's Artifacts. The process records are as follows: https://blog.csdn.net/theVicTory/article/details/104282873

Since the lib file is missing, the solution is to add the folder you need when setting the output project, as shown below, add lib to the output root when Artifacts is set and put the project's dependent jar package in this directory to solve the problem .

So the question is, what are Artifacts? How does IDEA package and output a Java Web project?

Artifacts

Artifacts is a concept in maven. It is a tool for packaging Java web projects so that the projects can be deployed on the server or distributed to the application platform. There are three packaging methods:

  • Java Archive, which aggregates Java files and related resources into a file for packaging
  • WAR: Web Application aRchive, a JAR file containing Web application resources such as JSP, Servlet, Java class, XML, tag library, etc.
  • exploded: expansion mode, that is, the war file is not compressed, and the original file directory structure is retained, which is convenient for file modification during development.

There is a Project Structure icon in the upper right corner of IDEA . You can also use the shortcut key Ctrl + Alt + Shift + S to open it. The Type selected in the configuration in Artifacts is war exploded, and the project is published to the specified directory without compression. . The output box of the option box can specify the location of the project to be published. By default, an out directory will be created under the current project for the publication of the project. The published content is the content under the label <output root>. If the resources used in your project are not placed in this directory, they will not be packaged into the publishing directory, so that there may be an error that the resource cannot be found, so if you need it To add some files to the release directory, you need to manually add them under this <output root> tag.

Other Project Structure tabs are used to set the project: the first is the Project tab, which can set the project name, SDK and project compilation output path

The second tab is Modules, which can be used to modularize the project. For example, I use the web project module. It also has three sub-tabs, where Sources can be used to mark the folder type in your project, so that IDEA can better identify your project. The second Paths is used to set the file output path of the project's compilation, testing and deployment in detail. The third Dependencies are used to set the dependencies used by the project, such as SDK, lib, dependency

 The third tab is the configuration of Libraries, which is the lib library that the project depends on. For example, here my project depends on the Java EE 6 library. Click the + sign to add the jar package to the library

 The fourth Facets tab describes the various frameworks, technologies and languages ​​used in Module, such as web, strtus2, spring, hibernate, etc. These Facets let Intellij IDEA know how to treat the module content and ensure that it is consistent with the corresponding framework and language. Facet is tightly integrated with Module. If you configure it in Module, Facet will also appear in it.

The fifth is the previous Artifacts tab, which is used to configure the project package deployment and output.

IDEA deploys Tomcat project

There are three ways to deploy a Tomcat server project

  • The first is the most common, which is to put the project in the webapps folder under the Tomcat installation directory, so that after starting the server, you can directly access all projects in the folder through the server.
  • Furthermore, we can modify the Tomcat / conf / server.xml file to specify the server deployment directory
    <Context path="/xx" docBase="D:\\workspace\\xx\\target\\xx" reloadable="true" sessionCookiePath="/xx"sessionCookieName="yoursessionname">
     </Context>
  • The third method is to create an xml file in the Tomcat / conf / Catalina directory to set the mirror location by creating a mirror directory.

    <Context path="/xx" docBase="D:\\workspace\\xx\\target\\xx" debug="0" privileged="true"> </Context>

    IDEA starts the Tomcat server through the third mirroring method. You can see that its server startup is through catalina.bat.run, not startup.bat.

CATALINA_HOME is the installation directory of Tomcat, and CATALINA_BASE is the working directory of Tomcat. If we want to run multiple instances of Tomcat, but do not want to install multiple copies of Tomcat software. Then we can configure multiple working directories, each instance owns a single working directory, but shares the same installation directory. Each running instance of Tomcat needs to use its own conf, logs, temp, webapps, work, and shared directories, so CATALINA_BASE points to these directories. The other directories mainly include Tomcat binaries and scripts, and CATALINA_HOME points to these directories. As shown below, you can see the log output by IDEA when starting Tomcat. A temporary working directory of tomcat is created in the IDEA directory of the c drive, but the installation directory is still used

Published 124 original articles · Like 65 · Visit 130,000+

Guess you like

Origin blog.csdn.net/theVicTory/article/details/104682415
Recommended