I start hating Netbeans: It constantly seems to get in my way.
For example, I want to debug the webapp. That causes netbeans to run all tests (via MVN). Those tests fail and that’s known, I just f*cking want to debug the app. Have not found a switch to convince Netbeans to set -DskipTests=true for debug mode.
Or: Why doesn’t netbeans automagically show the file I’m editing in the projects tab? I get sick pressing “ctrl-shift-1″ to do that.
Or: I have tons of open files all the time, why would you want to hide them randomly from the tabs and let me search them in the drop-down to the right? Eclipse and IntelliJ handle that one a lot better.
Netbeans: GO AWAY!
(and no I can’t switch or I lose project support which I don’t want to, no time for that)
April 19, 2012
Netbeans: Go away!
March 8, 2012
ReviewBoard integration for IntelliJ 11
I really like Review Board, a pre-commit review tool which helps keep coding quality high especially in distributed teams.
So far I used the command line tool “post-review”, which works perfectly in conjunction with Perforce. With Subversion or if you are using Windows, using post-review can really become a pain.
Fortunately, for IntelliJ, someone wrote a plugin which allows you to comfortably post reviews from within the IDE:
https://code.google.com/p/reviewboard-plugin-for-idea/
This plugin is not well known, and until today, it was only compatible with IntelliJ up to version 10.x. But now, thanks to main contributor Kane, you can also download the plugin for IntelliJ 11.
https://code.google.com/p/reviewboard-plugin-for-idea/downloads/list
Thanks a lot, Kane!
Cheers
Chris
March 18, 2011
Setting static properties with Spring
Sometimes I need to set a static property with Spring, and each time the Google result seems a bit hard to comb through.
Partly probably because Spring guys think static property injection is evil, but sometimes it just makes sense!
So for my benefit (and yours too) here is a link to a pretty nice tutorial about this subject:
http://planproof-fool.blogspot.com/2010/03/spring-setting-static-fields.html
And if you don’t like the non-static setter to a static property (like me), here is the code to directly inject a static property for your applicationContext.xml:
<bean class="org.springframework.beans.factory.config.MethodInvokingFactoryBean">
<property name="staticMethod" value="de.inweb.blog.BadDesign.setTheProperty"/>
<property name="arguments">
<list>
<ref bean="theProperty"/>
</list>
</property>
</bean>
February 3, 2011
Maven Quick Reference Card – a life saver!
Not much to say – how come that after years of using Maven and after endless searching for maven related stuff I find a quick reference card which pretty much contains most solutions already:
http://maven.apache.org/guides/MavenQuickReferenceCard.pdf
Cheers!
August 27, 2010
Maven filtering with deployment profiles
When you set up a maven project, especially for web application projects (producing a WAR file), you often need to configure the WAR file before it gets deployed. I use maven filtering together with maven profiles.
There are tons of ways to accomplish this, but I prefer to integrate deployment properties into the WAR itself. This way, the build process already produces a stand-alone WAR file ready to use, and you don’t need an additional step to modify the WAR content.
This is how you can accomplish this (pom.xml):
<build>
<resources>
<resource>
<directory>${basedir}/src/main/java</directory>
<filtering>true</filtering>
<includes>
<include>**</include>
</includes>
<excludes>
<exclude>**/*.java</exclude>
</excludes>
</resource>
<resource>
<directory>
${basedir}/src/main/webapp/WEB-INF
</directory>
<includes>
<include>web.xml</include>
</includes>
<filtering>true</filtering>
<targetPath>..</targetPath>
</resource>
[...]
<resources>
[...]
<filters>
<filter>src/main/filters/filter-${env}.properties</filter>
</filters>
</build>
<dependencies>
[...]
</dependencies>
<properties>
<!-- This is the default profile if no profile is selected on the command line -->
<env>dev</env>
[...]
</properties>
<profiles>
<profile>
<id>dev</id>
<properties>
<env>dev</env>
</properties>
</profile>
<profile>
<id>prod</id>
<properties>
<env>prod</env>
</properties>
</profile>
<profiles>
Now, create one filter file for each profile (for the two profiles dev and prod in the example above):
src/main/filters/filter-dev.properties src/main/filters/filter-prod.properties
insert filter token as described here, and execute your maven with a profile for deployment:
mvn clean install -P prod
August 21, 2010
Hibernate Event Listeners – Mappings for Spring
When I wanted to use hibernate event listeners or interceptors to modify an entity before it is saved and after it is loaded from the DB, I did not find a satisfying list of available events! Fortunately I found this post (in German) which simply listed all hibernate mappings from the code:
http://www.nautsch.net/2008/05/16/hibernate-eventlisteners-in-spring-konfigurieren/
I think – as I too didn’t find a better documentation about it – this is a great idea.
And it proves once more: Code is the best documentation.
static {
eventInterfaceFromType = new HashMap();
eventInterfaceFromType.put("auto-flush", AutoFlushEventListener.class);
eventInterfaceFromType.put("merge", MergeEventListener.class);
eventInterfaceFromType.put("create", PersistEventListener.class);
eventInterfaceFromType.put("create-onflush", PersistEventListener.class);
eventInterfaceFromType.put("delete", DeleteEventListener.class);
eventInterfaceFromType.put("dirty-check", DirtyCheckEventListener.class);
eventInterfaceFromType.put("evict", EvictEventListener.class);
eventInterfaceFromType.put("flush", FlushEventListener.class);
eventInterfaceFromType.put("flush-entity", FlushEntityEventListener.class);
eventInterfaceFromType.put("load", LoadEventListener.class);
eventInterfaceFromType.put("load-collection", InitializeCollectionEventListener.class);
eventInterfaceFromType.put("lock", LockEventListener.class);
eventInterfaceFromType.put("refresh", RefreshEventListener.class);
eventInterfaceFromType.put("replicate", ReplicateEventListener.class);
eventInterfaceFromType.put("save-update", SaveOrUpdateEventListener.class);
eventInterfaceFromType.put("save", SaveOrUpdateEventListener.class);
eventInterfaceFromType.put("update", SaveOrUpdateEventListener.class);
eventInterfaceFromType.put("pre-load", PreLoadEventListener.class);
eventInterfaceFromType.put("pre-update", PreUpdateEventListener.class);
eventInterfaceFromType.put("pre-delete", PreDeleteEventListener.class);
eventInterfaceFromType.put("pre-insert", PreInsertEventListener.class);
eventInterfaceFromType.put("pre-collection-recreate", PreCollectionRecreateEventListener.class);
eventInterfaceFromType.put("pre-collection-remove", PreCollectionRemoveEventListener.class);
eventInterfaceFromType.put("pre-collection-update", PreCollectionUpdateEventListener.class);
eventInterfaceFromType.put("post-load", PostLoadEventListener.class);
eventInterfaceFromType.put("post-update", PostUpdateEventListener.class);
eventInterfaceFromType.put("post-delete", PostDeleteEventListener.class);
eventInterfaceFromType.put("post-insert", PostInsertEventListener.class);
eventInterfaceFromType.put("post-commit-update", PostUpdateEventListener.class);
eventInterfaceFromType.put("post-commit-delete", PostDeleteEventListener.class);
eventInterfaceFromType.put("post-commit-insert", PostInsertEventListener.class);
eventInterfaceFromType.put("post-collection-recreate", PostCollectionRecreateEventListener.class);
eventInterfaceFromType.put("post-collection-remove", PostCollectionRemoveEventListener.class);
eventInterfaceFromType.put("post-collection-update", PostCollectionUpdateEventListener.class);
eventInterfaceFromType = Collections.unmodifiableMap( eventInterfaceFromType );
}
And this is how you can use this information:
In Spring, you can configure an event listener for a session factory:
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
[...]
<property name="eventListeners">
<map>
<entry key="save-update">
<ref local="yourSaveOrUpdateListener" />
</entry>
<entry key="save">
<ref local="yourSaveOrUpdateListener" />
</entry>
<entry key="update">
<ref local="yourSaveOrUpdateListener" />
</entry>
<entry key="post-load">
<ref local="yourPostLoadListener" />
</entry>
[...]
</map>
</property>
[...]
</bean>
You can use the key in Hibernate’s map above to know which events are available and how to name the key in the spring configuration. The class name above tells you which interface to implement for the given listener.
March 20, 2010
mvn eclipse: “Request to merge when ‘filtering’ is not identical.”
When filtering properties is turned on with maven and I regenerated the eclipse project with maven (mvn eclipse:eclipse), I got this problem after updating to a current mvn release:
org.apache.maven.lifecycle.LifecycleExecutionException: Request to merge when 'filtering' is not identical. Original=source src/main/java: output=null, include=[**/*.java], exclude=[], test=false, filtering=false, merging with=resource src/main/java: output=target/classes, include=[**], exclude=[**/*.java|config.properties|**/*.java], test=false, filtering=true
Well, looks like I’m not the only one with this problem! The best thread & solutions I found here:
http://forums.atlassian.com/thread.jspa?threadID=34952&tstart=30
In short, you want to use version 2.6 of the eclipse plugin, and a quick way to do that is execute mvn eclipse this way:
mvn org.apache.maven.plugins:maven-eclipse-plugin:2.6:eclipse -DdownloadSources=true -DdownloadJavadocs=true
February 26, 2010
Get going with Jetty: Run in Eclipse, Change Port in Maven
Jetty is a GREAT servlet engine, which I mainly used for development. Yet, you can use it for production as well.
Developing with Jetty is very easy already, but if you need to get going NOW, this may help:
RunJettyRun
If you work with Eclipse, and want an integrated Jetty for development, all you need id this:
http://code.google.com/p/run-jetty-run/wiki/GettingStarted
Change Port when using maven
Jetty runs on port 8080 by default. How you change that port in RunJettyRun is pretty easy (just change the run config).
If you start Jetty using Maven on the command line with this command:
mvn jetty:run
you can change the port by specifying the runtime variable jetty.port. For example, if you want to use port 8900 instead, use the following command:
mvn -Djetty.port=8900 jetty:run
I know this is not rocket science, but this kind of information may help you to get going with Jetty even faster.