Maven project remote deployment && How to configure database connection using tomcat

Maven project remote deployment && How to configure database connection using tomcat

one. Remote deployment using tomcat

1.1 Problems encountered:

A third-party jar package needs to be referenced in the project. When using mvn to package the project, an error message will be reported: 'dependencies.dependency.systemPath'for com.dingtalk.api:taobao-sdk-java:jar must be omitted. The reason for the problem is that when mvn packages the project, it loads pom.xml first. If the local repository does not have the dependency, an error message will be reported.
Solution: Install the third-party jar package to the local warehouse using the command: Mvn install:install-file -Dfile=E:\taobao-sdk-java-auto_1479188381469-20200422.jar -DgroupId=taobao-sdk-java -DartifactId=taobao-sdk-java -Dversion=2.0 -Dpackaging=jar. Add war to the pom dependency and package the project into a war package. Otherwise, it will be a jar package by default and cannot be deployed. After configuring tomcat-users.xml in the tomcat config directory, if restarting tomcat does not work, restart the tomcat service. If you can successfully access http://localhost:8080/manager/html, it proves that the configuration is successful. To find the error, you can quickly locate the cause of the error through the tomcat log information to improve the efficiency of solving the problem. 5. The reason why the previous attempts failed was that this project was copied, and the path of the terminal command line in idea was still the path of the previous project. The pom in the previous project did not configure the plug-in, so the connection could not be made.
1.2 Remote deployment configuration
(1) Add plug-in:

<plugin>
  <groupId>org.apache.tomcat.maven</groupId>
  <artifactId>tomcat7-maven-plugin</artifactId>
  <version>2.2</version>
  <configuration>
    <username>admin</username>
    <password>123456</password>
    <url>http://47.102.123.186:8095/manager/text</url>
    <server>tomcatServer</server> //To be consistent with the id in the server<update>true</update>
    <path>/zw</path>//project name</configuration>
</plugin>

(2) Configure the tomcat-users.xml configuration file in the tomcat directory:

<role rolename="admin-gui"/> 
<role rolename="manager-gui"/> // Allow access to the HTML interface (that is, the URL path is /manager/html/*) <role rolename="manager-script"/> // Allow access to the plain text interface (that is, the URL path is /manager/text/*)
<user username="admin" password="123456" roles="admin-gui,manager-gui,manager-script"/>
//Notice! You can add multiple roles to this user. For remote deployment, at least this role is required: manager-script. You can also enable manager-gui for visual management.

(3) Configure Maven's setting.xml file under the servers tag:

<server>		
<id>tomcatServer</id>
<username>admin</username>
<password>123456</password>
</server>

(4) Use the command: mvn tomcat7:deploy

two. Specific steps to configure database connection configuration using tomcat configuration file

You need to configure server.xml, context.xml, and web.xml in the conf directory of tomcat.
The specific configuration is as follows: Configure under the GlobalNamingResources tag of Server.xml:

`<Resource name="jdbc/DataSource" auth="Container"
type="javax.sql.DataSource"
driverClassName="com.microsoft.sqlserver.jdbc.SQLServerDriver"		
url="jdbc:sqlserver://192.168.0.1;databaseName=xydi" username="sa" 
password="sa" 
maxActive="20" //Maximum number of connections maxIdle="10"
maxWait="-1"/>`//The longest waiting time

Configuration under Context.xml:

<ResourceLink name="jdbc/DataSource" global="jdbc/DataSource" 
type="javax.sql.DataSource"/>// Import the configuration information of server.xml

Configuration under Web.xml:

<resource-ref>
<res-ref-name>jdbc/DataSource</res-ref-name>//Consistent with the name of the resource <res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>`

If you use the Spring framework:

<bean id="dataSource" class="org.springframework.jndi.JndiObjectFactoryBean">
  <property name="jndiName" value="java:comp/env/jdbc/DataSource"/>
  <property name="expectedType" value="javax.sql.DataSource"/>
</bean>

Without using the Spring framework:

Connection con = null;
Context c = new InitialContext();
DataSource ds = (DataSource) c.lookup("java:/comp/env/jdbc/DataSource"); //The project name should correspond to that in context.xml		
con = ds.getConnection();

Summarize

This is the end of this article about remote deployment of Maven projects and configuring database connections using Tomcat. For more information about remote deployment of Tomcat database connections for Maven projects, please search for previous articles on 123WORDPRESS.COM or continue to browse the following related articles. I hope you will support 123WORDPRESS.COM in the future!

You may also be interested in:
  • idea2020.3 detailed tutorial on configuring Maven environment and configuring Tomcat
  • Detailed tutorial on Java (JDK/Tomcat/Maven) runtime environment configuration and tool (idea/eclipse) installation
  • IDEA configures the Java development environment (maven, gradle, tomcat)
  • SSM projects are frequently deployed as war packages, using tomcat and maven to implement hot deployment configuration
  • Idea configures maven-tomcat-plugin to implement project deployment
  • Import Maven Web project into Eclipse and configure it to run in Tomcat
  • Two ways to configure Tomcat in Maven projects

<<:  MySQL 8.0.20 winx64 installation and configuration method graphic tutorial

>>:  Vue implements three-dimensional column chart based on echarts

Recommend

Solution to nginx-ingress-controller log persistence solution

Recently I saw an article on a public account tha...

How to delete a property of an object in JavaScript

1. delete delete is the only real way to remove a...

A brief analysis of the configuration items of the Angular CLI release path

Preface Project release always requires packaging...

Using Docker+jenkins+python3 environment to build a super detailed tutorial

Preface: After the automation is written, it need...

An article to help you thoroughly understand position calculation in js

Table of contents introduction scroll Element.scr...

How to use libudev in Linux to get USB device VID and PID

In this article, we will use the libudev library ...

Two ways to visualize ClickHouse data using Apache Superset

Apache Superset is a powerful BI tool that provid...

How to design the homepage of Tudou.com

<br />I have been working in front-end for s...

Docker modifies the configuration information of an unstarted container

When I first used docker, I didn't use docker...

Convert XHTML CSS pages to printer pages

<br />In the past, creating a printer-friend...

JavaScript to achieve click image flip effect

I was recently working on a project about face co...

How to use async and await correctly in JS loops

Table of contents Overview (Loop Mode - Common) D...

Docker uses the nsenter tool to enter the container

When using Docker containers, it is more convenie...

How to encapsulate WangEditor rich text component in Angular

The rich text component is a very commonly used c...

Detailed explanation of CSS animation attribute keyframes

How long has it been since I updated my column? H...