Showing posts with label maven. Show all posts
Showing posts with label maven. Show all posts

Wednesday, October 13, 2010

Set optional jetty-env.xml for JNDI in maven jetty plugins

I talked about how to set up jndi with jetty in last post. But I still like to use "jetty:run" in the maven jetty plugin. It uses an embed server that hard to configure. Later I found a way to specify a non-conventional position for jetty-env.xml in maven-jetty-plugin. So I put jetty-env.xml in that position and specify it in pom.xml. Now I can still use jetty:run. But when it packaged as war and deployed in web container. It cannot run without setting JNDI in server.

Here is my setting:
1. Put jetty-env.xml in WEB-INF/local/jetty-env.xml;
2. Add following into pom.xml

<plugin>
<groupId>org.mortbay.jetty</groupId>
<artifactId>maven-jetty-plugin</artifactId>
<version>6.1.22</version>
<configuration>

<contextPath>/</contextPath>

<jettyEnvXml>src/main/webapp/WEB-INF/local/jetty-env.xml</jettyEnvXml>
.......
</configuration>
</plugin>


Well, if you really hate any settings in svn repository. You can put jetty-env.xml somewhere outside svn directory. Use

<jettyEnvXml>${jetty.setting}</jettyEnvXml>

Now when you start maven append the system property jetty.setting=directory.

mvn -Djetty.setting=**/jetty-env.xml jetty:run

Tuesday, August 24, 2010

Switch to Netbeans

I get fairly frustrated by Eclipse. It is nice and polished in most sense. However, a few things keep bothering me. A few essential tools in our work needs plugins. Svn and maven plugins are both problematic. Early this year, for some reason, svn plugin keeps freezing the eclipse. Maven plugin also feels somehow weird. I did not get it through until I start to use spring's Spring Tools Suite(STS), a customized eclipse from spring source. It is kind of nice with maven built-in. I still need to install svn plugin, which does not freeze anymore. But the svn commit often fails, not sure whether I should blame the plugin or the googlecode's svn repository though. But it is likely some suboptimal setting in svn plugin. However, maven plugin (M2eclipse) still runs sluggishly and occasionally it freezes STS, especially in the MacBook Pro (4G Ram, 2.4G T8300). It often takes 10 seconds or more to open a pom.xml files, even in a fairly powerful machine ( 2.4G Core Quad, 8G Ram). Our projects are reasonably complicated, dependency in the order of 100 things. It has some nice tool for maven, such as the search in dependency. But the speed is too slow. It takes even 10 seconds to switch to a window of pom.xml. Something seriously wrong with m2eclipse.

Recently Eclipse upgrade to 3.6. I tried to upgrade. But it does not work well for me. Some common shortcut key does not work such as Ctrl-Alt-C for commit.

I don't remember how it starts. I saw netbeans a few days ago. I used netbeans before eclipse. But it is a long time ago. In recent few projects, everyone else use s eclipse, so I use it as well. Well, I took a serious look at netbeans (6.9.1) this time, to my pleasure, it has maven and svn built-in. So it should be OK for my project. Our project is a multi-module maven project. I first thought the project is eclipse specified as we commit from eclipse. And I know for sure that there are some eclipse's setting in repository. I tried netbeans and it works. It actually works pretty better than I thought. It checkout the project into several projects, each module becomes a project. It actually is better, as now each project's default paths (src/test/web/res/..) are recognized automatically into the project viewer. In eclipse, it is one project and eclipse cannot recognize the default maven paths in modules. So they are all normal folders and it is quite inconvenient to look for the path I need within about 10 different folders. One plus. Well, soon I found a few other goodies. It automatically include the default ~/.m2/settings.xml into the project. This is fairly convenient because it does control quite some properties in the project and I often needs to modify it. And best of all, pom.xml opens fast. In the crude looking, it is treated as a simple xml file. And a close look shows that you can also open a dependency graph, which does take some time. But most time, I do not need to see that, I only need to work with it as simple xml.

Svn is not as powerful. It does not provide a svn repository view. However, you can checkout things and other normal tools like update, commit, merge, diff are there and that is enough for me.

And an extra plus is that it seems bundled with Spring. And I got some basic tools for spring out of box, such as bean editor...

