Remote Debugging Play Framework

At times it is required to debug the code, debugging can be easy with any IDE. Running a play framework app and remote debug the application is possible by attaching the process and placing appropriate break points which would hit the breakpoint when the process is attached.

Start sbt-shell

Run Command clean compile test

This would result in starting a process with PID which can be traced from the sbt-shell window

opt/jdk1.8.0_181/bin/java -agentlib:jdwp=transport=dt_socket,address=localhost:35226,suspend=n,server=y -Xdebug -server -Xmx1536M -Didea.managed=true -Dfile.encoding=UTF-8 -Didea.runid=2018.2 -jar /home/sufia/.IdeaIC2018.2/config/plugins/Scala/launcher/sbt-launch.jar idea-shell
Listening for transport dt_socket at address: 35226

[sufia@sufia informis-server]$ lsof -i:35226
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
java 5981 sufia 4u IPv4 668592 0t0 TCP localhost:35226 (LISTEN)

In InteliJ->Run->Attach to Process, select the PID: 5981

This would hit the breakpoint and you would be able to debug through

The 92% chunk asset optimisation problem nodejs Angular5

At times running Angular Application on an environment which is fresh can be daunting. We may end up with errors which are not in alignment towards the development. One such of a case is the 92% chunk asset optimization problem when running a build of the Angular application.

On AWS hooked up an ec2-instance with Ubuntu 16.04, every thing works fine until you run the command npm run build.

We are stuck in an exception, 92% chunk asset optimisation and the dist directory is not created. Though we end up looking information on the development stack, but at times it could also be related to the Operating System SWAP space.

If the SWAP space on the OS if short or not available, this error shows up and to go around the error follow the instructions to check and allocate swap space on ubuntu. Hopefully this should help in getting around the problem.

One of the easiest way of increasing the responsiveness of your server and guarding against out of memory errors in your applications is to add some swap space. Swap is an area on a hard drive that has been designated as a place where the operating system can temporarily store data that it can no longer hold in RAM.

Basically, this gives you the ability to increase the amount of information that your server can keep in its working “memory”, with some caveats. The space on the hard drive will be used mainly when space in RAM is no longer sufficient for data.

The information written to disk will be slower than information kept in RAM, but the operating system will prefer to keep running application data in memory and use swap for the older data. Overall, having swap space as a fall back for when your system’s RAM is depleted is a good safety net.

sudo swapon -s

Another command for the same thing

free -m

Before we do this, we should be aware of our current disk usage. We can get this information by typing:

df -h

Although there are many opinions about the appropriate size of a swap space, it really depends on your personal preferences and your application requirements. Generally, an amount equal to or double the amount of RAM on your system is a good starting point.

Since my system has 4 Gigabytes of RAM, and doubling that would take a significant chunk of my disk space that I’m not willing to part with, I will create a swap space of 4 Gigabytes to match my system’s RAM.

Creating SWAP File
sudo fallocate -l 4G /swapfile
Check by running the following command that the SWAP file was created and space was reserved
ls -lh /swapfile
Enable SWAP Fiile
sudo mkswap /swapfile
Verfiy Permissions are set correctly
ls -lh /swapfile
Now that our file is more secure, we can tell our system to set up the swap space by typing:
sudo swapon /swapfile

We can verify that the procedure was successful by checking whether our system reports swap space now:

sudo swapon -s
Filename                Type        Size    Used    Priority
/swapfile               file        4194300 0       -1

We have a new swap file here. We can use the free utility again to corroborate our findings:

free -m

https://www.digitalocean.com/community/tutorials/how-to-add-swap-on-ubuntu-14-04

Samples on Play

http://ics-software-engineering.github.io/play-example-mysql/

http://pedrorijo.com/blog/play-slick/

 

https://github.com/daxyonis

https://alexgaribay.com/2014/06/16/authentication-in-play-framework-using-java/

Chat Application

http://matthiasnehlsen.com/blog/2013/06/23/angularjs-and-play-framework/

Reactive, real-time log search with Play, Akka, AngularJS and Elasticsearch

Forums built with Play

https://github.com/hakandilek/publicplay

https://devhub.io/repos/eljaydub-play2-crud

http://www.programcreek.com/java-api-examples/index.php?source_dir=play2-crud-master/project-code/app/play/utils/crud/views/Utils.java#showField-FieldMetadata-fieldMetadata-Object-o

Improving Play! 2.1 with Knockout.js

 

http://vyazici.blogspot.in/2012/03/chat-application-with-play-framework.html

