Tag Archives: #java

Debugging Java Applications With IntelliJ IDEA Professional

I graduated from University of Texas with a BS in Computer Science in December of 2015 and I’ve been working for the University ever since. One of the problems I’ve encountered throughout my 3 year study is the lack of information on debugging applications. Sure you can get some fancy theoretical course on Debugging Programs, but majority of the students go through all the Computer Science courses writing damn print statements. Print statements might have been fine in the early 2000s, but come on, it’s 2016+. Please see the attached typical program
Typical CS student application

Continue reading Debugging Java Applications With IntelliJ IDEA Professional


Running the Testing framework with Saucelabs and TravisCI

Saucelabs Test Video

TravisCI Log


TravisCI Java

TravisCI Encryption

This again was pretty straight forward. After signing up with TravisCI using my GitHub account I just had to add the .travis.yml file to the repository. Make sure to configure the travis file correctly and if need to be you can also add encrypted information. I happened to commit my access key, but TravisCI does offer encryption options. I’ll just have to go back and regenerate a new one 🙂


Configuring SauceLabs with Selenium and Serenity

GitHub Example Repository

Saucelabs Selenium Test

Serenity makes life pretty easy because it integrates well with Saucelabs. It’s as simple as adding the credentials and browser information into the serenity.properties file.

A useful tool is the list of platforms. Saucelabs only provides a certain variety of OS/Browser combinations so you have to make sure to run the correct combination. Also on the Saucelabs website we can find WIN7, however in Selenium WIN7 is not a valid enum, so we have to use vista instead. Here’s the list of valid platforms directly from Selenium source.

For example:

## Firefox 
## https://saucelabs.com/beta/tests/a604701041db440697fdd7148fcc6ff3/watch

##Internet Explorer 10
## https://saucelabs.com/beta/tests/36bbc3ebb45a48fb9a97da8046aa7dfd/watch

##Internet Explorer 9
## https://saucelabs.com/beta/tests/c1ba02f7182f43f6895f0563ad843745/watch

JBehave and Selenium Testing with IntelliJ IDEA example

For the last couple of weeks I’ve been doing QA testing using Serenity, Selenium, and JBehave. I’ve been writing tests and configuring a framework to test our websites and I’m more and more convinced about the power of JBehave. You can find my learning Github repo at JBehave social example. Also for the most part I recommend using Idea IntelliJ.

Continue reading JBehave and Selenium Testing with IntelliJ IDEA example

Deploying Web applications with Ant and IntelliJ IDEA to a remote Tomcat server

Automating Deployments. Why?

Creating a New Project

Building the WAR file

Configuring Ant

Add a new user for script management


Automating Deployments. Why?

I’ve spent the last couple of days trying to automate the deployment of the CORSninja application. Up to this point it has been a manually process using Tomcat Web Manager to upload the war file. However, I wanted to automate the task as I’ve done on my NodeJS server with Git. Along the way I enountered a couple of problems, such as authorization issues with Tomcat and Ant not being familiar with the Tomcat deployment classes. These will be addressed along the way.

Creating a New Project

We’ll start of by creating a new Java Enterprise application and checking Web Application also ensure “Create web.xml” is checked.

Set the Project name to DeploymentExample.

Create a new Web Application

new Web Application

When the creation process completes, try running the application to ensure that everything is working. Pressing the green arrow will run the application and a blank page pointing at localhost:8080 should open.

Start the Web Application

Blank running App

To make it more believable let’s modify the index.jsp that can be found in the “web” folder. Between the body tags add the line

<h1> Good Bye localhost, and Hello World</h1>

Try running the app again, selecting Update Resources when the small window shows up. Selecting Update Resources streamlines the update process, however when more complex changes are made you’ll need to redeploy the app.

Update resources

Good Bye localhost, Hello World

Building the WAR file

We now need to create the WAR file that will be deployed. By default the IntelliJ Make Project creates an “exploded artifact”, but we’ll need an “Archive” (WAR) artifact for deployment.

