Archive for the ‘Maven’ Category

h1

Speeding up Eclipse

January 25, 2011

Eclipse can get a bit sluggish, especially when you’ve got the Scala and Maven plugins installed into it. I found the following website with some useful improvements you can make to the eclipse.ini file to speed it up. This works for Windows and Linux systems and will probably work with Mac as well. It give eclipse more memory so if you are running a dev machine with 4GB of RAM then this should work fine. The eclipse.ini file can be found in the root of the eclipse application folder.

The vmargs parameter as shipped uses these heap settings (at the bottom of the eclispe.ini file):

-Xms40m
-Xmx364m

It needs to specify a larger heap and more stack.

-Xss8m
-Xms800m
-Xmx2048m
-XX:NewSize=400m
-server
-XX:+DoEscapeAnalysis
-XX:+UseConcMarkSweepGC

Adjust the max heap size (“mx”) to be sure that it fits in real memory. “ms” should be twice the “NewSize”.

Ref: http://projectfortress.sun.com/Projects/Community/wiki/Eclipse

h1

Putting properties in the web xml file

January 25, 2011

If you are building a web app in Java or Scala, you might want to feed in a variable from outside which describes something special about the particular environment the web app is running on.  On a normal application you might do this from the command line with a command line argument.  In a web app, you put the variables in the web.xml file. In a maven built project this can be found in /src/main/java/webapp/WEB-INF/web.xml

The XML for the variable looks like this …

<env-entry>
<env-entry-name>PROPS_FOLDER</env-entry-name>
<env-entry-value>/opt/webapp/properties</env-entry-value>
<env-entry-type>java.lang.String</env-entry-type>
</env-entry>

In your code, the property can be accessed by any class which extends HttpServlet. The following imports are therefore required:

import javax.servlet.http.HttpServlet;
import javax.naming.Context;
import javax.naming.InitialContext;

The property can then be accessed in your Java code like this:

Context env = (Context) (new InitialContext().lookup("java:comp/env"));
String PROPS_FOLDER = (String) env.lookup("PROPS_FOLDER");

And in Scala like this:

val env:Context = (new InitialContext().lookup("java:comp/env")).asInstanceOf[Context];
val PROPS_FOLDER:String = env.lookup("PROPS_FOLDER").asInstanceOf[String];
h1

Get a file request to jetty maven web project via web.xml

December 17, 2010

When using a maven managed POM project which has an embedded jetty server, I wanted to be able to direct some requests straight to a file in the webapp directory rather than being handled by the servlet code. I found that adding the following to src/main/scala/webapp/WEB-INF/web.xml allowed me to do this.

        <servlet-mapping>
         <servlet-name>default</servlet-name>
         <url-pattern>filename.ext</url-pattern>
        </servlet-mapping>
h1

Getting Java running from Maven

November 3, 2010

Good site describing how to get Java applications compiled, tested and run from mvn:

http://www.vineetmanohar.com/2009/11/3-ways-to-run-java-main-from-maven/