• Enter Slide 1 Title Here

    This is slide 1 description. Go to Edit HTML of your blogger blog. Find these sentences. You can replace these sentences with your own words.

  • Enter Slide 2 Title Here

    This is slide 2 description. Go to Edit HTML of your blogger blog. Find these sentences. You can replace these sentences with your own words.

  • Enter Slide 3 Title Here

    This is slide 3 description. Go to Edit HTML of your blogger blog. Find these sentences. You can replace these sentences with your own words.

Showing posts with label Tools. Show all posts
Showing posts with label Tools. Show all posts

Thursday, August 24, 2017

Without root/sudo permission install Node.js on Linux/CentOS

Node.js is a free and open source JavaScript runtime for server side programming. For *nix environments, users can do installations with RPMs or via package managers like yum. However, most often developers face restrictions during installation due to the need of root permission for directories like "/usr/local/bin". Here, we will be installing Node.js inside a directory under user_home.

1. Download binary distribution

Latest binaries can be downloaded from Node.js official release directory.

https://nodejs.org/download/release/
For CentOS 6.7, I downloaded Linux 64-bit binary of latest version (8.4.0) from below link.
https://nodejs.org/download/release/v8.4.0/node-v8.4.0-linux-x64.tar.gz
Make sure to pick suitable binary for your installation.

2. Extract into installation directory

This binary file must be extracted into the directory that you are installing Node.js. In my machine, I extracted it into below directory.
/home/user/software/nodejs_v8.4.0/

3. Add Node.js to PATH

It is required to append Node.js installation to PATH variable. For that, you can update either ~/.bash_profile or ~/.bashrc file as below.

export NODEJS_HOME=/home/user/software/nodejs_v8.4.0
export PATH=$PATH:$NODEJS_HOME/bin

4. Verify installation

Open up a console and check Node.js version to verify the installation as below.

bash$ node --version
v8.4.0
If you see the installed version as v8.4.0, that confirms the installation is completed. For this we did not use any additional *inx user privileges.

Related Articles

Tuesday, August 22, 2017

[Solved] Nginx - error: HTTP rewrite module requires the PCRE library

Nginx $ ./configure: error: the HTTP rewrite module requires the PCRE library. While trying to install Nginx server using the source distribution, "./configure" command failed on CentOS 6.7 with below error message. It complains that PCRE library is not available on the system.

./configure: error: the HTTP rewrite module requires the PCRE library.
You can either disable the module by using
--without-http_rewrite_module option, or
install the PCRE library into the system,
or build the PCRE library statically from
the source with nginx by using --with-pcre=<path> option.

Solution

You can install this library either via command line or GUI.

Resolve via Command line

yum install pcre-devel

Resolve via GUI

Go to "System" -> "Administration" -> "Add/Remove Software" as shown below.

Then search for "pcre-devel", select "Development files for pcre" and install by clicking "Apply" as shown below.
After that, you can rerun the "./configure" command to continue installing Nginx 1.12.1 server.
Hope this helps.

Related Articles

Tuesday, November 19, 2013

[Eclipse] How to use local DTDs to validate XMLs

By default Eclipse does not support local DTD files. Because of this, many developers loose a privilege of Eclipse; content assistance for parameter/attribute is missing while working with DTD based XML files. However if you are connected to Internet, you will not face this issue.

Here is a tip to show you how to point your Eclipse instance to local DTD files.

1. Add XML Catalogs

First you need to open up the "XML Catalog" dialog by:
Windows -> Preferences -> XML -> XML Catalog
Then click on "Add..." and select "Catalog Entry". For a single local DTD file you need to add one Catalog Entry.

For the location: you need to find DTD file from your local disk.
For the Key: you need to enter the relevant key as per the <!DOCTYPE entry of your XML files.

2. Hibernate Examples Demo

This tip is demoed using Hibernate as an example. Hibernate Configuration DTD and Hibernate Mappings DTD is added locally into Eclipse below. First of all, you need to download and store hibernate jar file somewhere in your local disk; we used hibernate-core-3.6.10.Final version (available here as well as here).

2.1 Hibernate Configuration DTD

DTD file referred by hibernate.cfg.xml file is "hibernate-configuration-3.0.dtd". To point eclipse to that DTD, you need to enter below values and select OK in above "Catalog Entry" screen.


Key: -//Hibernate/Hibernate Configuration DTD 3.0//EN
Location: jar:file:/<path/to/jar>/hibernate-core.jar!/org/hibernate/hibernate-configuration-3.0.dtd

Then Eclipse will create a new Catalog and save with below details.

Entry element: Public
Location: org/hibernate/hibernate-configuration-3.0.dtd in jar file opt/libs/hibernate-core.jar
URI: jar:file:/opt/libs/hibernate-core.jar!/org/hibernate/hibernate-configuration-3.0.dtd
Key type: Public ID
Key: -//Hibernate/Hibernate Configuration DTD 3.0//EN

2.2 Hibernate Mappings DTD

DTD file referred by <entity>.hbm.xml file is "hibernate-mapping-3.0.dtd". Same as above step, in "Catalog Entry" screen you need to enter below values and select OK.

Eclipse will create a new Catalog and save with below details.

Entry element: Public
Location: org/hibernate/hibernate-mapping-3.0.dtd in jar file opt/libs/hibernate-core.jar
URI: jar:file:/opt/libs/hibernate-core.jar!/org/hibernate/hibernate-mapping-3.0.dtd
Key type: Public ID
Key: -//Hibernate/Hibernate Mapping DTD 3.0//EN