http://www.vdzon.com/2015/08/24/creating-a-web-application-with-play-akka-and-java/

http://geeks.aretotally.in/tag/play-framework-2/

https://dzone.com/articles/persistence-and-dao-testing-0

https://github.com/ianrae/mettle-framework

https://www.toptal.com/java/building-modern-web-applications-with-angularjs-and-play-framework

https://github.com/unterstein/play-knockout-sample

http://www.ibm.com/developerworks/library/wa-playful-web-dev-1-trs-bluemix/

 

Optimizing Static Asset Loading with Play Framework

FORMS

https://github.com/JoseVte/template-api-rest-java-playframework.git

https://github.com/opensas/play-demo/wiki/Step-6—styling-form

JPA

Neat Explanation of using JPA with Play:- http://www.waitingforcode.com/play-framework/database-and-jpa-in-play-framework/read

application.conf example :- https://raw.githubusercontent.com/akquinet/Play–Framework-Example–Library/master/conf/application.conf

http://stackoverflow.com/questions/20836923/difference-between-jpa-and-ebean-play-framework

https://github.com/nikitsenka/play-jpa-java-example

https://github.com/beingsagir/play-java-spring-data-jpa

https://github.com/jamesward/play2bars/tree/java-jpa

https://github.com/zarinfam/play24-guice-spring

http://gbmetzner.github.io/Multiple-DB/

Authorization

https://github.com/schaloner/deadbolt-2

http://stackoverflow.com/questions/28459333/how-to-build-an-uber-jar-fat-jar-using-sbt-within-intellij-idea

https://www.tunnelbear.com/blog/authenticating-users-in-the-play-framework/

https://github.com/mslinn/play-authenticated

https://github.com/knoldus/jwt-play-authentication

https://github.com/TunnelBear/PlayAuthenticationSample

ACTION COMPOSITION

http://iankent.uk/blog/action-composition-in-play-framework/

https://resources.oreilly.com/examples/9781783982400/tree/master/2400OS%20code%20bundle/Chapter%207/pfe-java/app/controllers

http://bryangilbert.com/post/code/scala/action-composition-auth/

Action composition in the Play Framework

APIs, REST

https://github.com/JoseVte/template-api-rest-java-playframework

Building a REST API in Java and Scala Using Play Framework – Part 1

https://semaphoreci.com/community/tutorials/how-to-add-integration-tests-to-a-play-framework-application-using-scala

DI

Dependency injection in Play Framework using Scala

Caching

Introducing the Google Guava Cache

http://www.concretepage.com/google-api/google-guava-cache-example-using-loadingcache-cachebuilder-and-cacheloader

http://fanli7.net/a/JAVAbiancheng/JAVAzonghe/20131003/guicing-play-framework.html

EXPLANATION:http://codingjunkie.net/google-guava-cache/

CACHING EXAMPLE :

https://www.javacodegeeks.com/2015/01/using-google-guava-cache-for-local-caching.html

https://github.com/Haneke/HanekeSwift/issues/101

http://mydailyjava.blogspot.in/2013/07/extending-guava-caches-to-overflow-to.html

 

https://blog.codecentric.de/en/2016/03/caching-de-luxe-spring-guava/

https://vladmihalcea.com/2014/03/03/caching-best-practices/

MODULE DEFINITION and CONFIGURATION

Hibernate with JPA Annotations and Guice

 

Best of Breed Opensource on Play

https://www.theguardian.com/info/developer-blog/2015/dec/30/how-to-add-a-form-to-a-play-application

https://blog.redelastic.com/diving-into-akka-streams-2770b3aeabb0

http://matthiasnehlsen.com/blog/2014/08/04/building-a-geo-aware-link-shortener-with-play-framework/

File Cutters, File Spiltting

https://blog.knoldus.com/2012/03/20/handling-large-data-file-using-scala-and-akka/

https://www.programcreek.com/java-api-examples/?code=reljicd/play-framework-blog/play-framework-blog-master/app/actions/PostExistsAndUserIsOwnerAction.java# playframework samples

https://www.programcreek.com/java-api-examples/?code=CSCfi/exam/exam-master/app/security/CombinedRoleAndPermissionHandler.java#

https://github.com/commercetools/commercetools-sync-javahttps://github.com/commercetools/sphere-play-sdk/tree/0c8abf48b45f349d97f28d6b6b8fc56b9e8a8374

http://stackoverflow.com/questions/41402495/akka-stream-splitting-a-stream-of-bytestring-into-multiple-files

