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

Reasons why MySQL kill cannot kill threads

Table of contents background Problem Description ...

How does MySQL ensure data integrity?

The importance of data consistency and integrity ...

Binary Type Operations in MySQL

This article mainly introduces the binary type op...

MySQL uses custom sequences to implement row_number functions (detailed steps)

After reading some articles, I finally figured ou...

Using HTML+CSS to track mouse movement

As users become more privacy-conscious and take m...

MYSQL subquery and nested query optimization example analysis

Check the top 100 highest scores in game history ...

Learn Node.js from scratch

Table of contents url module 1.parse method 2. fo...

Detailed process of installing and deploying onlyoffice in docker

0. System requirements CPU I5-10400F or above Mem...

Specific usage of CSS compound selectors

Intersection Selector The intersection selector i...

Web design must also first have a comprehensive image positioning of the website

⑴ Content determines form. First enrich the conten...

Example analysis of mysql stored procedure usage

This article describes the usage of MySQL stored ...

A comprehensive understanding of Vue.js functional components

Table of contents Preface React Functional Compon...

Detailed explanation of SSH password-free login configuration under Linux

Assume there are two Linux servers A and B, and w...