2.3 Results


After creating the Catalogs, you can check this my opening your hibernate.cfg.xml file and trying to open up the DTD file link in the top of the file by "Ctrl + Mouse Over". You will notice that Eclipse prompts two links and one is the local DTD.

Similarly, Eclipse will provide content assistance for XML file editing even when internet connectivity is gone.

3. Conclusion

Using this method, you can create catalogs for any DTD and let Eclipse point to your local DTD files. Hope this helps you.

Thursday, November 7, 2013

[Eclipse] Exporting & Importing Launch configurations

Many Eclipse "Launch Configuration" created has so much details; OSGi configurations for instance. So there arises a requirement of exporting the launch configurations and later importing them into other Eclipse workspaces. Interestingly, Eclipse has an import/export feature for "Launch Configuration"; which is quite simple but handy. I believe some software developers are not taking the advantage of this.

Here are the steps to follow.

1. Exporting Configurations

First you need to select:
  File -> Export...
Then select:
  Run/Debug -> Launch Configurations

Then you will see a view with all available launch configurations as shown below. You can select the configurations you need to export. You need a provide a location to store the exported configurations.

Each configuration will be saved into separate XML files, but with the extension as ".launch".

2. Importing Configurations

Similar to export, first you need to select:
  File -> Import...
Then select:
  Run/Debug -> Launch Configurations

Then you will see a view where you can select a directory with ".launch" files. When that folder is selected, available launch configurations will be displayed in the UI; so that you can select which ones to be imported as shown below.

3. Sample .launch file

Below is the exporter file for the OSGi launch configuration we created for Eclipse Kepler 4.3.1.
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<launchConfiguration type="org.eclipse.pde.ui.EquinoxLauncher">
<booleanAttribute key="append.args" value="true"/>
<booleanAttribute key="automaticAdd" value="true"/>
<booleanAttribute key="automaticValidate" value="false"/>
<stringAttribute key="bootstrap" value=""/>
<stringAttribute key="checked" value="[NONE]"/>
<booleanAttribute key="clearConfig" value="false"/>
<stringAttribute key="configLocation" value="${workspace_loc}/.metadata/.plugins/org.eclipse.pde.core/Multi-Management-App"/>
<booleanAttribute key="default" value="true"/>
<booleanAttribute key="default_auto_start" value="true"/>
<intAttribute key="default_start_level" value="4"/>
<booleanAttribute key="includeOptional" value="true"/>
<booleanAttribute key="org.eclipse.jdt.launching.ATTR_USE_START_ON_FIRST_THREAD" value="true"/>
<stringAttribute key="org.eclipse.jdt.launching.JRE_CONTAINER" value="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>
<stringAttribute key="org.eclipse.jdt.launching.PROGRAM_ARGUMENTS" value="-os ${target.os} -ws ${target.ws} -arch ${target.arch} -nl ${target.nl} -consoleLog -console"/>
<stringAttribute key="org.eclipse.jdt.launching.SOURCE_PATH_PROVIDER" value="org.eclipse.pde.ui.workbenchClasspathProvider"/>
<stringAttribute key="org.eclipse.jdt.launching.VM_ARGUMENTS" value="-Declipse.ignoreApp=true -Dosgi.noShutdown=true"/>
<stringAttribute key="pde.version" value="3.3"/>
<booleanAttribute key="show_selected_only" value="true"/>
<stringAttribute key="target_bundles" value="org.apache.felix.gogo.command@default:default,org.apache.felix.gogo.runtime@default:default,org.apache.felix.gogo.shell@default:default,org.eclipse.equinox.console@default:default,org.eclipse.osgi@-1:true"/>
<booleanAttribute key="tracing" value="false"/>
<booleanAttribute key="useCustomFeatures" value="false"/>
<booleanAttribute key="useDefaultConfigArea" value="true"/>
<stringAttribute key="workspace_bundles" value="com.digizol.osgi.multiservice.english@default:default,com.digizol.osgi.multiservice.sinhala@default:default,com.digizol.osgi.multiservice@default:default,com.digizol.osgi.baseservice@default:default"/>
</launchConfiguration>

Hope this helps you.

Wednesday, November 6, 2013

[Eclipse] org.osgi.framework.BundleException: Could not find bundle: org.eclipse.equinox.console

With latest Eclipse Kepler 4.3.1 SR1, I tried to run one of my older OSGi projects. Earlier this project was running smoothly with Eclipse Indigo (3.7.1).

However, when I tried to execute it via Eclipse Kepler version as a "OSGI Framework" configuration; I was surprised since it showed an exception as org.osgi.framework.BundleException: Could not find bundle: org.eclipse.equinox.console .

Below is the complete stack-trace.

!SESSION date time -----------------------------------------------
eclipse.buildId=unknown
java.version=1.6.0_26
java.vendor=Sun Microsystems Inc.
BootLoader constants: OS=linux, ARCH=x86, WS=gtk, NL=en_US
Command-line arguments: -dev file:$Location/dev.properties -os linux
-ws gtk -arch x86 -consoleLog -console