http://stackoverflow.com/questions/29517478/splitting-a-large-log-file-in-to-multiple-files-in-scala

https://github.com/johandahlberg/Splitter

http://james-iry.blogspot.in/2007/09/monads-are-elephants-part-1.html

http://stackoverflow.com/questions/13454347/monads-with-java-8

https://stedolan.github.io/jq/tutorial/

grpc play framework:

https://github.com/raboof/play-scala-grpc-server/tree/master/app

https://github.com/jfloff/grpc-java-sbt

http://jlogg.weebly.com/blog/writing-rest-apis-using-the-grpc-framework

Setting up PHP Environment for Development

https://gist.github.com/DaRaFF/3995789

https://www.digitalocean.com/community/tutorials/how-to-install-linux-apache-mysql-php-lamp-stack-on-ubuntu-16-04

https://www.linode.com/docs/websites/apache/apache-web-server-on-ubuntu-14-04

http://serverfault.com/questions/357108/what-permissions-should-my-website-files-folders-have-on-a-linux-webserver

OSGI CONTAINERS

https://github.com/doolse/sbt-osgi-felix

https://github.com/mbknor/ddsl-play2-module

https://github.com/mathieuancelin/play-osgi

https://github.com/tux2323/sbt-osgi-demo

https://github.com/sbt/sbt-osgi

