A solution for fixing broken Maven Project Archetypes in Eclipse. + Installing cURL.

This post is a brief two-part piece, about a couple of things I worked on, earlier this afternoon.

The first part covers, 'How to fix broken Maven Project Archetypes in Eclipse'. The second part is a short one on, 'Installing cURL'.

Part1: How to fix broken Maven Project Archetypes in Eclipse

If you use Eclipse for JavaEE development and use Apache Maven via the M2Eclipse plugin, to handle the management of project libraries and dependencies, chances are you may have come across an issue with regards to not being able to create a Maven project using some of the archetypes that come bundled within your Eclipse for JavaEE installation (such as the 'org.appfuse.archetypes:appfuse-basic-spring:RELEASE' archetype, which is a lovely archetype for building a Java web application with Hibernate, Spring and Spring MVC, produced by the good folks at appfuse.org). Other bundled AppFuse archetypes include ones with the following artifactIds: appfuse-basic-jsf, which sets-up a Maven project with Hibernate, Spring and JavaServerFaces, appfuse-basic-struts, which sets-up a Maven project with Hibernate, Spring and Struts2, appfuse-basic-tapestry, which sets-up a Maven project with Hibernate, Spring and Tapestry4, and a host of others.

By the way, one of the great benefits of using a Maven archetype, like these ones from AppFuse, for creating your Application is gotten from the almost-complete, preconfigured, packaged project it produces, which eliminates much of the ramp-up time it typically takes, when setting-up a project for building an enterprise-scale Java web application. For instance, no need to create and add your own webapp deployment descriptor (web.xml) or hibernate or jpa or spring config files from scratch, since the tool produces or downloads and adds the set of config files, properties files etc. that the selected project type requires, along with all the 3rd-party libraries needed.

The issue that this blog-post addresses occurs when you attempt to use one of the AppFuse archetypes that comes bundled within Eclipse, to create a Maven project. The issue also surfaces on other Eclipse/WTP-based IDEs for JavaEE such as SpringToolsSuite (STS) and MyEclipse. To reproduce/see the issue, do the following:

1. Launch open your Eclipse for JavaEE (I'll assume you have installed the M2Eclipse plugin - maven plugin for Eclipse. If not, then do install it by doing Help->Install New software and pointing to the repository site at http://download.eclipse.org/technology/m2e/releases).

Eclipse IDE for JavaEE Development

2. Do File->New->Maven Project (or New->Other->Maven->Maven Project), click Next on the New Maven Project wizard, to the screen with the list of Archetypes and select the "org.appfuse.archetypes:appfuse-basic-spring:RELEASE" archetype.


3. Click Next, specify the archetype/project parameters i.e. groupId, artifactId, version and package name. And click Finish.



4. Upon doing that, the project creation process will encounter an error, with message - "Failed to create project 'projectname': Could not resolve archetype org.appfuse.archetypes:appfuse-basic-spring:RELEASE from any of the configured repositories".


It turns out that the error is being caused by mismatches that abound between the properties of the selected archetype that came bundled within Eclipse and the properties specified on the remote repository. e.g. the archetype name and/or the groupId and/or the artifactId and/or the version, seem to have all been updated/changed by AppFuse, but have not yet been updated by Eclipse in its internal names.

The solution is to obtain an updated list of archetypes from a valid catalog on the remote repository.To do this, you will add a Remote Catalog (i.e. one that contains the updated list of archetypes) to your Eclipse workspace preferences, as follows:

1. Do 'Window'->'Preferences'.

2. On the Preferences screen, expand the Maven node in the leftPane's treeview.

3. Under the Maven node, select "Archetypes".

4. Click "Add Remote Catalog..." button, on the rightPane.


5. In the "Remote Archetype Catalog" dialogBox, specify the catalog url and description, by entering "https://oss.sonatype.org/content/repositories/appfuse/archetype-catalog.xml" for the Catalog File, and an appropriate description (e.g Remote catalog of AppFuse archetypes).


6. Click "Verify..." (this contacts the remote url and downloads+enumerates through the list of archetypes found) and then click OK.

7. Finally, click "Apply" and "OK"

With the above steps done, when you now create a new Maven Project, on the "Select an archetype" screen of the 'New Project' wizard, you can then select your newly added catalog on the catalogs dropdown list, and see all the available archetypes downloaded from the remote url.


Pick your required archetype (appfuse-basic-spring), click Next, populate the project properties and click Finish and it will successfully create the project, without the above issue.



New Maven Project successfully created

NOTE: I am using Eclipse 4.3 (Kepler) for JavaEE, with m2e plugin installed. 

Part 2: Installing cURL

curl is a free, open-source software, which consists of a command-line tool (cURL) and library (libcurl), for transferring data using URL syntax, with support for various communication protocols. curl supports protocols such as DICT, FILE, FTP, FTPS, Gopher, HTTP, HTTPS, IMAP, IMAPS, LDAP, LDAPS, POP3, POP3S, RTMP, RTSP, SCP, SFTP, SMTP, SMTPS, Telnet and TFTP. It also has support for SSL certificates, HTTP POST, HTTP PUT, FTP uploading, HTTP form based upload, proxies, cookies, user+password authentication (Basic, Digest, NTLM, Negotiate, kerberos...), file transfer resume, proxy tunneling and a busload of other useful tricks.

A common usage of cURL is as a basic HTTP client. For example, the command,


will simply retrieve the content of the webpage at target url and display it on the standard output specified on the system - usually the command/terminal window or console. curl can be a very useful tool during development of RESTful web services. Using it, one can easily test and verify output from a webService.

The curl command-line can take a host of options or switches. The user manual (aka ManPage) is available online here - http://curl.haxx.se/docs/manpage.html

To install cURL, there are two choices: 

1. download the source code and make a build and produce executable binaries for your platform.

2. download ready-made executable binaries for your selected platform.

Option 1 is great if you are interested in getting hold of the source code and perhaps are considering contributing to the curl project as a developer. Obviously, option 2 is the much simpler choice for a user. It basically entails downloading the appropraite zip file or tarball for your platform, from here - http://curl.haxx.se/download.html.

To get the appropriate file, it is advisable to use the "cURL Download Wizard" link found on the Download (http://curl.haxx.se/download.html) page.

Select "curl executable" for the package type,  select your OS from the dropdownlist (e.g. Windows/Win32), select Generic or Cygwin, select "Any" for the Win32 version and finally select/download an appropriate zip archive.

To install the package, simply unzip the archive to a suitable directory on your system e.g. c:\curl. 

cURL binaries installed to directory at c:\curl

I'll also recommend adding the installation path containing the binaries (e.g. c:\curl) to your system path environment variable. So that you wouldn't have to always cd into the curl installation path to be able to run the curl command.

Sample curl command executed, showing output

Comments

Post a Comment