!ENTRY org.eclipse.osgi 4 0 date time
!MESSAGE Could not find bundle: org.eclipse.equinox.console
!STACK 0
org.osgi.framework.BundleException: Could not find bundle: org.eclipse.equinox.console
at org.eclipse.osgi.framework.internal.core.ConsoleManager.checkForConsoleBundle(ConsoleManager.java:211)
at org.eclipse.core.runtime.adaptor.EclipseStarter.startup(EclipseStarter.java:298)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:177)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:636)
at org.eclipse.equinox.launcher.Main.basicRun(Main.java:591)
at org.eclipse.equinox.launcher.Main.run(Main.java:1450)
at org.eclipse.equinox.launcher.Main.main(Main.java:1426)

Solution

A quick look into the details revealed that the default shell of Eclipse has been moved to "Apache Felix Gogo"; so the necessary bundles must be added to the "Run Configuration" before running. Followings are the four bundled that you need to select from the list.

org.apache.felix.gogo.command_0.10.0v<version>.jar
org.apache.felix.gogo.runtime_0.10.0v<version>.jar
org.apache.felix.gogo.shell_0.10.0v<version>.jar
org.eclipse.equinox.console_1.0.100<version>.jar

After adding these as shown in the above diagram, the program runs smoothly.

For more details on the changes on OSGi shell, please refer here.

Monday, November 4, 2013

OSGi Console of Eclipse Kepler 4.3.1

Eclipse IDE is developed based on OSGi plugin architecture, but I had not seen the list of OSGi bundles that are used in my Eclipse installation. Today I noticed that there is a way to find the list of bundled used, and it is quite simple. So I thought of sharing it with you.

I am running Eclipse version 4.3.1 (JEE Kepler). First we need to open the OSGi console of the running Eclipse instance. For that we need to open up the 'Console view' first via:

Window -> Show view -> Console

Then you need to select "Host OSGi Console" on the sub-toolbar in this Console view as shown in the image below.
As soon as you go to this console view, you will see below WARNING, which is quite OK since our intention is also to connect to the running instance of Eclipse.
WARNING: This console is connected to the current running instance of Eclipse!
osgi>

If you are already familiar with OSGi console in OSGi software development, then most likely you know how to find details about the plugins. However even if you are new to OSGi, no need to worry. You simple have to enter "ss" command in this console to see the list of bundles with id and state. I got a list of 822 plugins and below is a trimmed down version of the output I received.

WARNING: This console is connected to the current running instance of Eclipse!
osgi> ss
"Framework is launched."


id State Bundle
0 ACTIVE org.eclipse.osgi_3.9.1.v20130814-1242
1 ACTIVE org.eclipse.equinox.simpleconfigurator_1.0.400.v20130327-2119
2 RESOLVED ch.qos.logback.classic_1.0.7.v20121108-1250
Fragments=525
3 RESOLVED ch.qos.logback.core_1.0.7.v20121108-1250
4 RESOLVED ch.qos.logback.slf4j_1.0.7.v20121108-1250
Master=817
5 ACTIVE com.ibm.icu_50.1.1.v201304230130
6 RESOLVED com.jcraft.jsch_0.1.46.v201205102330
7 RESOLVED com.ning.async-http-client_1.6.5.20130531-2315
8 RESOLVED com.sun.el_2.2.0.v201303151357
9 RESOLVED com.sun.syndication_0.9.0.v200803061811
10 RESOLVED java_cup.runtime_0.10.0.v201005080400
11 RESOLVED javaewah_0.5.6.v201307211000
12 RESOLVED javax.activation_1.1.0.v201211130549
13 RESOLVED javax.annotation_1.1.0.v201209060031
14 RESOLVED javax.el_2.2.0.v201303151357
15 RESOLVED javax.inject_1.0.0.v20091030
16 RESOLVED javax.jws_2.0.0.v201005080400
17 RESOLVED javax.mail_1.4.0.v201005080615
18 RESOLVED javax.persistence_2.1.0.v201304241213
19 RESOLVED javax.servlet_3.0.0.v201112011016
20 RESOLVED javax.servlet.jsp_2.2.0.v201112011158
21 RESOLVED javax.wsdl_1.6.2.v201012040545
22 RESOLVED javax.wsdl_1.5.1.v201012040544
23 RESOLVED javax.xml_1.3.4.v201005080400
24 RESOLVED javax.xml.bind_2.1.9.v201005080401
25 RESOLVED javax.xml.rpc_1.1.0.v201209140446
26 RESOLVED javax.xml.soap_1.2.0.v201005080501
27 RESOLVED javax.xml.stream_1.0.1.v201004272200
28 RESOLVED javax.xml.ws_2.1.0.v200902101523
29 RESOLVED net.sourceforge.lpg.lpgjavaruntime_1.1.0.v201004271650
30 RESOLVED org.apache.ant_1.8.4.v201303080030
31 RESOLVED org.apache.axis_1.4.0.v201005080400
32 RESOLVED org.apache.batik.css_1.6.0.v201011041432
33 RESOLVED org.apache.batik.util_1.6.0.v201011041432
34 RESOLVED org.apache.batik.util.gui_1.6.0.v201011041432
35 RESOLVED org.apache.bcel_5.2.0.v201005080400
36 RESOLVED org.apache.commons.codec_1.4.0.v201209201156
37 RESOLVED org.apache.commons.collections_3.2.0.v2013030210310
38 RESOLVED org.apache.commons.discovery_0.2.0.v201004190315
39 RESOLVED org.apache.commons.httpclient_3.1.0.v201012070820
40 RESOLVED org.apache.commons.io_2.0.1.v201105210651
41 RESOLVED org.apache.commons.lang_2.6.0.v201205030909
42 RESOLVED org.apache.commons.logging_1.1.1.v201101211721
43 RESOLVED org.apache.commons.logging_1.0.4.v201101211617
44 RESOLVED org.apache.commons.net_3.2.0.v201305141515
45 ACTIVE org.apache.felix.gogo.command_0.10.0.v201209301215
46 ACTIVE org.apache.felix.gogo.runtime_0.10.0.v201209301036
47 ACTIVE org.apache.felix.gogo.shell_0.10.0.v201212101605
48 RESOLVED org.apache.httpcomponents.httpclient_4.1.3.v201209201135
49 RESOLVED org.apache.httpcomponents.httpcore_4.1.4.v201203221030
50 RESOLVED org.apache.jasper.glassfish_2.2.2.v201205150955
51 RESOLVED org.apache.log4j_1.2.15.v201012070815
52 RESOLVED org.apache.lucene.analysis_3.5.0.v20120725-1805
53 RESOLVED org.apache.lucene.core_3.5.0.v20120725-1805
54 RESOLVED org.apache.velocity_1.5.0.v200905192330
55 RESOLVED org.apache.ws.commons.util_1.0.1.v20100518-1140
56 RESOLVED org.apache.wsil4j_1.0.0.v200901211807
57 RESOLVED org.apache.xalan_2.7.1.v201005080400
58 RESOLVED org.apache.xerces_2.9.0.v201101211617
59 RESOLVED org.apache.xml.resolver_1.2.0.v201005080400
60 RESOLVED org.apache.xml.serializer_2.7.1.v201005080400
61 RESOLVED org.apache.xmlrpc_3.0.0.v20100427-1100
62 STARTING org.eclipse.ant.core_3.2.500.v20130402-1746
63 STARTING org.eclipse.ant.launching_1.0.300.v20130514-1341
64 STARTING org.eclipse.ant.ui_3.5.400.v20130514-1341
65 STARTING org.eclipse.compare_3.5.401.v20130709-1308
66 STARTING org.eclipse.compare.core_3.5.300.v20130514-1224
67 RESOLVED org.eclipse.core.commands_3.6.100.v20130515-1857

