Saturday, October 19, 2013

[Alfresco] How to Remote Debug an Alfresco Windows Service in Eclipse

This article refers to Tomcat 6 and Alfresco 3.4.0

Problem:

So you have the Alfresco system installed on the Microsoft Windows platform and it is installed as a service. You have trawled the web for hours trying to figure out how to enable remote debugging from Eclipse. A lot of sites talk about changing the Tomcat configuration and you’ve tried modifying all the .bat files in the tomcat/bin folder within your Alfresco installation and nothing works?

Solution:

This problem is compounded by lots of conflicting information on the web with some resolution methods to be used on a UNIX install rather than Windows or with the Windows version when it is not installed as a service.  You may have seen the following argument string to be included in the Tomcat configuration mentioned but don’t know where to put it?

-Xdebug -Xrunjdwp:transport=dt_socket,address=8000,server=y,suspend=n

The answer, it turns out, is not so easy to find. Essentially you need to configure the “alfrescoTomcat” service by doing the following:

1.  Open a Command Prompt (START –> Run –> cmd).
2.  Change to the “tomcat\bin” folder (e.g. cd c:\alfresco\tomcat\bin).
3.  Enter the command tomcat6w.exe //ES//alfrescoTomcat which launches the service configuration dialog box. Note that if you try to run the executable by double-clicking it you will get the following error message:

    The specified service does not exist as an installed service.

4. Click on the JAVA tab and enter the following text at the bottom of the “Java Options” field as per the below screenshot (note that that line break is significant):

-Xdebug
-Xrunjdwp:transport=dt_socket,address=8000,server=y,suspend=n

Enjoy!

Monday, September 30, 2013

[Linux] Creating Shortkeys for Common Commands

In Linux, you can assign short keys to commands you are required to run more often. These are called ‘alias’ and could be added in your .bashrc file. This really helps in quickly doing things and also avoid unnecessary mistakes while writing the commands. Below are some example:

To list all the files in current directory, including hidden files, you can assign a short key for it, say "ls" like mentioned below:
alias ls="ls -a"

View some properties file at particular location:
alias vdp="vi $JBOSS_HOME/server/default/conf/props/some.properties"

To get the running process:
alias jbp="ps -ef | grep jboss"

To view logs:
alias tlog="tail -f $JBOSS_HOME/bin/nohup.out"

Remove some files inside a directory:
alias clrjb="rm -rf $JBOSS_HOME/server/default/work/jboss.web"

Changing directory:
alias jb="cd $JBOSS_HOME/bin"

Beside this, the most useful is one here under. You can use this as “update <relative_directory_path>” to perform some steps in a sequence, one after another. This is called 'function' in linux, and are slightly different from alias, as they expect argument to be passed to them.

function update () {
  cd $SRC_HOME/"$1";
  mvn clean install -DskipTests -o -e;
  cd $SRC_HOME/someOtherFolder;
  mvn clean generate-resources -o -e;
  cd $JBOSS_HOME/bin/;
  sh runit.sh;
  tail -f $JBOSS_HOME/bin/nohup.out;
}

To have these effective, run "source .bashrc" command. 

NOTE: $JBOSS_HOME is an environment variable set as follows:
export JBOSS_HOME=/home/systest/web/jboss/jboss-5.1.0.GA

Enjoy!

Friday, August 26, 2011

[Maven] maven-compiler-plugin: ERROR Unable to locate the Javac Compiler in: C:\Program Files\Java\jre6\..\lib\tools.jar


If you’ve installed Maven plugin for Eclipse and while trying to build/install through Run -> Maven Install, you’re getting following error:

[ERROR] Unable to locate the Javac Compiler in:
  C:\Program Files\Java\jre6\..\lib\tools.jar
Please ensure you are using JDK 1.4 or above and
not a JRE (the com.sun.tools.javac.Main class is required).
In most cases you can change the location of your Java
installation by setting the JAVA_HOME environment variable.

Here is the simplest solution to this most annoying problem:

Go to Window -> Preferences -> Java -> Installed JREs
  1. Remove the default jre
     
  2. Add new JRE location pointing to C:\Program Files\Java\jdk1.6.0_26\jre i.e. same as of your JAVA_HOME\jre
Click ok and try running your project through Maven Install.
Enjoy :)

Friday, April 8, 2011

[Maven] Integrate Maven with Eclipse


To integrate Maven with Eclipse, just follow the steps mentioned below and you're done!

Install Maven (3.0.3)

   1. Download Maven and unzip it.

   2. Create MAVEN_HOME System Variable.

   3. Add %MAVEN_HOME%\bin; to your System Path.

   4. On command prompt, type "mvn -version" to verify the installation, it will display following information

Apache Maven 3.0.3 (r1075438; 2011-02-28 22:31:09+0500)
Maven home: C:\Program Files\apache-maven-3.0.3\bin\..
Java version: 1.6.0_24, vendor: Sun Microsystems Inc.
Java home: C:\Program Files\Java\jdk1.6.0_24\jre
Default locale: en_US, platform encoding: Cp1252
OS name: "windows 7", version: "6.1", arch: "x86", family: "windows"

   5. On command prompt, type "mvn clean". This will download some jar files from Maven central repositor, followed by some BUILD FAILURE error indicating missing POM (pom.xml) file in current directory; so dont worry about it.

   6. Go to user home directory (for e.g. C:\Users\<username>), you'll find an .m2 folder with 'repository' subfolder. This is default local Maven repository location. As a result of "mvn clean" command, Maven downloaded maven-clean-plugin-2.4.1.jar file in it which you can see under C:\Users\<username>\.m2\repository\org\apache\maven\plugins\maven-clean-plugin\2.4.1 folder.

Now Maven is installed and ready to use with other projects.


Installing Maven Plugin for Eclipse

   1. After installing eclipse, install M2Eclipse in Eclipse using following update sites:

Maven Integration for Eclipse: http://m2eclipse.sonatype.org/sites/m2e/0.12.1.20110112-1712/
Maven Integration for Eclipse Update Site: http://m2eclipse.sonatype.org/update/

   2. As soon as you're done with all the steps followed by restart of Eclipse, you're now ready to Import your existing Maven projects in it.

   3. But before that, you might see a Maven Integration for Eclipse JDK Warning, stating to verify -vm option in eclipse.ini pointing to a JDK.

   4. To fix this, go to Eclipse installation directory (i.e. ECLIPSE_HOME), you'll see eclipse.ini file which contains command-line options that are added to the command line used to when Eclipse is started up.

   5. Add following lines to eclipse.ini before the -vmargs option, since everything after -vmargs is passed directly to the JVM.

-vm
C:\Java\JDK\1.5\bin\javaw.exe

Please note that the -vm option and its value (the path) must be on separate lines. Also, the value must be the full absolute path to the Java executable, not just to the JAVA_HOME directory. 

This will fix the JDK warning from Maven plugin, and now you can use Maven commands directly from Eclipse.