Place Java project using database on the server created in VPS so far

Placing the app on the server for the first time.

Environment so far

I am still using the environment created up to Building Java execution environment on Sakura VPS.

--Sakura VPS

Where I stumbled

You need to restart if you change anything. I was quite worried without knowing the rudimentary thing.

Export and deploy war files

Prepare a WAR file. The figure below is exported in Eclipse. image.png

Official sample file. If you can't prepare an affordable war, you can't check the operation of the database, but for the time being, it may be good to put this and check it.

Upload WAR file by FTP

It is easiest to deploy with the GUI (Tomcat Web Application Manager) that was set last time, but since it became unusable after that, deploy it manually. I will move it later, so wherever I upload it. For the time being, upload the test folder under the WWW where the FTP authority was set with WinCSP.

/var/www/html/test image.png

Move the war file under webapps

Example: Move the war file temporarily placed under html under webapps

# mv /var/www/html/test/sample.war /usr/local/apache-tomcat-8.5.34/webapps/

After a while, it will be automatically expanded, and if the project does not use the database, it can be accessed from the browser up to this point.

Example:

https://IP address of VPS/sample/

Subsequent steps are required for projects using databases.

Export and deploy SQL files

Export SQL file.

The figure below is MySQL Workbench. image.png

Deploy SQL files

It's easy to understand visually, so deploy it using phpMyAdmin. https://VPSのIPアドレス/phpMyAdmin(URL変更推奨)/

Create a new database on the Database tab. Match the collation to the same as the database in the development environment.

image.png Import the SQL file you just exported image.png

Describe server settings

Describe the settings of the following 2 file servers

There is a file with the same name in Eclipse, so copy and paste the relevant part from there. Change the database name and password accordingly.

The figure below shows the location of the file in Eclipse.

image.png

Describe Resources in Global Naming Resources

/usr/local/tomcat/conf/server.xml


 <GlobalNamingResources>
    <!-- Editable user database that can also be used by
         UserDatabaseRealm to authenticate users
    -->


		<Resource driverClassName="com.mysql.jdbc.Driver" initialSize="1" maxIdle="3" maxTotal="5" maxWaitMillis="5000" name="jdbc/[DB name]" password="【password】" type="javax.sql.DataSource" url="jdbc:mysql://127.0.0.1:3306/[DB name]?useUnicode=true&amp;characterEncoding=utf8" username="root" validationQuery="SELECT 1"/>

/usr/local/tomcat/conf/context.xml



     <ResourceLink name="jdbc/[DB name]"
 global="jdbc/[DB name]"
 type="javax.sql.DataSource" />

Reboot and check.

Recommended Posts

Place Java project using database on the server created in VPS so far
Using the database (SQL Server 2014) from a Java program 2018/01/04
Try using the Stream API in Java
Kick ShellScript on the server from Java
Build Web Application Server (Java) on VPS
I stumbled on the Java version in Android Studio, so I will summarize it
ChatWork4j for using the ChatWork API in Java
Display "Hello World" in the browser using Java
Display "Hello World" in the browser using Java
Try communication using gRPC on Android + Java server
Try using the COTOHA API parsing in Java
I tried using Log4j2 on a Java EE server
Try global hooking in Java using the JNativeHook library
Differences in code when using the length system in Java
JSON in Java and Jackson Part 1 Return JSON from the server
Try launching a webAP server on the micro using Helidon
Show detailed error in Logger when running Java on server
How to switch Java in the OpenJDK era on Mac