...

818 RESOLVED org.sonatype.m2e.mavenarchiver_0.15.0.201207090125-signed-20130612210623
819 RESOLVED org.uddi4j_2.0.5.v200805270300
820 RESOLVED org.w3c.css.sac_1.3.1.v200903091627
821 RESOLVED org.w3c.dom.smil_1.0.0.v200806040011
822 RESOLVED org.w3c.dom.svg_1.1.0.v201011041433
osgi>
If you are interested in finding further details about these OSGi bundles, you can enter 'help' in the OSGi console and find the list of commands to try out.

[Ubuntu] Multiple launchers for each individual Eclipse installation

I have multiple Eclipse versions installed in my Ubuntu 12.04, so I wanted to have separate launcher icons in Launchpad. However I noticed it is not possible to create launch icons simply using:
"Right click -> Lock to Launcher" approach since the same launcher icon is used for all Eclipse installations; simply said there will be only one launcher icon for all Eclipse installations. 


It is quite easy to create multiple launcher icons for multiple installations. Below is the 4 steps you need to follow.

1. Create <eclipse-name>.desktop files for each installation

I created eclipse-jee-kepler.desktop file inside Kepler Eclipse installation folders, but you use any preferred location.

2. Update <eclipse-name>.desktop file with information

For "Eclipse JEE Kepler" installation, add the below content to eclipse-jee-kepler.desktop. You will have to change the path to the executable eclipse file.
[Desktop Entry]
Version=4.3.1
Name=Eclipse JEE Kepler
Comment=Eclipse JEE Kepler
Exec=/<path>/eclipse-jee-kepler-SR1-linux-gtk/eclipse
Icon=/<path>/eclipse-jee-kepler-SR1-linux-gtk/eclipse.ico
StartupNotify=false
Terminal=false
Type=Application
Categories=Development

You can create an eclipse.ico file to be displayed in the Launchpad yourself. As displayed here, I have created a simple file for my usage.

3. Grant permission to execute

Right click on this eclipse-jee-kepler.desktop file and select "Properties". Then go to the "Permissions" tab and select execute permission as shown in the image.

4. Run the eclipse installation

You can double click on the eclipse-jee-kepler.desktop file to start your eclipse installation. When this eclipse installation is started, the provided eclipse.ico will be displayed in the Launchpad. Now you can create a launch icon simply using "Right click -> Lock to Launcher".

Finally...

For each of your eclipse installations, you can create separate files with above 4 steps; then replace the property values to match with each eclipse installations (including a separate .ico).

If you are interested in finding more information about Unity Launchers and Desktop files, you can refer here.

Monday, October 28, 2013

[Jenkins] Automatically retry a failed build

Are your Jenkins builds failing due to unavoidable reasons like unavailability of external databases, file systems etc? The only solution you might be having right now is to reschedule the build after fixing that external issue. In this post, I will be discussing on how you can automatically rerun a failed build.

Setup

For this, we are going to use a plugin named Naginator, version 1.8 is available here for download. As the first step, please install this plugin into your Jenkins.

When it is installed, there will be a new action named "Retry build after failure" added to the post-build action list in job configuration page (as shown).

