Tech It Easy: February 2015

Friday, 27 February 2015

Today I learnt to use Gradle-Plugin called 'Application'

Dear Java Friends,

I started using Maven from 2013 August. After a while I came across Gradle. It is pretty much similar and simpler than Maven. It also has the notion of plugins as Maven. Today I have learnt a new plugin named application and used it like charm.



Demo app code at my Githubhttps://github.com/PraveenGandhi/gradle-application-plugin-demo

Long back I have seen a presentation (http://www.infoq.com/presentations/Improve-Your-Java-with-Groovy) by Ken Kousen called "Improve Your Java with Groovy". There he emphasizes about Gradle and says:

Maven people seeing Gradle for the first time, some times just weep, you know how much simpler life can be.

Usually I used to create some kind of automation utilities at work (inspired by my Senior at Cognizant). Now the time has come to share these tools that make my work easier with other friends (might not be typical java developers) like testers and Business guys.

I cannot give these tools as they are to others, if I give like that I need to help to to use it. Rather it is better to make some executable scripts (.bat files) which makes the usage of the tool much easier. Initially I used to create such by my bear hands. Now it is all there as a simple Gradle plugin (application).

How?


From Gradle docs:

The Gradle application plugin extends the language plugins with common application related tasks. It allows running and bundling applications for the jvm by creating a jvm application Distribution.

It gives us the tasks like run, distZip,distTar and so on.

I have used run to simply run the app using Gradle.
I used distZip to create a distribution which has every thing required to run the app without the Sophisticated build tools and/or IDEs.

The above said distribution (project_name-version_number.zip) has two folders namely bin and lib.

As the name,
bin folder has start-up scripts like batch(for windows) and bash(for UN*X).
lib folder has the output jar (of the current project) and all the libraries mentioned in the dependency list of build.gradle.

Long live Gradle :)



Thursday, 12 February 2015

spring-hibernate-multi-module-maven

Dear Friends,

Please have a look at my first Multi Module Maven project. It is a demo project for Spring MVC in following two flavors
  1. Java Config
  2. XML Config

Code is on my GitHub repository https://github.com/PraveenGandhi/spring-hibernate-maven-multi-module.



Wednesday, 11 February 2015

JBoss Gotchas

Dear Friends,

At times we might have to hit the apps running in Linux machine or another machine connected through the same network.

If you want to hit an application deployed in tomcat which is running in the same network that you are connected in, then you have to use http://IP_or_hostname:port_number/contextRoot
for example http://JaiRam-PC:8080/app that's it, you are good to go.

But if the application is running in JBoss you might see "This webpage is not available" as shown below.


Reason:
By default (due to security reasons) JBoss AS binds only to localhost.

Resolution or work around:

1. While running the JBoss use another param as follows

run.sh -b 0.0.0.0 
(on windows as follows)
run.bat -b 0.0.0.0
2. From JBoss AS 7, we have one more option, 
that is we can edit the JBOSS_HOME/standalone/configuration/standalone.xml to change the "public" and "management" interfaces to point to the hostname of your system or 0.0.0.0

Going one step further:

Form JBoss 7 on wards configuring the server and deployments can be done by admin console app (management). It runs on port number 9990 by default (http://localhost:9990/console/App.html) Which is again by default enabled for localhost, to be enable on network mode we have to run the server as follows

standalone.sh -bmanagement 0.0.0.0
(on windows as follows)
standalone.bat -bmanagement 0.0.0.0

I used to run my server as follows:




Lengthy param names are as below

-Djboss.bind.address=0.0.0.0
-Djboss.bind.address.management=0.0.0.0

Where did I apply this:

  1. At work I have got a Linux box (Performance Testing Environment) and I have to deploy my app in JBoss 7.1.1 in that box from another machine (my Laptop).
  2. One of my friends (middle-ware guy) was asked to start JBoss as said above like both the public (deployed apps) and management console app should be accessed in the same network. I suggested him to add  both parameters when running server as below and that worked like a charm.

standalone.sh -b 0.0.0.0 -bmanagement=0.0.0.0

Hope this post is useful to you, please drop in your comments.