JBoss Community

Hacking AS7 using Eclipse

modified by Andre Dietisheim in JBoss Tools - View the full document

Preface

There's already a article that shows you very well how to checkout and build the AS7 code base using command line tools. Unfortunately using Eclipse on top of those steps shows some gotchas that are not obvious. This article will show you how to import the AS7 projects to Eclipse.

 

 

 

Checkout the AS7 code base

 

The reference documentation may be reached at http://community.jboss.org/wiki/HackingonAS7. It shows you extensively what steps need to be achieve to get things up and running on the command line. Please follow these steps. I'll try to add the corresponding steps for EGit later on

 

TODO: add instructions using EGit

 

Install M2Eclipse and EGit

The next step involves installing the appropriate plug ins for Eclipse. The easiest way to achieve that is to install them from the Eclipse Marketplace.

 

 

http://community.jboss.org/servlet/JiveServlet/downloadImage/16140/install-from-marketplace.png

 

 

http://community.jboss.org/servlet/JiveServlet/downloadImage/16139/install-egit.png

 

http://community.jboss.org/servlet/JiveServlet/downloadImage/16138/install-m2eclipse.png

 

Add local git Repository


After rebooting Eclipse, you'll now be able to import the local git repository.

 

 

http://community.jboss.org/servlet/JiveServlet/downloadImage/102-16718-6-16132/449-73/add-local-git-repo.png

 

 

http://community.jboss.org/servlet/JiveServlet/downloadImage/102-16718-6-16133/450-455/add-local-git-repo-2.png

 

Import Maven Project

You'll then finally be able to import your AS7 sub-project into Eclilpse. Pick it in the list of available folders in the Working Directory and choose Import Maven Project from the context menu.

 

 

http://community.jboss.org/servlet/JiveServlet/downloadImage/102-16718-6-16143/300-405/import-mavenproj-from-git.png

 

You'll then end up with an project in your package explorer, that holds the name given to it in the maven pom.

 

Correct compilation errors

Run the maven build in eclipse

You may eventually have to run the maven build in a first place so that all required maven artifacts get installed to the local maven repo.

 

Quick fix the M2Eclipse lifecycle errors

You may also experience maven related probles when using the latest m2eclipse 0.13. M2eclipse speeds up the build cycle by stripping it down to the bare minimum needed in Eclipse (you may read detailed documentation about in the m2eclipse wiki). M2eclipse will therefore report you that specific plugins are not covered by the build lifecycle. Those errors are easily fixable with quick fixes that are offered to you in the pom editor.

 

Correct build path precedence errors

You may experience compilation errors that are not related to m2eclipse. Most of them are due to the fact, that the build setup in Eclipse differs from what is used with bare Maven on the command line.

In my particular case, where I imported the AS7 demos, I ended up with the odd case where the Eclipse compiler complained about an illegal attribute to the @Resource annotation.

 

 

http://community.jboss.org/servlet/JiveServlet/downloadImage/102-16718-6-16144/450-249/compilation-errors.png

 

 

The compilation error that is reported is due to a bad resolution of the @Resource annotation.

 

If you use Eclipse with m2eclipse you'll end up with at least 2 compilation containers that resolve required classes. Eclipse will lookup in the JRE System Library in a first place and fall back to the Maven dependencies in a second step.

 

 

http://community.jboss.org/servlet/JiveServlet/downloadImage/102-16718-6-16145/450-122/build-path.png

 

 

The Eclipse compiler actually applies the annotation that may be found in the jdk. This jdk annotation does not support the lookup attribute and compilation therefore fails. On the other hand the maven dependencies hold the correct, extended annotation which knows about a lookup attribute. So this basically boils down to the precendece of the compilation containers in Eclipse. You may fix the above error in the project build path:

 

Remove the JRE System Library and add it back again.

 

The GUI will actually not show any change, it will still show the JRE System Library in first and the Maven Dependencies in second place. Behind the scenes though, their order was inverted. Eclipse now resolves artifacts from the Maven container and will fall back to the JRE if needed.

 

 

http://community.jboss.org/servlet/JiveServlet/downloadImage/102-16718-6-16137/450-90/classpath-file.png

 

The root cause is adressed in the following Eclipse bugzilla: https://bugs.eclipse.org/bugs/show_bug.cgi?id=342128

Comment by going to Community

Create a new document in JBoss Tools at Community