Configuration

First create a new job. If you need to retry an existing job, please open the job configuration page. Then click on the "Add post-build action" button and select "Retry build after failure". This will add a new configuration section as shown in the below image.


There are 3 configuration settings (as numbered in above image). Let's discuss each in details below.

Setting 1 -> Rerun build for unstable builds as well as failures

This option is there to indicate whether you should be retrying the UNSTABLE state builds as well in addition to FAILURE state builds. Let's set it to true.

Setting 2 -> Delay before schedule

This allows you to define how long to delay a retrying build start-time from the time it was failed. There are two options to choose from; one is to provide a "fixed period" and the other is to provide an "increasing period". Let's use fixed period; and set 300 there (meaning 5 mins).

Setting 3 -> Max number of successive failed build

This is used to control the number of continuous failure builds. Jenkins will not automatically retry more than this maximum number of consecutive failures. So let's set 2 there so that it is retried only two times.

Conclusion

As expected, this is working without any issues and stops retrying as soon as the build is successful. Hope this will help you in avoiding manual retries.

Wednesday, October 16, 2013

[Log4j] How to integrate with your Java project

This is a quick guide on how to use log4j in your Java project. This task requires only five simple steps listed below. Each of these step is explained in details below.

  1. Set up the project with log4j
  2. Create log4j.properties file
  3. Write a class to record log messages
  4. Compile and run program
  5. Check the log messages

1. Set up the project with log4j

As the first step, let's download the log4j 1.2.17 latest archive (tar or zip). When you extract the archive, log4j-1.2.17.jar file is available in the root of the directory.

Let's create a new project named say log4j-helloworld and copy the log4j-1.2.17.jar into a folder named lib inside the project.

2. Create log4j.properties file

Next task is to create a log4j.properties file (shown below) inside the project folder. This file is the configuration file that provides how, where, which etc instructions on generating log messages.


# root level configurations
log4j.rootLogger=INFO,console,file

# configuration for console outputs
log4j.appender.console=org.apache.log4j.ConsoleAppender
log4j.appender.console.layout=org.apache.log4j.PatternLayout

# configuration for file output (into a file named messages.log)
log4j.appender.file=org.apache.log4j.RollingFileAppender
log4j.appender.file.File=messages.log
log4j.appender.file.layout=org.apache.log4j.PatternLayout

# threshold for file output
log4j.appender.file.Threshold=ERROR

3. Write a class to record log messages

Let's write a simple class named Main (in src folder) with a main method to generate some log statements. Logger is added to the class as an attribute and used to write logs of different levels like debug, info and error.

package com.digizol.log4j.helloworld;

import org.apache.log4j.Level;
import org.apache.log4j.Logger;

public class Main {

private static Logger log = Logger.getLogger(Main.class);

public static void main(String[] args) {

log.debug("This is debug method");
log.info("This is info method");
log.error("This is error method");

log.log(Level.DEBUG, "This is debug from Level.DEBUG");
log.log(Level.INFO, "This is info from Level.INFO");
log.log(Level.ERROR, "This is error from Level.ERROR");

}
}

4. Compile and run program

If you compile and run from command line, followings are the commands. Make sure to create classes folder inside project for generated class files before executing the commands.


# compile
javac -cp lib/log4j-1.2.17.jar -d classes -sourcepath src src/com/digizol/log4j/helloworld/Main.java

# run
java -cp lib/log4j-1.2.17.jar:./classes:./ com.digizol.log4j.helloworld.Main

If you are using an IDE like Eclipse, you can simply add log4j jar file into the build path before compiling. When running the Main class, you need to give the path to log4j.properties file in run configuration.

5. Check the log messages

In the Main class, we have added two debug level messages. However the rootLogger is configured in INFO level in log4j.properties file, so none of the debug level log messages are expected as outputs.

Console output as as below.

This is info method
This is error method
This is info from Level.INFO
This is error from Level.ERROR

Console has received both INFO and ERROR log messages, but not DEBUG.

However messages.log file has received only the ERROR level log messages as below.

This is error method
This is error from Level.ERROR

This is because the Threshold level of the file logging appender is set to ERROR which overrides the rootLogger configuration.

Hope this helps you to start using log4j in your next project. I have added this project here for your references.

Tuesday, September 17, 2013

Find which process holds a port number in Linux

Here is a simple tip to find out the process that has bounded a given port number. java.net.BindException: Address already in use - this is an error log message that software developers and deployment engineers encounter quite often since the same application or process is already running in the background occupying the port. Below we will locate a process based on the port.

1. Finding the process that holds the port

lsof -i <Internet address>

Let's find the process using the port "8080"

$ lsof -i :8080
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
java 14124 kamal 35u IPv4 18493 0t0 TCP *:http-alt (LISTEN)

If needed, we can extract just the PID by leaving out all other information as shown below.

$ lsof -i :8080 -t
14124

PID above is the process id that uses the port 8080.

Using this PID, you can view the process details using following command.

ps u -p <PID>

Let's find the process details of PID 14124

$ ps u -p 14124
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
kamal 14124 6.6 7.2 2399340 588220 pts/0 Sl+ 10:39 1:01 /usr/lib/jvm/java-6-sun/bin/java

2. Terminating the process using the process id

A process can be terminated using the kill command.

kill -9 <PID>

Let's kill the above process as follows.

$ kill -9 14124