NoSuchMethodError in javax.persistence.Table.indexes()[Ljavax/persistence/Index

URL url = Thread.currentThread().getContextClassLoader()
    .getResource("javax/persistence/Table.class");
System.out.println(url);

I’ve ran into the same problem. The question here is that play-java-jpa artifact (javaJpa key in the build.sbt file) depends on a different version of the spec (version 2.0 -> “org.hibernate.javax.persistence” % “hibernate-jpa-2.0-api” % “1.0.1.Final”).

When you added hibernate-entitymanager 4.3 this brought the newer spec (2.1) and a different factory provider for the entitymanager. Basically you ended up having both jars in the classpath as transitive dependencies.

Edit your build.sbt file like this and it will temporarily fix you problem until play releases a new version of the jpa plugin for the newer api dependency.

libraryDependencies ++= Seq(
javaJdbc,
javaJpa.exclude("org.hibernate.javax.persistence", "hibernate-jpa-2.0-api"),
"org.hibernate" % "hibernate-entitymanager" % "4.3.0.Final"
)

DB first – generating POJO on Ubuntu in Eclipse

At times eclipse in Ubuntu does not show up with menu items, to display the menu’s

sudo -H gedit /usr/share/applications/eclipse.desktop

replace 
Exec=ECLIPSE with Exec=env UBUNTU_MENUPROXY= eclipse

http://www.codesenior.com/en/tutorial/Hibernate-Automatically-Create-Java-POJO-Classes-From-Database-Tables-In-Eclipse

Ubuntu not showing eclipse menu

  1. Open your eclipse.desktop file:
    sudo -H gedit /usr/share/applications/eclipse.desktop
    

    (If you can’t find it in this path, try in ~/.local/share/applications/eclipse.desktop. Otherwise, you could have to find yours using locate command).

  2. Replace the Exec= line with this:
    Exec=env UBUNTU_MENUPROXY= eclipse
    

    Where “eclipse” is the path to your eclipse executable. In this case it’s just “eclipse” since there’s a symlink in /usr/bin folder.

    NOTE: If you can’t find your eclipse.desktop file, you can simply create one from scratch in the above path, and fill it with these lines:

    [Desktop Entry] 
    Type=Application 
    Name=Eclipse 
    Icon=eclipse 
    Exec=env UBUNTU_MENUPROXY= eclipse 
    Terminal=false 
    Categories=Development;IDE;Java;
    
  3. Save the file.

Setting up Play Development Environment on Ubuntu

# Configure apt for java
# http://www.webupd8.org/2012/01/install-oracle-java-jdk-7-in-ubuntu-via.html
apt-get update
apt-get install -y python-software-properties
add-apt-repository -y ppa:webupd8team/java
echo oracle-java8-installer shared/accepted-oracle-license-v1-1 select true | /usr/bin/debconf-set-selections

# Update apt sources
apt-get update

apt-get install -y unzip wget git vim oracle-java8-installer oracle-java8-set-default

# Install scala
cd /opt
wget http://www.scala-lang.org/files/archive/scala-2.12.0.tgz
tar -zxvf scala-2.12.0.tgz
# end scala

#Installing playframework on ubuntu there are two options

OFFLINE INSTALLER
Go to https://downloads.typesafe.com/typesafe-activator/1.3.12/typesafe-activator-1.3.12.zip, download the offline installer close to 617MB

OR MINIMAL ACTIVATOR

# Install play with activator
#Download and Install Play (the folder should have permission to write)
#wget http://downloads.typesafe.com/typesafe-activator/1.3.12/typesafe-activator-1.3.12-minimal.zip
#unzip typesafe-activator-1.3.12-minimal.zip
#mv activator-1.3.12-minimal activator

The off-line installer downloads all the dependencies required to run play applications. In a scenario where in we download only the small foot print of activator the dependencies are downloaded at the time of loading the project, which can be annoying and time consuming.

Follow the instructions at https://www.playframework.com/documentation/2.5.x/Installing to install the play and chose “installing play with activator” and follow instructions listed
Extracting Activator

Extract the archive on a location where you have write access. Running activator writes some files to directories within the distribution, so don’t install to /opt, /usr/local or anywhere else you’d need special permission to write to.
Adding Activator to your Path

For convenience, you should add the Activator installation directory to your system PATH:

export PATH=$PATH:/opt/activator/bin

source ~/.bashrc

Making the activator as an executable execute the following command

sudo chmod a+x /activator/bin/activator

Just in case after executing the above commands and when we issue activator in the terminal, if it says command not found, we need to manually edit the bashrc file as follows

gedit source ~/.bashrc

add the command to the bottom of the file

export PATH=$PATH:/opt/activator/bin

 

unzip typesafe-activator-1.3.12.zip
mv typesafe-activator-1.3.12 activator

cd /opt
export PATH=$PATH:/opt/activator/bin
source ~/.bashrc
sudo chmod a+x /activator/bin/activator
./activator
# end play with activator

#echo ‘PATH=${PATH}:/opt/scala-2.12.0/bin:/opt/play-2.2.5’ >> /etc/profile
echo ‘PATH=${PATH}:/opt/scala-2.12.0/bin’ >> /etc/profile

echo ‘PATH=${PATH}:/opt/activator/bin’ >> /etc/profile

sudo apt-get install git

echo “Installing IntelliJ IDEA…”

# We need root to install
[ $(id -u) != “0” ] && exec sudo “$0” “$@”

# Attempt to install a JDK
# apt-get install openjdk-8-jdk
# add-apt-repository ppa:webupd8team/java && apt-get update && apt-get install oracle-java8-installer

# Prompt for edition
#while true; do
#    read -p “Enter ‘U’ for Ultimate or ‘C’ for Community: ” ed
#    case $ed in
#        [Uu]* ) ed=U; break;;
#        [Cc]* ) ed=C; break;;
#    esac
#done
ed=C

# Fetch the most recent version
VERSION=$(wget “https://www.jetbrains.com/intellij-repository/releases” -qO- | grep -P -o -m 1 “(?<=https://www.jetbrains.com/intellij-repository/releases/com/jetbrains/intellij/idea/BUILD/)[^/]+(?=/)”)

# Prepend base URL for download
URL=”https://download.jetbrains.com/idea/ideaI$ed-$VERSION.tar.gz”

echo $URL

# Truncate filename
FILE=$(basename ${URL})

# Set download directory
DEST=~/Downloads/$FILE

echo “Downloading idea-I$ed-$VERSION to $DEST…”

# Download binary
wget -cO ${DEST} ${URL} –read-timeout=5 –tries=0

echo “Download complete!”

# Set directory name
DIR=”/opt/idea-I$ed-$VERSION”

echo “Installing to $DIR”

# Untar file
if mkdir ${DIR}; then
tar -xzf ${DEST} -C ${DIR} –strip-components=1
fi

# Grab executable folder
BIN=”$DIR/bin”

# Add permissions to install directory
chmod -R +rwx ${DIR}

# Set desktop shortcut path
DESK=/usr/share/applications/IDEA.desktop

# Add desktop shortcut
echo “[Desktop Entry]\nEncoding=UTF-8\nName=IntelliJ IDEA\nComment=IntelliJ IDEA\nExec=${BIN}/idea.sh\nIcon=${BIN}/idea.png\nTerminal=false\nStartupNotify=true\nType=Application” -e > ${DESK}

# Create symlink entry
ln -s ${BIN}/idea.sh /usr/local/bin/idea

echo “Done….Installing IntelliJ IDEA…”

echo “Start….Installing Scala..”