donderdag 27 september 2007

mvn site:deploy on windows

I had to find a way to deploy javadoc towards a server. So I found out that the maven site has a reporting plugin for javadocs. To get all this working on windows follow these steps:

We need SSH so I installed cygwin with the following modules:

openssh
tcp_wrappers
zlip
unzip

After installation of cygwin run it and on the console execute the following command to import your windows system users into cygwin:
mkpasswd   -cl   >   /etc/passwd
mkgroup --local > /etc/group


If you are logging on to a domain you'll probably need to modify the /etc/group file to match the group ids with /etc/passwd.

The error I got because of this problem was something with setgid


Could be due to myself but I thought this referenced explanation was confusing. What you should do is open the /etc/passwd file. See for the line with as first element (separated by :) your username. Then see if the 4th element (counting from 1, so the GID in name:password:uid:GID:gecos:home:shell) matches the third field on the line with name Users in /etc/group. When these do not match edit the /etc/group file to fix this problem.


Now you can start the SSH server with the following command from within cygwin (don't know if altering users config requires restart of cygwin?):
net start sshd


And now you can go back to maven to deploy your site. Maven needs the following configuration. Edit POM to contain:
<distributionManagement>
<site>
<id>website</id>
<url>scp://localhost/cygdrive/c/PATH_TO_TOMCAT/webapps/mvnsites/${project.version}</url>
</site>
</distributionManagement>
<reporting>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
</plugin>
</plugins>
</reporting>


Replace the PATH_TO_TOMCAT or any other server.


Then execute the following goals:
mvn javadoc:javadoc
mvn site:site
mvn site:deploy


resources:
http://pigtail.net/LRP/printsrv/cygwin-sshd.html
http://maven.apache.org/plugins/maven-javadoc-plugin/
http://maven.apache.org/plugins/maven-site-plugin/
http://www.javaworld.com/javaworld/jw-02-2006/jw-0227-maven.html

woensdag 26 september 2007

scm using maven and subversion

You remember my first post on SCM? Well finally I had some time to get this running. Let me tell you how.

First create a project using maven2 (maven in 5 minutes):
c:
cd projects
mvn archetype:create -DgroupId=com.name.test -DartifactId=scmtest


Now edit the pom.xml file:
cd scmtest
edit pom.xml


To add the following line underneath the <url> tag (mvn scm plugin):
<url>http://maven.apache.org</url>
<scm>
<connection>scm:svn:file:///c:/svn-repo/scmtest/trunk</connection>
</scm>


Don't execute any mvn release goals yet because we still need to configure subversion. Let's start with creating the repo. Like you may have seen in the previous url to the repo I'm putting everything locally. Just for testing. When you have a server running somewhere you probably also know how to manage it (svn repo creation and config).
svnadmin create c:/svn-repo/scmtest


I'm not completely sure about the best way to get the standard svn repo structure in there? What I did is to create a /trunk, /branches and /tag folder and copying my mvn project into there. And then I import all of it in once.


Next you can import your project for the first time:
svn import file:///c:/svn-repo/scmtest -m "initial import"


Now check this out somewhere else first so you van continue working on an svn enabled project which is needed. You note the difference in the svn repo url? This time I only need what's in the trunk folder. Our actual project, not the tags and branches.
svn checkout file:///c:/svn-repo/scmtest/trunk c:/projects/scmtest-svn


Please note that for the next commands you need to be in the folder you just checked out. If you copied the command before this will be c:/projects/scmtest-svn/ so go there first.


And then add some files to the ignore list. The target directory and eclipse files for instance. This command requires the system variable SVN_EDITOR to be set. This could be set to the edit command which is the default text based editor of your windows system.
svn propedit svn:ignore .


Note that the dot (.) pointing to the current directory is required, don't forget it. That's the whole point (:-)) of being in the right directory.


So this command will popup the svn editor you set. And there add the following lines to this file:
target
.project
.classpath


And don't forget to save this file. So we can continue, we're almost there. In fact the svn repo is now up and running, we have the most recent version checked out, ... so now we can prepare our first release.

In real life you would only do this after some development, this time you can try out immediately by executing the following maven plugin:goal:
mvn release:prepare


Next you'll be prompted for the release numbers. You can use defaults by hitting enter each time.

If all goes well you're now working on a new SNAPSHOT version. You can verify this by looking at the pom file. The next step, to really get your new release in the mvn repo execute:
mvn release:perform


And if you had some problems you can try:
mvn release:rollback


Some more release goals.

To get the project into eclipse you can always run the following maven plugin:goal:
mvn eclipse:eclipse


Note how we already added the now generated eclipse files to the ignore list.

maandag 17 september 2007

about the java classloader

Some stuff you should know about classloading. The classloader makes 3rd party classes available to the jvm. So you can run your own code and use others libraries.

The first important thing (besides knowing how to set the classpath) is the hierarchy of the different classloaders.



You can always write your own classloader to append at the bottom of this hierarchy. Most servlet containers also provide their own classloader so look closely at the given documentation. For example this link points towards the classloader hierarchy of tomcat.

The loading of a class consists of 3 phases. This is described in the java specification:

1. loading
2. linking
3. initialization

To actually see this you can always execute some code with the verbose option of the jvm turned on:
java -verbose YourMainClass
This will log the class found and those phases. If you even want more information you can also try
java -verbose:class YourMainClass

The most common errors on this issue will be ClassNotFoundException and ClassCastException. Which you probably met before.

Another problem to be aware of is that each class (given the same package etc) can only be loaded once into the classloader. So if you provide an old version of your library on the extensions library of your jvm and add an updated version to your system classpath you will experience dependency conflicts. Only the old version will be loaded into memory because it's first in the classloader hierarchy. And if that old version is missing a method (or has another method signature) you'll get a NoSuchMethodException.

The next error can occur when a class is using native system libraries. When this library is not found the code will throw an UnsatisfiedLinkError. After this error occured the class will be obscured from memory so next calls on this class will give a NoClassDefFoundError. Which makes it tricky.

Other resources can be loaded from your classpath using ClassLoader.getResourceAsStream(String path)


resources:
internals of java classloading
demystifying classloading problems

maandag 3 september 2007

maven: add resources to ear

When building ear for weblogic you'll probably want to add a custom weblogic-application.ear to the ear. This file should be in the META-INF directory of the ear next to the application.xml.

To get this done add some configuration to the maven-ear-plugin like this:

<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-ear-plugin</artifactId>
<configuration>
<earSourceDirectory>EarContent</earSourceDirectory>
<earSourceExcludes>**/application.xml</earSourceExcludes>
<modules>
<!-- modules here -->
</modules>
</configuration>
</plugin>
</plugins>


And make sure the folder you point to in this config contains a META-INF directory containing the weblogic-application.xml. No need to say you can add other resources to your this way. In fact this config will add everything in the EarContent directory, except for the excluded application.xml which will still be generated by maven.