Open the File->“Project Structure” (⌘ 😉 dialog and select “Artifacts.” Click the + button to add a new Artifact in the menu that opens select “Web Application: Archive” and “For …. exploded”.

For Deployment

On the following screen change “Name:” to “DeploymentExample:war” and modify the Output directory to /Users/…./out as in the picture. Ensure Build on Make is checked.

Change the output deployment

Click OK to close the dialog.

In the top right corner click on “Tomcat… ” and select “Edit Configuration”. In the new dialog navigate to Deployment and remove the exploded artifact by pressing – .

Now we add the new WAR artifact by pressing the + button and selecting Artifact. In the pop up select “DeploymentExample:war”. Now on every build the WAR file will be generated.

Now we create the war file by either pressing the Make Project (Green arrow with 011001) or the run button.

Either way in the Project Structure tree you should see a red “out” folder,expand it, and you should see the .war file. This file will need to be deployed.

Deployment WAR

This WAR file will be sent to the remote Tomcat server. If you don’t already have a Tomcat instance installed on the remote server you can follow this great Digital Ocean tutorial.
How To Install and Configure Apache Tomcat on a Debian Server.

Add a new user for script management

With Tomcat installed on the remote server add a new user with the manager-script role. The first day I spent a good couple of hours troubleshooting the Ant deployment because I tried adding all the roles under one user. This was fixed by adding a new seperate user with the manager-script role.

Using vim or your favorite editor open the tomcat-users.xml file, usually located at /var/lib/tomcat7/conf/.

vim  /var/lib/tomcat7/conf/tomcat-users.xml

Adding a new user with manager-script role

Save the file and restart the Tomcat service with

service tomcat7 restart

Configuring Ant

With Tomcat configured and ready to accept the WAR file. We’ll need to create the Ant build. Start off by creating a build.xml and a property file build.properties that will store the credentials.

Right click on the root project and select New -> File and name it build.xml.
Repeat the process to create a file named build.properies.

New -> File
Root Directory with build.xml and build.properties


The build.properties file will include the credentials and access information to the Tomcat instance. This file will usually be included in the .gitignore for security, so the credentials are not accidently distributed. Notice that the Tomcat Manager URL needs to end with /text

#build.properties file


Now we edit the build.xml file. This serves a similar purpose to the Unix makefiles. Specifies certain targets and actions. We willl create 5 specific targets that will allow us to deploy, undeploy, stop, and start the application.

This is typically a copy and paste template that won’t change much.

<?xml version="1.0" encoding="UTF-8"?>
 <project name="DeploymentExample" default="war" basedir=".">
     <property file="build.properties" />
    <property name="war-file-name" value="DeploymentExample_war.war" />
         <property name="target-directory" value="out/"/>

<tstamp prefix="build-info">
     <format property="current-date" pattern="d-MMMM-yyyy" locale="en" />
     <format property="current-time" pattern="hh:mm:ss a z" locale="en" />
   <format property="year-month-day" pattern="yyyy-MM-dd" locale="en" />

<taskdef name="start" classname="org.apache.catalina.ant.StartTask" />
<taskdef name="stop" classname="org.apache.catalina.ant.StopTask" />
<taskdef name="deploy" classname="org.apache.catalina.ant.DeployTask" />
<taskdef name="undeploy" classname="org.apache.catalina.ant.UndeployTask" />

<target name="stop" description="stop application in tomcat">
    <echo message="${tomcat-manager-password} ${tomcat-manager-username}" />
        path="/${project-name}" />

<target name="start" description="start application in tomcat">
    <start url="${tomcat-manager-url}" 
                path="/${project-name}" />

<target name="undeploy" description="undeploy from tomcat">

<target name="deploy" description="deploy to tomcat">
    <echo>deploying from client</echo>

<target name="build-and-deploy" depends="undeploy, deploy, start" />

Once we have the build.xml file we need to link it to IntelliJ. We can do that by openning the Ant Build panel located on the right side and pressing the + add button.

Click on the Ant Build to open the builder

If the dialog isn’t pointing towards the correct directory press the Project Directory icon (Blue IntelliJ icon, 3rd from the left). Double click the build.xml file to link it.

Find the build.xml file

Once added you will see the targets included with the build.xml file.

Targets included with the build.xml file

If you try executing any of the targets at this point, you’ll receive the following error.
TaskDef not found
…DeploymentExample/build.xml:15: taskdef class org.apache.catalina.ant.StartTask cannot be found …

To remedy this we need to include the Tomcat Catalina library for Ant. This can either be imported via pom.xml, imported using File -> Project Structure, or if you already have Tomcat installed on the machine you can find them in the Tomcat directory. You might want to check the External libraries folder, if it’s already included there.

Find the Tomcat libraries

Once you find the Tomcat libraries just right click catalina-ant.jar and select Copy Path.

Select Copy Path

Now it’s time to include them in the Ant’s Classpath. Go back to the Ant Build panel and right click on the main item and select Properties.

Ant Build panel and select Properties

Navigate to Additional Classpaths and select “Add All in Directory”. Paste the path to the Tomcat library folder, and erase the file name so it’s pointing to the /lib folder. It’ll automatically link all the jars Ant needs.

Select the tomcat lib directory

classpaths -> lib folder included


Now we make a couple of last changes to the build.xml file.

<property name="war-file-name" value="DeploymentExample_war.war" />

change the value to the appropriate war filename. For example “DeploymentExample_war.war”

Finally, in the Ant Build panel double click on “deploy” and “start”. If you get no console output or error notifications the deployment was succesful, so try logging into the Tomcat Web Manager.

DeploymentExample succesfully deployed.

If Ant start was executed, the application will be already started. To open the website in the Topcat Web Manager click on the Application you just deployed. This will open the app we have just deployed.

Running web application

If you receive ……DeploymentExample/build.xml:23: java.io.IOException: Server returned HTTP response code: 401 for URL: http://cors.ninja:8080/manager/text/stop?path=%2FDeploymentExample. Try going back to here and restarting Tomcat7 or verifying the new user was added to tomcat-users.xml.