netbeans Posts

[Netbeans] Error NoClassDefFoundError when Building Java Project using Maven

I got this error when trying to build my maven project on Netbeans,

java.lang.NoClassDefFoundError: org/apache/commons/lang/StringUtils

Here is my complete stacktrace,

Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/commons/lang/StringUtils
	at org.apache.maven.wagon.providers.file.FileWagon.resolveDestinationPath(
	at org.apache.maven.wagon.providers.file.FileWagon.resourceExists(
	at org.sonatype.aether.connector.wagon.WagonRepositoryConnector$
	at org.sonatype.aether.util.concurrency.RunnableErrorForwarder$
	at java.util.concurrent.ThreadPoolExecutor.runWorker(
	at java.util.concurrent.ThreadPoolExecutor$
Caused by: java.lang.ClassNotFoundException: org.apache.commons.lang.StringUtils
	at org.codehaus.plexus.classworlds.strategy.SelfFirstStrategy.loadClass(
	at org.codehaus.plexus.classworlds.realm.ClassRealm.loadClass(
	at org.codehaus.plexus.classworlds.realm.ClassRealm.loadClass(
	... 7 more

Looks like it happen because my maven doesnt have a StringUtils class, from apache-commons-lang library. Adding commons-lang-2.6.jar to my Netbeans maven folder (E:\Program\NetBeans 8.2\java\maven\lib\ext) solves this issue.

[PostgreSQL] Got Error “FATAL: database databasename does not exist” Despite Database is Exists on PGAdmin

Today i spent a ridiculous amount of time trying to figure out how come suddenly my java application cannot connect to postgresql database. It gives error “FATAL: database databasename does not exist”, and the weird thing is that i can browse and query to my postgresql database from PGAdmin and other database browser.

Here is my application’s complete error stacktrace

Caused by: org.postgresql.util.PSQLException: FATAL: database "geoportal" does not exist
    at org.postgresql.core.v3.ConnectionFactoryImpl.readStartupMessages(
    at org.postgresql.core.v3.ConnectionFactoryImpl.openConnectionImpl(
    at org.postgresql.core.ConnectionFactory.openConnection(
    at org.postgresql.jdbc2.AbstractJdbc2Connection.<init>(
    at org.postgresql.jdbc3.AbstractJdbc3Connection.<init>(
    at org.postgresql.jdbc3g.AbstractJdbc3gConnection.<init>(
    at org.postgresql.jdbc4.AbstractJdbc4Connection.<init>(
    at org.postgresql.jdbc4.Jdbc4Connection.<init>(
    at org.postgresql.Driver.makeConnection(
    at org.postgresql.Driver.connect(

Weird because i can see my db both from PGAdmin and psql console,
pg geoportal

pg console

When suddenly i realize when im checking my postgresql port, and i can see 2 different postgresql with different PID occupied the same port, 5432. Somehow my PGAdmin and psql connect to the right instance while my application connect to the wrong instance.

After killing my unwanted postgresql PID from taskmanager, suddenly my java application can run well again.
pg success connect

Building A Runnable Maven JavaSE Desktop Application And Including Its Jar Dependencies

Usually it’s very easy to create a runnable jar using Netbean’s ant plugin, but on this project im trying to utilize maven. One painfull thing is somehow maven is unable to build create a runnable jar file which included its jar dependencies.

After several minutes googling, i’ve found a very good solution. Here is the content of my pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="" xmlns:xsi="" xsi:schemaLocation="">

And dont forget, adding an xml file, customAssembly.xml which located on src/main/assembly/ folder

<assembly xmlns="" xmlns:xsi=""

Just build your application from Netbeans, and you will find a zip file on your Netbeans’ target folder, which consist of a runnable jar file and a lib folder containing your jar dependencies. 😉

Unable to Delete Dist Folder from Netbeans’ Build.xml File

I found this weird error when building my java application into jar from Netbeans, somehow Netbeans shows error due to unreadable dist folder. And the weird thing is, i cannot delete the dist folder manually, it keeps giving me the Folder Access Denied dialog box with choices to “Try Again” or “Cancel”. I also have tried changing permissions in the properties window but it does not seem to work.

Well the workaround is actually simple, i just open task manager, and end explorer.exe process. And i dont know why, but my dist folder is gone. Very weird actually 😀

Simulate A Post Request Using Java

Today, i’ll do a simple example on how to simulate a http post request using Apache Common Http Components. This is a usefull utility, because i use it heavily on many projects, specially to do a simple messaging between desktop clients and the server side. Very simple, very lightweight and also very reliable.

Okay, first i start with the server version of the application. I create a new WebProject on Netbeans, create a simple servlet and deploy it on tomcat. This is a very simple servlet to print on netbeans console and give response whether 0 if failed, or 1 if succeed.

package com.edw.servlet;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.log4j.Logger;

public class LoginServlet extends HttpServlet {
    private Logger logger = Logger.getLogger(LoginServlet.class);
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        try {
            String username = request.getParameter("username");
            String password = request.getParameter("password");
            logger.debug("receiving post " + username + " and " + password);
        } catch (Exception e) {

As usual, i register my servlet on web.xml.

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" xmlns="" xmlns:xsi="" xsi:schemaLocation="">

And now is my client’s side Java application.

package com.edw.postsimulator;

import java.util.ArrayList;
import java.util.List;
import org.apache.http.Consts;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.client.HttpClient;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.util.EntityUtils;

public class PostSimulator {
    // this is your target url
    private static String url = "http://localhost:8084/WebTestPost/loginServlet";
    public static void main(String[] args) throws Exception  {
        HttpClient httpclient = new DefaultHttpClient();
        HttpPost httpPost = new HttpPost(url);

        // set the parameters
        List <NameValuePair> nvps = new ArrayList<NameValuePair>();
        nvps.add(new BasicNameValuePair("username", "edwin"));
        nvps.add(new BasicNameValuePair("password", "dodol"));

        // set the encoding
        httpPost.setEntity(new UrlEncodedFormEntity(nvps, Consts.UTF_8));

        // send the http request and get the http response
        HttpResponse response = httpclient.execute(httpPost);
        HttpEntity resEntity = response.getEntity();
        // read the server's response contents

These are what is written on my Netbean’s console,

And this is my Netbean’s project configurations

Hope it helped others, Cheers :-[