Showing posts with label Java Knowledge. Show all posts
Showing posts with label Java Knowledge. Show all posts

7/22/2016

Java commonly used util functions

Jave:
=====
Paths.get(a, b);  // path join
String.format("%s, haha ", a);

Dependency Injection: Guice
https://github.com/google/guice/wiki/Motivation

https://github.com/google/guice/wiki/GettingStarted

Java docs:
==========

http://www.grpc.io/grpc-java/javadoc/io/grpc/stub/StreamObserver.html

Server:
=======
Apache Struts
Apache Tiles

Jetty as the servelet container

7/15/2016

In memory MySQL for java | Embedded MySQL for java unit testing

Mainly used the idea from:
http://blog.palominolabs.com/2011/10/03/embedded-mysql-on-java-with-connectormxj-and-64-bit-linux/
And
https://github.com/airlift/testing-mysql-server

The idea is to use mysql-connector-mxj, but the development has been discontinued. Therefore the newest version that came with it is Mysql 5.5.9. That's included in mysql-connector-mxj-db-files.

That's too old and I want to use a newer version: 5.7.5.

The goal here is therefore to build the new mysql-connector-mxj-db-files jar file to include the new Mysql version.

Here is what I did:

1. Download the newer version MySQL to: ~/Downloads/mysql-5-7-5/mysql-5.7.5-m15-linux-glibc2.5-x86_64

2. Run the command:
bin/mysql_install_db --insecure  --user=mysql --datadir=/tmp/dbfiles/5-7-5/data --lc-messages-dir=./share/

cd /tmp/dbfiles/5-7-5/data
jar -cf ../data_dir.jar *

This step generates the data folder to /tmp/dbfiles/5-7-5/data. Then I create the data_dir.jar file. The data_dir.jar file should be included in the mysql-connector-mxj-db-files jar.

Another command to run:
jar -cf /tmp/dbfiles/5-7-5/share_dir.jar share/

The share_dir.jar should also be included in the mysql-connector-mxj-db-files jar.

3. Create the mysql-connector-mxj-db-files.jar with newer MySQL version.

Unzip the original mysql-connector-mxj-db-files.jar file. Copy the mysql, mysqld file, data_dir.jar, share_dir.jar to appropriate locations.

Run another jar -cf bla bla command to create the final mysql-connector-mxj-db-files.jar.

6/14/2016

Use Jetty to serve static content

ResourceHandler resourceHandler2 = new ResourceHandler();
resourceHandler2.setDirectoriesListed(true);
resourceHandler2.setResourceBase("/path/to/static_files");
ContextHandler staticContextHandler2 = new ContextHandler("/html");
staticContextHandler2.setHandler(resourceHandler2);

...

handlerList handlers = new HandlerList();
handlers.addHandler(servletContextHandler);
handlers.addHandler(staticContextHandler2);

httpServer.setHandler(handlers);