Maven starts postgres server

I am working on a project for school and I need to replace hsqldb with postgresql in the maven project.

We are currently starting the hsql server by running

mvn exec: java -P hsqldb

To my knowledge, it scans the hsqldb profile in pom.xml

<profile> <id>hsqldb</id> <build> <plugins> <plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>exec-maven-plugin</artifactId> <version>1.2.1</version> <executions> <execution> <goals> <goal>java</goal> </goals> </execution> </executions> <configuration> <mainClass>org.hsqldb.server.Server</mainClass> <arguments> <argument>-database.0</argument> <argument>db/name</argument> <argument>-dbname.0</argument> <argument>name</argument> </arguments> </configuration> </plugin> </plugins> </build> </profile> 

So, I need to reuse this part with postgres installation, I already added postgres as a dependency.

 <mainClass>ServerClass</mainClass> 

- my biggest problem, since I can not find the main server class in postgresql bank

+1
java maven postgresql hsqldb
Jun 04 '14 at 11:05
source share
2 answers

PostgreSQL is not a memory server. It cannot be loaded only as a library and started.

You will need a wiring harness control code:

  • initdb temporary datadir

  • Edit postgresql.conf , as required by the addition of lines, or by including include_dir and drop-down files. If you only need a trivial configuration, you can skip this step; things like port can be set via environment variables, and many others can be set using the -c flags in the server start command.

  • create a random port number to use

  • Start the server - run postgres -D the_datadir new instance of the server using the Java Process control. You can pass custom configuration values ​​with -c and also set environment variables to control behavior.

  • Connect to JDBC and CREATE DATABASE , then run the test setup

  • Run your tests

  • Stop the server by killing the process you started.

  • Remove datadir

You will need to control the process in the class with the appropriate temp directory processing, cleaning up on an unclean output (kill the Pg server and remove the datadir for exception), etc.

I will be surprised if you cannot find a canned code for the harness for borrowing for this. I wonder if we add to PgJDBC and associate it with the driver? If you find something good or write something good, please write me a comment on this answer and I will consider it to be included as a utility class in PgJDBC.

However, tests are much more common in a newly created test database in an existing PostgreSQL instance that is already running on your server. You simply configure your test suite using the PostgreSQL username / password / host / port / database (or let it connect to the postgres database and the CREATE and DROP database). In the end, some configuration is required: installing or compiling PostgreSQL, make sure the binaries are on PATH , etc.

Another option is to use Amazon RDS: use the AWS RDS API to start a new instance of PostgreSQL and use it for your tests. This is probably impractical if your tests fail to run for a long time due to installation time and minimal runtime, but this is another option similar to the service in Heroku.

+5
Jun 04 '14 at 11:32
source share

I believe you need this:

 <mainClass>org.postgresql.Driver</mainClass> 
0
Jun 04 '14 at 11:10
source share



All Articles