Hope this helps, also make sure you read details of "lsof" command for further details.

Tuesday, September 10, 2013

[Ubuntu] DeVeDe generated DVD menus not working

DeVeDe is a popular software for DVD creation, and I am using 3.21.0 version of that on Ubuntu 12.04 to generate DVDs from different files of .avi, .mpg and .mp4 types. However after the upgrade to Ubuntu 12.04, I was facing issues with the menus of generated DVD. Recently, I noticed that this is due to an incompatibility issue with ffmpeg solution provided by Ubuntu (detailed bug is found here).

Simplest workaround for this issue is to avoid the use of ffmpeg, and interestingly DeVeDe provides an option to do this.

Go to "Edit -> Preferences"
then uncheck "Use FFMPEG instead of Mencoder" as shown in the below image.

That setting will resolve this problem.

Wednesday, October 12, 2011

Firefox Address (Location) Bar Hidden or Missing

Firefox Address bar (or Location bar) is not visible suddenly and browser looks some what similar to the image shown here. Though Navigation bar is visible; there is no space to enter a URL? Sometimes users face this issue though it is not that common. This article shows how to resolve the issue; considering the user is not an expert in configuring Firefox.

Steps:
  1. Right click on area marked as "1".
  2. Select Customize... (marked as "2").
  3. Select the "Location" item from the pop up "Customize Toolbar" dialog box.
  4. Drag and drop "Location" item to the area marked as "3".
  5. Firefox itself will place the location bar correctly as earlier.


If you wish to restore all defaults items on the Firefox browser, use the "Restore Default Set" button in "Customize Toolbar" dialog box.

Related: Google redirect to incorrect country domain: Fix on Firefox

Wednesday, October 20, 2010

Thunderbird 3.1.5 Release with Critical security fixes

Mozilla Thunderbird 3.1.5 version released today. This free and open source email client is one of the better standalone ones available. Since development is done by a community of developers with the help of security experts; issue identification and resolution process is so efficient. Thunderbird 3.1.5 can be downloaded from here for any platform (Windows, Mac OS and Linux) in around fifty languages.

This release has fixes for five critical security vulnerabilities as shown below.
  • Unsafe library loading Vulnerabilities
  • Dangling pointer vulnerability in LookupGetterOrSetter
  • Use-after-free error in nsBarProp
  • Buffer overflow and memory corruption using document.write
  • Miscellaneous memory safety hazards (rv:1.9.2.11/ 1.9.1.14)

An upgrade to latest 3.1.5 version is advised to avoid any security issues. All credit goes to those great people who devote their time and effort on getting another release out.

Wednesday, July 8, 2009

Attempted to lock an already-locked dir: Subversion issue

"Attempted to lock an already-locked dir" - svn: Working copy locked; this message is frequently faced by users of SubVersion (SVN) source repository. The message is self explanatory; simply some source files are locked and no commit or update operations allowed on those files/folders. In some occasions, Software developers in a team receive this message in a SVN operation even though none of them have locked the files or folders; causing confusion. So how would you try and resolve?

We use Subversion to create and store our projects in repositories; Subclipe (an Eclipse plugin) as the client tool to connect to repository.

We tried following solutions

1. Commit Changes - change and commit changes into repository
2. File Delete - delete the files and commit the delete into repository
3. Override & update - override the local changes and update from repository

None of the above options resolved the issue, but got the same type of error messages. Followings are the error messages shown inside Eclipse while trying the above mentioned options.

commit -m C:/workspace/MyProject/config.properties
Attempted to lock an already-locked dir
svn: Working copy 'C:\workspace\MyProject' locked

update -r 13 C:/workspace/MyProject/src
Attempted to lock an already-locked dir
svn: Working copy 'C:\workspace\MyProject' locked

delete --force C:/workspace/MyProject/config.properties
Attempted to lock an already-locked dir
svn: Working copy 'C:\workspace\MyProject' locked

Use Cleanup command

Subversion:Team-CleanupSubversion supports a command named "Cleanup"; it is used to release the locks on a project.

If you have faced with the above issue while no one has locked the project files, you can run this command and resolve the issue.
You do this in Eclipse by right clicking the project; then Team->Cleanup as shown in the image.

Wednesday, November 5, 2008

Tomcat + Apache HTTP: Servers Connecting Guide

Apache Tomcat is a Servlet/JSP container and used to deploy dynamic Java contents like JSPs and Servlets. Tomcat has some web server capabilities, however it is not a full blown web server to serve high traffic web sites. In the meantime Apache HTTP server is a full blown web server. So in general Tomcat is configured along with Apache HTTP server to maintain a healthy web site with dynamic content. This article will cover the steps of configuring HTTP server and Tomcat connection, however this will not discuss installation details of Apache or Tomcat.

System Requirements

  • Apache HTTP server installed
    • download from here
    • we used version 2.2.10 for this article
  • Apache Tomcat installed
    • download from here
    • we used version 5.5 here
Short Names
Followings are the short names used to denote folders used in this article.
  • %APACHE_HTTP_HOME%
    • denotes Apache HTTP Server installation directory. In our testing machine, it is "D:\ASF\Apache"
  • %CATALINA_HOME%
    • Tomcat installation directory; for example: "D:\ASF\Tomcat"

Connection Configurations

The connection between HTTP server and Tomcat will be done using Apache Tomcat Connector module named mod_jk which is configured inside Apache HTTP server. For that first download the correct version of connector from here.

