Saturday, April 23, 2011

Running Maven Built Web Applications Directly From Intellij IDEA

Detailed here courtesy of Matt Flemming:

http://mattfleming.com/node/281

Also here (slightly different) on the JetBrains Wiki:

http://wiki.jetbrains.net/intellij/Creating_a_simple_Web_application_and_deploying_it_to_Tomcat

None of these match up exactly to Intellij IDEA X, but fairly close. On the 'Deployment' tab choose deploy artifact, then choose the exploded war version of your project/maven module.

On the 'Server' tab, where the start url is defined, if you eneter your context path, this becomes implicit when accessing via browser url - ie you need not enter it.

Installing Tomcat on Mac OSX with MacPorts

All you need to know is here:

http://mikevalentiner.wordpress.com/2009/01/30/how-to-install-and-run-tomcat-on-macos/

In case it goes off line however, these are the basic steps you need to follow:

1) Install MacPorts - official guide is here...

2) Check macports installed correctly in the terminal, type
port -version


3) Install Tomcat by typing ‘sudo port install tomcat6′. Replace ‘tomcat6′ with ‘tomcat5′, if that is the version you are after. To see all versions of Tomcat available for install from MacPort, type ‘port list | grep tomcat’.


Below is the console blurb after the tomcat install succeeds:

# setting up needed dirs
# installing tomcat...
# adding the jstl libs
# maint. empty dirs...
# adding our scripts
# adding our scripts 2
---> Creating launchd control script
###########################################################
# A startup item has been generated that will aid in
# starting tomcat6 with launchd. It is disabled
# by default. Execute the following command to start it,
# and to cause it to launch at startup:
#
# sudo port load tomcat6
###########################################################
---> Installing tomcat6 @6.0.32_0
#
# Configuration files in /opt/local/share/java/tomcat6/conf have been
# installed with a .sample extension so that they won't be replaced by a
# port update. Each will be copied to its proper location during the
# first startup of tomcat by catalina.sh or tomcatctl if you don't
# do this yourself first. If this _is_ an update, you might do a diff to
# verify that you're not missing anything in the newer .sample versions
# of these files.
#
# The script /opt/local/share/java/tomcat6/bin/tomcatctl has been installed to
# facilitate start and stop of tomcat using the jsvc utility, which allows you to
# start tomcat as a true daemon process. Once tomcat has acquired its TCP socket,
# jsvc will drop its root privileges and run as user www.
#
# Under Apple Java, control over the Java version used to launch tomcat6 is
# through the shell variable JAVA_JVM_VERSION. This variable should be set
# to a java version such as 1.5, 1.6, or CurrentJDK (for the default version).
# You may set JAVA_JVM_VERSION in /opt/local/share/java/tomcat6/bin/setenv.sh.
#



4) Once installed, you need to make a few tweeks to get it to run. The first is to set up the tomcat-users.xml file in tomcat6/conf. Edit the contents to look like:

<?xml version='1.0' encoding='utf-8'?>

<tomcat-users>

<role rolename="tomcat"/>

<role rolename="manager"/>

<role rolename="admin"/>

<user username="tomcat" password="password" roles="tomcat,admin,manager"/>

<user username="some-username" password="the-password" roles="tomcat,admin,manager"/> </tomcat-users>



5) The second tweek is to “fix” the file permissions on a number of files. In your shell window, cd to the tomcat6/bin directory and set all the .sh files so they are readable and executable:

sudo chmod 755 *.sh

6) The final tweek is to set the tomcat6 log files so they are writeable by tomcat. cd to the logs directory and change file permissions:
sudo chmod 777 catalina.*

7) That should be it. Start Tomcat be cd’ing to the bin directory and running:
sudo ./startup.sh

8) You can verify Tomcat is up and running by browsing to http://localhost:8080 in your browser.


Mac OS X, Gem Install Problem: "ERROR: Failed to build gem native extension"

If you are getting this error:

ERROR: Failed to build gem native extension.

when installing a ruby gem on OSX, then chances are you do not have the tools necessary to execute 'make' as part of the install process. Its an easy fix...install the XCode which will also install the necessary tools for the 'make' process. You can do this by either:

  1. Downloading from the AppStore, or from the Developer Centre
  2. Mac Xcode Tools off the Mac OS X Install Disc 1
That fixed it for me anyway. Enjoy!