Using SCM from within your Mojo
There is a guide on the topic from Maven. But that guide is missing an example on how to use it from within Mojo.
So let me show you a short example on a topic… Read more…
There is a guide on the topic from Maven. But that guide is missing an example on how to use it from within Mojo.
So let me show you a short example on a topic… Read more…
[Update:] Looks like the originator is Brian Fox from Sonatype with this article.
A short example on how to find out if the given maven execution is the root of execution, — or in other words: how to know if you are inside of a multi-module project module or in the parent?
Just extend your Maven Mojo from this abstract mojo and call isThisTheExecutionRoot()…
import java.io.File;
import org.apache.maven.execution.MavenSession;
import org.apache.maven.plugin.AbstractMojo;
public abstract class AbstractMojo extends AbstractMojo {
/** Maven Session.
*
* @parameter default-value="${session}"
* @required
* @readonly
*/
protected MavenSession mavenSession;
/** Base working directory.
*
* @parameter default-value="${project.basedir}"
* @required
* @readonly
*/
protected File basedir;
/**
* Returns true if the current project is located at the Execution Root
* Directory (where mvn was launched)
*
* @return true if execution root
*/
protected final boolean isThisTheExecutionRoot() {
final boolean result = mavenSession.getExecutionRootDirectory()
.equalsIgnoreCase(basedir.toString());
return result;
}
}
This code probably originates from Maven Changes Report Plugin: http://maven.apache.org/plugins/maven-changes-plugin/xref/index.html, but as I failed to find it within 10 minutes, I thought it might worth sharing.
This is just a short description on how to use OpenEJB with Tomcat to debug it within Eclipse.
The point is to be able to debug EJB applications from within Eclipse with a lightweight Tomcat container using OpenEJB.
You’re building a web application with some nice interface. You use JQuery and a bunch of Javascript libraries on top of it. So you download those applications and place them into your deployable package and reference them from your application.
But why do we wrestle with resources of (OSS) libraries? Downloading new versions, copying the resources to our application and deploying it again and again for each and every application.
I think W3C get that right. For example with XML Schemas: Usually XML Schema files (XSD) should be placed on some accessible URL on the Internet (or Intranet). So when you define your XML with schema definition you provide an URL which points to a resource on the Internet. Each application using the XML can fetch the Schema file and use it. Those URLs are fix URLs, does not change over time. So why don’t we do the same with Javascript files, images, etc.?
For example those popular FAMFAMFAM icons could be accessible one-by-one. Or just think of most popular JavaScript libraries like JQuery, Prototype, YUI, script.aculo.us, – you name it, – all could be accessible on a well defined URL. In that case we could access them whit a simple URL. Set up would be easy as pie…
We could provide a central repository for these resources. Something similar to Maven Repository but for other resources. It would be enough to have a unique name (as an Id).
For example I would put JQuery to a next path:
http://ossresources.org/jquery/jquery.js
Of course we need versions too. Or we could end up with non-working websites or applications from time-to-time.
My proposition would be, to extend the path from above to (kind of Maven way):
http://ossresources.org/jquery/1.3.2/jquery-1.3.2.js
Of course we could have Meta-versions too, like latest, snapshot, etc..
There are some problems with the setup from above. Lets see…
In corporate environment sometimes there are no access to the Internet, or the there are prussic proxy rules. In that case there is no access to the resources from above. – There is a same problem with XML Schemas too.
The only solution to this, is to set up a corporate repository that would proxy the resources to the Intranet. – Similar to Maven Repositories, like Artifactory or Nexus.
Okay. I’m not a lawyer but I think this is actually the bigger problem. We should find a way to distribute licences with resources too. We might put licences beside the resources, or provide a link for each resource. I just don’t know, I hope there are some folks that know the answer, and we could create a real repository…
I think this was the intention of the inventors of the web, but as usually something went wrong…
How nice it would be…
…to have DITA supported as a Doxia format, to be able to use DITA as a Maven site “language”.
…that Maven site could be rendered to eclipse help plug-in
…and deployed to Eclipse InfoCenter Server.
That would mean, that you could write single-source documentations that would be browse-able, indexed and search-able.
We use these technologies separately, and now I’m considering connecting them.
There are others with similar thoughts, but to be quite frank it looks like we’re alone…
I was searching for a way to use Jackrabbit with Spring. There are articles about this topic, but each of them suggests using spring-modules. Now, my problem with spring-modules jcr implementation is, that they depend on non-released or obsolete 3rd party JARs, like apravez.* and jeceira. Just take a look at the pom file, and you’ll see.
On the other hand I do not feel a need for jcrTemplate, jcrCallback or any other ORM flavor helpers. I just need a nice, easy integration of Jackrabbit, where I can easily inject JCR Session into any class with spring.
The JNDI way would do, but I do not want to use JNDI, I want to configure Jackrabbit from my spring beans.
Now with those premises, I came out with a quite easy setup, that follows below.
Spring configuration:
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:util="http://www.springframework.org/schema/util" xmlns:context="http://www.springframework.org/schema/context"
xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/util
http://www.springframework.org/schema/util/spring-util-2.5.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-2.5.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-2.5.xsd">
<bean name="jcrConfiguration"
class="org.apache.jackrabbit.core.config.RepositoryConfig"
factory-method="create">
<constructor-arg index="0"
type="java.io.InputStream"
value="classpath:repository.xml" />
<constructor-arg index="1"
type="java.lang.String"
value="/tmp/repository" />
</bean>
<bean name="jcrRepository" factory-method="create"
class="org.apache.jackrabbit.core.RepositoryImpl">
<constructor-arg>
<ref bean="jcrConfiguration"/>
</constructor-arg>
</bean>
<bean name="jcrSession"
factory-bean="jcrRepository"
factory-method="login"
scope="session"
destroy-method="logout">
</bean>
</beans>
The configuration of Jackrabbit is defined in repository.xml file, – I just took the default repository.xml, the one that is created when running TransientReposiotry for the first time. Of course for better integration and configuration define your own. There is one more configuration point and that could be seen in the XML from above. Spring bean jcrConfiguration defines where the repository.xml configuration is and the path to repository resources, – the second argument. For test purpose I just used /tmp/repository but for production you might set it to something like: repository Do not forget to set up spring RequestContextListener or you’ll be missing session (and request) scope in spring configurations. In web.xml just define a listener:
org.springframework.web.context.request.RequestContextListener
From code we’ll just going to use the jcrSession. Here is a small example for usage:
@Service
public class TopicService implements BeanFactoryAware {
private BeanFactory beanFactory;
public Session getJcrSession() {
Session jcrSession =
(Session) beanFactory.getBean("jcrSession");
return jcrSession;
}
@Override
public void setBeanFactory(BeanFactory beanFactory)
throws BeansException
{
this.beanFactory = beanFactory;
}
public void myFucntion() {
Session session = getJcrSession();
// here you do what you would do with JCR...
}
}
As my service is singleton I inject Spring Bean Factory with the help of org.springframework.beans.factory.BeanFactoryAware mixin, so each time I call getJcrSession() I get a JCR session bind to HTTP session.
Well, that’s it. A simple configuration, easy usage.
After a lot of work and some traveling I’m back, and I’m about to write about how do I manage to use Mac for Java development. (Note: This is the last part of the Apple Project series.)
First of all, let me describe what I use and how do I/we use it.
Eclipse is our choice of IDE. We use Subversion as SCM, Maven as a build system/dependency management/reporting/documentation/etc.. Beside these we use, (just to mention few that could be in relation with OS):
Primarily we are building web applications, backed with RDBMS – so I need a some local database for my Mac, and our choice of RDBMS is PostgreSQL, but we use Oracle and DB2 as well.
Eclipse SVN plugin Subverisve comes with javaHl support for windows, but not for linux.
Under linux you could use SVNKit, but that is somewhat slower, and a bit buggy. That is an out-of-box solution. But you could use javaHl JNI svn client too.
Had enough. P2 gave me just too much headache.
Today I removed P2 from my two production Eclipse installation. What a relief…
Update Manager (UM) works fine, as it worked in 3.3. Installed AJDT, Q4E, SpringIDE, TestNG, AnyEdit, … without any issue.
At my last few tries, I managed to install AJDT successfully, but after it I locked myself out. At next install P2 were missing AspectJ feature, and were willing to do nothing.
I read somewhere that P2 will not let you install uninstallable or wrong software… well… no comment.
I still beleave P2 is “not an evil”, and it will turn out to be great. But now I think it came in to suddenly and with lot of missing features/bugs. – I know this is the best way to test it…
, and I usually happily volunteer in these kind of testings, but not arbitrarily.
As you might know I’m a Ubuntu guy. I like Linux, OSS and I enjoy using it.
Once I was a C/C++ developer working on Windows, creating Windows applications. So I know Windows quite well (not much changed). Nowadays each time I have to sit in front of a Windows machine as a devloper I’ll get frustrated, as my productivity drops by at least 40%. Okay, it might be only because I am out of practice, but I beleave that at least 20% is because it so much easier/faster to work with Linux. – Just think of the console, Eclipse speed, and no reboot
Now as so many of my friends raved about the Apples, I’ll give it a try.
The MacBook with its small and firm design caught me. My first thought was, it would be perfect for photo companion, and it could help me out on trips as a replacement for my desktop developer machine running Eclipse and other Java stuff.
So here am I, today with a borrowed MacBook and ready for adventure.
If you’re interested in how an Ubuntu guy can cope with the Apples, stay tuned.