For version 2.2.10 of Apache HTTP; correct connector version is 2.2.4 (available here). Make sure to download the correct version, as incorrect version may result in errors.

Mod_jk configuration

Apache HTTP ServerNow the downloaded mod_jk module must be configured in Apache HTTP server. First rename the above downloaded file say mod_jk-1.2.26-httpd-2.2.4.so to "mod_jk.so". In Apache server, module files are stored under %APACHE_HTTP_HOME%\modules folder. Now copy the mod_jk.so file into this folder.

Then open the HTTP server configuration file named httpd.conf. It's located in %APACHE_HTTP_HOME%\conf folder. This file has a number of lines used to load Modules starting with "LoadModule ". Add the following line below these lines.

LoadModule jk_module modules/mod_jk.so

Now the downloaded mod_jk module is added into Apache server.

Tomcat Server Information

We need a new properties file to store details about the Tomcat server. Create a new file named workers.properties inside %APACHE_HTTP_HOME%\conf folder with the following content.

worker.list=localTomcat
worker.localTomcat.host=localhost
worker.localTomcat.port=8009
worker.localTomcat.type=ajp13

Pay attention to the above port 8009; this is the port defined inside %CATALINA_HOME%\conf\server.xml file as follows.

<!-- Define an AJP 1.3 Connector on port 8009 -->
<Connector port="8009" protocol="AJP/1.3" redirectPort="8443" />

Tomcat ServerIf the port in AJP 1.3 connector section of Tomcat is different than 8009, change the above workers.properties file to match that.

Now we need to configure the workers.properties file in %APACHE_HTTP_HOME%\conf\httpd.conf file. For that add the following lines after the line that we added into httpd.conf in a previous step.

JkWorkersFile conf/workers.properties
JkShmFile logs/mod_jk.shm
JkLogFile logs/mod_jk.log

Now everything is setup. However still we have not yet defined the important part; which user requests to be forwarded to Tomcat server from Apache server.

URL Patterns

Following is the format of those configurations.

JkMount  <URL_PATTERN>  <WORKER>
  • <URL_PATTERN> - the url pattern that you need to forward to Tomcat
  • <WORKER> - the worker name defined in workers.properties file.
We can set up multiple url patterns as follows.