Overall, netbeans seems to run faster. It does not looks as nice, swing is not as good as SWT. But it looks OK, and this is the secondary concerns for me. Things seems integrated more tightly in netbeans. Eclipse seems more module, everything comes in as plugin and there are lots of great plugin. But for my work, I only need those typical tools. And netbeans seems to serve me better.

I switched to netbeans and it works fine for me for a week now . We will see how it works out in more time.


Update: Dec. 16th, 2010
Two good things about Netbeans:
* It formated HTML corrected. You will definitely hate Eclipse/sprinesource when you try to auto-format html. Netbeans also take care of javascript in html <script> tag.
* Netbeans also understand javascript syntax to some degree and points out some obvious typo such as extra ";", "}", ... Javascript is nice, but hard to debug and often a small typo like that costs me half an hour as firebug/chrome developer tool does not realize it and reports some other errors and leads you everywhere but the correct place. That is a really benefit with Netbeans.

Friday, July 16, 2010

Hibernate

Recently I start to build an sub system for MIREX submission. It is not too complicated, it should accept submission of programs with certain metadata, such as contributors, notes, etc... And Mirex runner (NEMA system, or a human runner) should be able to change the status, leave note and inform the submitter. It is not simple when you need to consider every detail. And I have already spent about two weeks on it.

One thing I need to learn is Hibernate. We used that already in our system. But Amit and others have implemented it and provided me with a DAO object. So I have no direct interaction with it. This time, I have to write every bit from the scratch. Well, that is not totally true. I have their old code for reference. I use the annotation mapping, and spring hibernate template. I spent quite some time to read "Java Persistence with Hibernate", not the best choice. The book was written by one of the authors of Hibernate, and is very detailed and not really good for the first-timer. After couple of days, I finished about half the books and started to read the hibernate documentation from their site. It turns out much more accessible. It has some good example and explains things pretty clearly and I really like it.

Today, I realize that I need to have bi-direction many-to-one and many-to-many association with list. The order is important. I looked though the book and again, the documentation gives me an easier answer. @OrderColumn. And here comes the problem. We are using a quite mixed version of hibernate, some modules use 3.2.6, some uses 3.3.0GA and some use 3.4.0GA, with JPA 1. None of them support @OrderColum. It took me a while to figure out that this is the new annotation for JPA2. I have to upgrade hibernate in order to use this feature. Otherwise, I can use some hibernate annotation. I figured to whatever, just upgrade. So the latest 3.5.1Final we go.

The first problem I run into is that I cannot find it in the main maven repoistory. After some search, I found it is only in JBoss's repository. I need to add it into our own proxy repository server. I have to ask Amit for the username/password for it. After some talk, I found out we have already had it in the proxy list. I SHOULD HAVE tried before ask...

And soon, I found the module structure changes. Hibernate-annotation depends on hibernate-core. So I only need to include hibernate-annotation. But soon I run into the next problem, Spring cannot build the session-factory for Hibernate, it cannot find some classes about slf4j. I am confused. Hibernate already has slf4j dependence. After some 20 minutes on google, I finally figured out that Hibernate has slf4j-api. But I also need to make my code depends on slf4j12. So include it and I got new different error.

This time is ehcache. The old code has hibernate.cache.provider_class=org.hibernate.cache.EhCacheProvider. I looked at hibernate-core.jar, and sure, it dose not have such class. After a while, I realized it might not in core. I check the repository, there is one module, hibernate-ehcache. Here we go. But again, new problem pops up.

It is something about assistance. I am confused again. Hibernate does have dependency on javaassistence. A close look says that is is in test scope. Maybe that is the reason. Add the new dependency, and finally my unit tests sort of run.

My old database schema does not work with the new ordercolumn. The project has dependency on hibernate3-maven plug-in. I used to just copy their output ddl into mysql to generate the new database. But this time after I import the ddl, the test always tell me some field "note_Orders" is missing. I am really confused. I gives the @OrderColumn a new name. After run the maven test several times and I started to read the ddl more carefully and sure, the order columns are missing. WTF!!! Well, it turns out that hibernate3-maven plug-in depends on hibernate-3.4.0GA. It is probably does not understand this new annotation.

I add hibernate.hbm2ddl.auto=update into the hibernate config. And it seems to update my schema fine.

WHEW, quite some work!