Install Java / Tomcat / PostgreSQL without polluting your Mac environment

I think that it is the mainstream to secure portability with Docker or virtual machines, but I think that "it works if you place it in an appropriate place without installing it" including me is still popular, so I summarized it in this article. I did.

Environment of this article

Advance preparation

First, create a directory to place the set of resources. Here, create a directory called myserver directly under the user's home directory and place all resources in it.

Java installation

This section is the most confusing part of the procedure in this article. If you already have Java 8 installed, you can skip this step.

Java download

Download from the official Oracle website. The version in this article is Java 8 u161.

Extract binaries from package

Extract the pkg file from the dmg file, place it anywhere, then open a terminal and navigate to the pkg location. Please refer to the following articles for the procedure from that point onward.

Try Java 9 without installing on Mac https://qiita.com/mather314/items/8d112569d7bb0805683e

Install tomcat

Next is Tomcat, a web application server. You can find the procedure here and there, so it's just for your reference.

Download tomcat

After downloading and unzipping the tar.gz from the official project site, rename it totomcat8 and place it in the myserver directory at the beginning.

https://tomcat.apache.org/download-80.cgi

Environment settings

Instead of setting it with environment variables, create a file named setenv.sh in tomcat8 / bin and set the Java location to be used. The app I wanted to run this time will cause OutOfmemory if I don't have about 1GB of memory, so I also set the startup option.

setenv.sh


JAVA_HOME=/Users/username/myserver/java
JAVA_OPTS="-Xms1024M -Xmx1024M"

Manager settings

Set the admin user and its password for Tomcat Manager. Open tomcat8 / conf / tomcat-user.xml and set as follows. Here, it is admin / pass.

tomcat-user.xml


<tomcat-users ... >
    :
<user username="admin" password="pass" roles="manager-gui,admin-gui"/>
    :
</tomcat-users>

Operation check

After starting Tomcat by running tomcat8 / bin / startup.sh, go to http: // localhost: 8080 / in your browser. If the Tomcat screen is displayed, it is successful.

Also, make sure you can also access http: // localhost: 8080 / manager / html to connect to Tomcat Manager with the user / password you set earlier.

Install PostgreSQL

Then install the database PostgreSQL. I can't find the procedure as much as Tomcat, but it is just for reference. (The entire article is a collection of references ...)

Download PostgreSQL

After downloading the binary from the official website and unzipping it, rename it to pgsql and place it in the myserver directory. I'm using version 9.6 here.

https://www.enterprisedb.com/download-postgresql-binaries

Database preparation

After opening a terminal and navigating to pgsql / bin, first create a data directory. A set of data is stored here, so if you want to place it in a location other than PostgreSQL itself, change it to any location.

$ ./pg_ctl initdb -D /Users/username/myserver/pgsql/data

Start the database by specifying the data directory and log file you just created.

$ ./pg_ctl start -l /Users/username/myserver/pgsql/pgsql.log -D /Users/username/myserver/pgsql/data

Let's connect to the database when it starts successfully. postgres is the name of the database created by default.

$ ./psql -d postgres
psql (9.6.6)
Type "help" for help.

postgres=# 

Creating database and schema

First, create the database mydb owned by you (username here username).

postgres=# CREATE DATABASE mydb OWNER username;
CREATE DATABASE

Once created, switch the operation target to the database you just created.

postgres=# \c mydb
You are now connected to database "mydb" as user "username".

Let's work on any schema and table creation with SQL.

mydb=# CREATE SCHEMA myschema;
CREATE SCHEMA
mydb=# CREATE TABLE myschema.mytable (name varchar(100), age int);
CREATE TABLE

JDBC placement

Finally, deploy the JDBC driver so that Tomcat can connect to PostgreSQL. After downloading from the official PostgreSQL site, move the jar file to tomcat8 / lib and you're done.

https://jdbc.postgresql.org/download.html

in conclusion

――This time, I decided to build the environment on Mac, but I feel that it can be the same for both Windows and Linux, so I will add it as soon as it becomes necessary. ――I haven't touched Java for nearly 10 years, and it may be that the procedure or setting is "I don't think so". I would appreciate it if you could point out. ――Also, this time I created this environment to introduce a certain framework, and I have not created a scratch application by myself. This kind of article can only be completed by running a simple operation verification app, but please forgive me.

Recommended Posts

Install Java / Tomcat / PostgreSQL without polluting your Mac environment
Install Java development environment on Mac
Install Java on Mac
Install tomcat + eclipse on mac
Build Java development environment (for Mac)
[Java & SpringBoot] Environment Construction for Mac
Java development environment (Mac, VS Code)
Java runtime environment construction method (Tomcat @ Linux)
Java development environment construction memo on Mac
Build a Java development environment on Mac
Download and install Eclipse (Java) (Mac version)
Build a JMeter environment on your Mac
[Mac] Install Java in Visual Studio Code
Install Docker and create Java runtime environment
Install java and android-sdk on Mac using homebrew
Summary of Java environment settings for myself [mac]
[Mac / Java / Eclipse / PostgreSQL] Connect Java application and database
Install Java, Apache, Tomcat9 on EC2 (Amazon Linux2)
[Beginner] Install java development tool in cloud9 development environment.
[Mac] Install Java in Visual Studio Code (VS Code)