JkMount  /myProject/* localTomcat
JkMount /*.jsp localTomcat
JkMount /*.do localTomcat

First one will send all requests for a web application named "myProject" to Tomcat while the second will send all requests ending with ".jsp". The third line configures for all requests ending with ".do" (many use .do extension with Struts actions).

Add required configuration lines as above into httpd.conf (just after the lines we added in above steps).

Setup Completed

Now try the URLs of your application as follows (using Apache port number, rather than Tomcat port number). We assumed Apache HTTP server is running on port 80. Following as some sample urls for the above configurations.

http://localhost/myProject/
http://localhost/testApp/main/admin.jsp
http://localhost/strutsApp/login.do

Now Apache will direct all these request to Tomcat (running on a different port) and serve the client smoothly.

Related Article: How to change Tomcat port

Related Article

Tuesday, September 16, 2008

Sun suspends NetBeans IDE DVD Starter Kit distribution program

Sun has suspended their NetBeans IDE DVD Starter Kit distribution program indefinitely. Yes, you read it correctly; they have done it. So many developers used to get most of Sun (free) products through the distribution program. Students with less bandwidth (in some colleges & universities); specially users without Internet access to home computers are fond of this service as NetBeans DVDs are freely delivered to their hands at no cost.

According to NetBeans.org;
"Since August 30th, 2005, NetBeans.org has shipped more than 225,000 CDs & DVDs to developers around the world through this initiative! During this period, NetBeans has experienced explosive growth as a download, media kit, and a community. To stay ahead of this encouraging trend we are looking into ways to effectively satisfy increasing demand for NetBeans software worldwide."

For sure this service played a huge role in helping so many Java developers. Also the program is a good marketing option for NetBeans since Eclipse (the best free Java IDE) provides no such services, rather than allowing free download. Sun also has decided to follow the same; stick only for free downloads. However the Starter Kit is available for download as an ISO image. In near future may offer downloads via mirrors and bit torrent; but not sure how near that future is. Anyway we are grateful to service Sun provided us.

Tuesday, September 9, 2008

[Eclipse] Access restriction: Class is not accessible due to restriction on required library

"Access restriction: Class is not accessible due to restriction on required library"; error message may be shown while developing Java projects in Eclipse IDE. Error message is self-explanatory, some classes can not be loaded into the project since restriction rules are being imposed on those classes.

How to solve

This error message can be removed by changing a setting inside Eclipse IDE. Open up the dialog box shown below, using any of the following paths.
  • Windows -> Preferences -> Java -> Compiler -> Errors/Warnings
  • (Project) Properties -> Java Compiler -> Errors/Warnings
Locate the "Forbidden reference (access rules)" option under "Deprecated and restricted API" section in the dialog box. This option decides how to handle access rules defined inside Eclipse. By default it is set to "Error" which causes Eclipse to complain about references to any restricted classes. Choosing any other option (Warning or Ignore) will remove these error messages.

"Warning" or "Ignore" options will only hide the potential issue in the project, by allowing the project to use any classes ignoring predefined access rules. To completely resolve this issue, analyze the project and located the use of restricted classes and take necessary actions (either remove those references or access rules).

Related Articles

Thursday, September 4, 2008

Chrome or Firefox - which browser to choose?

Chrome is the newest baby in browser family or the next competitor in browser war. What ever it is, Google released their browser named Chrome. But Mozilla Firefox is the most popular browser in the world right now and Google was the major supporter for Firefox. Even while supporting it, they have built their own browser free and open source. Here we are looking at the two browsers and trying to compare them to decide whether to switch to the new one or not leaving our old but fascinating friend Firefox?

Interesting features

1. One Process per each tab
Tab is not another thread running inside the browser process; there is a separate process per tab. Even if one tab crashes, the rest of the tabs will be running as nothing happened; which was not available in Firefox. This is one of the most interesting features.

2. New tab is filled with useful links
For a new tab in Firefox, you can load a predefined page, a blank page or a predefined set of page links (using an extension). But you would be much happier to see a set of links that you dealt with in recent past; Chrome comes exactly with that. The new tab will show a set of links;
  • Most visited pages
  • Recently closed
  • Recently Bookmarked
I do not think the last one will be much useful, but the other two will be pretty handy.

3. Rich Location bar
Location bar in Chrome is a combination of location bar & search bar. You can directly type a url or a search keyword, also it comes with suggestions.
Using separate location bar per each tab is also an interesting move, each tab looks like individual browser instances; while in firefox you have single location bar shared by all tabs.

4. Speed
Stephen Shankland at CNet has posted an article on speed, and it tells most of the details. However Brendan at MozillaZine has published another set of testing statistics. So we'll have to check some statistics done by an independent party to get a clear view. Anyway Chrome is starting up so fast compared to any other browser.

Some complains

Since Chrome is still in beta, this may be a good time to suggest some features or improvements. Following are some complains that we have.

1. No warning in closing
When multiple tabs are opened Firefox is used to show a warning in closing the browser, but Chrome does not and closes immediately. Since people can accidentally close the browser better to add it soon.

2. Displaying different fonts
Some of the fonts are not displayed smoothly as Firefox used to do. Above image shows how the same content is displayed in two of these browsers.

3. No XML viewer
May be it is not a must to have a XML viewer in a browser, but we are used to it. Firefox and IE both have good XML viewers, but Chrome lacks it. Similar to this Opera and Safari also do not have this feature. Many people happened to work with XML files every day and having an XML viewer in the browser is an added advantage.

4. Security issues
Chrome has exposed to a set of known security issues by using an older version of WebKit, which had already been fixed. Anyway we expect Google to fix it soon.

Main Concern

Above all of these our main concern is the lack of support for extension development. We are used to live with some great extensions with Firefox, which we are not experiencing with Chrome. Since it is still in beta version, we should wait for extension support. However no API is released for extension development, users will have to wait longer than expected to see some useful extensions. There are so many extensions that makes our lives easier and better. Few of them are;
  • NoScrip
  • Adblock
  • Gmail Manager
What are the other reasons that you are not switching to Chrome straightaway?

Wednesday, August 6, 2008

Write Java with JDK 1.5 features and run on JRE 1.4

JavaHave you being writing your Java code on Java 1.5 (JDK 1.5) with new features like auto boxing, generics and enums? And suddenly realized that your customer's servers are still using Java 1.4 (JRE 1.4)? This is not a surprise since most of the customers are not in a position to take a risk and try the newer versions as they are running live/online businesses. But as professionals in the software development field, we have to move with the latest/stable versions available in the market. That's where the conflict occurs.

Now you must deploy your Java 1.5 codes into a 1.4 Java runtime environment (even may be 1.3 or 1.2). Even if the Java code has not used any of the new features of Java 1.5, you still can not run your code in 1.4 JRE as the runtime throws an error saying "java.lang.UnsupportedClassVersionError".

Compile 1.5 codes for 1.4 JVM

Java compiler provides an option to specify the target JVM of the generated classes like 1.5, 1.4, and 1.3 as follows.

public class MyClass {
public static void main(String args[]) {
System.out.println("Main Method");
}
}

> javac -source 1.4 -target 1.4 MyClass.java

Even if your JDK is of version 1.5, above command will compile your class so that it can run on a JRE 1.4. But the above option only works if your class does not use any of the new features in Java 1.5 (like auto boxing, enums etc).

Check the following class. Compiling it with "target" option will result in a compile time error.

public class MyClass {
public static void main(String args[]) {
Integer count = 1;
System.out.println("Main Method");
}
}

> javac -source 1.4 -target 1.4 MyClass.java

The compiler error is shown because auto boxing is not supported in 1.4.

This means that we can not use 1.5 features if we are going to run the programs on an older version. So this is not a real solution for our issue.

Can not run/deploy code with new features on 1.4 JVM?

Java retroweaver logoThere is an open source free solution to this issue. The tool is named "Retroweaver", and it can generate class files for older JREs using classes with new features of the 1.5 version. This is a nice tool and it supports most of the Java 1.5 features.

Retroweaver site says;

... supports most 1.5 features while running on 1.4.
  • generics
  • extended for loops
  • static imports
  • autoboxing/unboxing
  • varargs
  • enumerations
  • annotations

Also this has a good documentation (even though it's not up to date. Don't blame them; they are doing it for free).

This tool can convert .class files of 1.5 version to another older JRE version. Also it has the capability of converting a complete .jar file.