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

Wednesday, November 5, 2014

“Non-resolvable parent POM: Could not transfer artifact” when trying to refer to a parent pom from a child pom with ${parent.groupid}

Looks like you're trying to both inherit the groupId from the parent, and simultaneously specify the parent using an inherited groupId!
In the child pom, use something like this:
4.0.0


  org.felipe
  tutorial_maven
  1.0-SNAPSHOT
  ../pom.xml


tutorial_maven_jar
Using properties like ${project.groupId} won't work there. If you specify the parent in this way, then you can inherit the groupId and version in the child pom. Hence, you only need to specify the artifactId in the child pom.

Wednesday, October 15, 2014

Maven does not find JUnit tests to run

By default Maven uses the following naming conventions when looking for tests to run:
  • Test*
  • *Test
  • *TestCase
Your test class doesn't follow these conventions. You should rename it or configure Maven Surefire Plugin to use another pattern for test classes.

Tuesday, October 7, 2014

Cannot make Project Lombok work on Eclipse (Helios)

After adding lombok and restarting eclipse or spring tools my project still failed to recognize getters and setters. Red markers everywhere!
The solution: right-click your project, go to Maven and select Update Project
After hours of searching and trying random solution, I find this to be the only solution that worked for me.
enter image description here

Tuesday, September 3, 2013

How to fix error “Updating Maven Project”. Unsupported IClasspathEntry kind=4?

The problem is caused by the fact that the STS (the Spring IDE/Eclipse) uses the m2e(clipse) plugin but that eclipse:eclipse has been probably been run on the project. When m2e encounters a "var" .classpath entry, it throws this error.
In order to fix this problem, you need to do the following:
  1. Make sure that the version of the m2e(clipse) plugin that you're running is at least 1.1.0, and preferably, the latest available. The update site is the following url: http://eclipse.org/m2e/download/.
  2. Disable the maven nature for the project (via the right-click menu)
  3. run mvn eclipse:clean (while your project is open in STS/eclipse)
  4. re-enable the maven nature.
    (Most of the time, this can be done by right-clicking on the project in question in the package explorer pane, and then choosing 'Configure'-> 'Convert to Maven Project')

http://stackoverflow.com/questions/10564684/how-to-fix-error-updating-maven-project-unsupported-iclasspathentry-kind-4

maven-archetype-webapp eclipse problem

imply create a java directory under main (i.e. src/main/java) and right-click on your project and selectMaven > Update Project Configuration.

http://stackoverflow.com/questions/3042518/maven-archetype-webapp-eclipse-problem

Thursday, August 29, 2013

Problems setting up a dynamic web project in eclipse using Java EE and Tomcat

I created a maven project using the command mvn archetype:generate ... to generate the project structure which I then imported into Eclipse. I then added a dynamic web facet to the project.
You shouldn't have to add any facet, things should just work if your project has a packaging of type war.
It would thus have been nice to provide the full command you used to create your project with the archetype plugin. Did you use the maven-archetype-webapp archetype? Did you ran something like that:
mvn archetype:generate -DarchetypeArtifactId=maven-archetype-webapp \
  -DgroupId=my.group.id -DartifactId=my-artifact -Dversion=1.0-SNAPSHOT
If not, then be sure that your pom has a war and that you use the default structure for a war project (see Usage for an example).
Then, what plugin are you using for the Eclipse integration? How did you import the project into Eclipse?
If you are using the maven-eclipse-plugin (if you ran eclipse:eclipse), then you need to configure it for WTP support. You need to pass the wtpversion on the command line (or to configure the plugin in the POM):
mvn -Dwtpversion=2.0 eclipse:eclipse
If you are using m2eclipse, then just import your project as a Maven Project (right-click the Package Explorerthen Import... > Maven Projects).
In both case, your project should be recognized as a Dynamic Web Module that you can Run on Server). There is nothing manual to configure for this (no facet to add).
Update: Did you install the Maven Integration for WTP (Optional) when installing m2eclipse?

mvn eclipse:eclipse within Eclipse

Yup, when you right-click over the project, in the Maven sub-menu, you have an Update Project Configuration command which does precisely that.

http://stackoverflow.com/questions/3288005/mvn-eclipseeclipse-within-eclipse

Saturday, August 11, 2012

Maven dependencies not visible in WEB-INF/lib

This should have nothing to do with eclipse and m2eclipse, and optionally for better support - m2e-wtp. Also, you don't need copy-dependencies. Here are a few possible reasons:
  • you should invoke mvn package (or right-click > maven > package) and obtain a war file - the (in the pom) must be war
  • your dependencies should be with the default scope (if they are provided or test they will not be included in the archive)
  • if you are running the project as dynamic web project on a server within eclipse, then you should open the project properties (right click > properties) and select "Deployment Assembly". There click "add", select "build path entries", and choose "maven dependencies". This will instruct WTP to send the maven dependencies to the server dir.

Friday, August 3, 2012

How to fix error “Updating Maven Project”. Unsupported IClasspathEntry kind=4?

Please see https://bugs.eclipse.org/bugs/show_bug.cgi?id=374332#c14
The problem is caused by the fact that the STS (the Spring IDE/Eclipse) uses the m2e(clipse) plugin but that eclipse:eclipse has been probably been run on the project. When m2e encounters a "var" .classpath entry, it throws this error.
In order to fix this problem, you need to do 2 things:
  1. Make sure that the version of the m2e(clipse) plugin that you're running is at least 1.1.0, and preferably, the latest available. The update site can be found in a folder of this url: https://repository.sonatype.org/content/repositories/forge-sites/m2e/
  2. Disable the maven nature for the project (via the right-click menu), run mvn eclipse:clean (while your project is open in STS/eclipse), and then re-enable the maven nature.
     
http://stackoverflow.com/questions/10564684/how-to-fix-error-updating-maven-project-unsupported-iclasspathentry-kind-4

Wednesday, July 18, 2012

How do you refresh maven dependencies from eclipse?

You generate the special eclipse files with mvn eclipse:eclipse, but once you've done that, you should let a plugin handle the dependencies while inside eclipse.
That's how we do it at my work place, and it generally works well.

http://stackoverflow.com/questions/136308/how-do-you-refresh-maven-dependencies-from-eclipse

Monday, July 16, 2012

class file has wrong version 50.0, should be 49.0″ by Maven

If this error occurs when you’re compiling your Maven project, there’s a good chance that you’ve included a Maven Dependency that was compiled using Java 1.6 and your Maven installation is running on a Java 1.5 JRE.
The good news is that Maven will tell you which Dependency is causing that. For instance, in my case it was java-web-api as shown in the error message:
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:2.3.2:compile (default-compile) on project hTask-web: Compilation failure
[ERROR] /Users/hordine/projects/hTask/hTask-web/src/main/java/com/hordine/htask/web/control/TaskController.java:[3,-1] cannot access javax.servlet.http.HttpServletRequest
[ERROR] bad class file: /Users/hordine/.m2/repository/javax/javaee-web-api/6.0/javaee-web-api-6.0.jar(javax/servlet/http/HttpServletRequest.class)
[ERROR] class file has wrong version 50.0, should be 49.0
This makes perfect sense, since if you use features of a later java version, i.e. 1.6, to build your application, then those features won’t be understood by an earlier Java JRE, i.e. 1.5, since they didn’t know what was coming in Java 1.6 yet. Yeah right.
But anyway, there are 2 quick ways to fix this. One is to find an earlier version of your Dependency, which was compiled using Java 1.5, and the other is to install a Java 1.6 JRE and get Maven to use that one. The later can be as simple as setting the JAVA_HOME environment variable to your Java 1.6 installation.
That’s it for this post.

http://hordine.wordpress.com/2012/05/02/class-file-has-wrong-version-50-0-should-be-49-0-by-maven/

Monday, June 11, 2012

Build failed question - maven - jre or jdk problem

You could try updating the JDK Eclipse is using, as follows:
Add and set the JRE in Window->Preferences...->Java->Installed JREs:
JRE type: Standard VM JRE Name: jdk1.6.0_18
JRE home directory: C:\Program Files (x86)\Java\jdk1.6.0_18
If this is not the case, it's possible that the brackets and spaces in the JAVA_HOME path are causing issues. Try copying your JDK to a different location and updating your JAVA_HOME.

http://stackoverflow.com/questions/2222560/build-failed-question-maven-jre-or-jdk-problem

Monday, May 28, 2012

Differences between Ant and Maven

In Maven: The Definitive Guide, I wrote about the differences between Maven and Ant in the introduction the section title is "The Differences Between Ant and Maven". Here's an answer that is a combination of the info in that introduction with some additional notes.
A Simple Comparison
I'm only showing you this to illustrate the idea that, at the most basic level, Maven has built-in conventions. Here's a simple Ant build file:
 name="my-project" default="dist" basedir=".">
    
        simple example build file
       
       
     name="src" location="src/main/java"/>
     name="build" location="target/classes"/>
     name="dist"  location="target"/>

     name="init">
      
      
      
       dir="${build}"/>   
    

     name="compile" depends="init"
        description="compile the source " >
      
       srcdir="${src}" destdir="${build}"/>  
    

     name="dist" depends="compile"
        description="generate the distribution" >
      
       dir="${dist}/lib"/>

      
       jarfile="${dist}/lib/MyProject-${DSTAMP}.jar" basedir="${build}"/>
   

    name="clean"
        description="clean up" >
     
      dir="${build}"/>
      dir="${dist}"/>
   
 
In this simple Ant example, you can see how you have to tell Ant exactly what to do. There is a compile goal which includes the javac task that compiles the source in the src/main/java directory to the target/classes directory. You have to tell Ant exactly where your source is, where you want the resulting bytecode to be stored, and how to package this all into a JAR file. While there are some recent developments that help make Ant less procedural, a developer's experience with Ant is in coding a procedural language written in XML.
Contrast the previous Ant example with a Maven example. In Maven, to create a JAR file from some Java source, all you need to do is create a simple pom.xml, place your source code in ${basedir}/src/main/java and then run mvn install from the command line. The example Maven pom.xml that achieves the same results.

  4.0.0
  org.sonatype.mavenbook
  my-project
  1.0

That's all you need in your pom.xml. Running mvn install from the command line will process resources, compile source, execute unit tests, create a JAR, and install the JAR in a local repository for reuse in other projects. Without modification, you can run mvn site and then find an index.html file in target/site that contains links to JavaDoc and a few reports about your source code.
Admittedly, this is the simplest possible example project. A project which only contains source code and which produces a JAR. A project which follows Maven conventions and doesn't require any dependencies or customization. If we wanted to start customizing the behavior, our pom.xml is going to grow in size, and in the largest of projects you can see collections of very complex Maven POMs which contain a great deal of plugin customization and dependency declarations. But, even when your project's POM files become more substantial, they hold an entirely different kind of information from the build file of a similarly sized project using Ant. Maven POMs contain declarations: "This is a JAR project", and "The source code is in src/main/java". Ant build files contain explicit instructions: "This is project", "The source is in src/main/java", "Run javac against this directory", "Put the results in target/classses", "Create a JAR from the ....", etc. Where Ant had to be explicit about the process, there was something "built-in" to Maven that just knew where the source code was and how it should be processed.
High-level Comparison
The differences between Ant and Maven in this example? Ant...
  • Ant doesn't have formal conventions like a common project directory structure, you have to tell Ant exactly where to find the source and where to put the output. Informal conventions have emerged over time, but they haven't been codified into the product.
  • Ant is procedural, you have to tell Ant exactly what to do and when to do it. You had to tell it to compile, then copy, then compress.
  • Ant doesn't have a lifecycle, you had to define goals and goal dependencies. You had to attach a sequence of tasks to each goal manually.
Where Maven...
  • Maven has conventions, it already knew where your source code was because you followed the convention. It put the bytecode in target/classes, and it produced a JAR file in target.
  • Maven is declarative. All you had to do was create a pom.xml file and put your source in the default directory. Maven took care of the rest.
  • Maven has a lifecycle, which you invoked when you executed mvn install. This command told Maven to execute the a series of sequence steps until it reached the lifecycle. As a side-effect of this journey through the lifecycle, Maven executed a number of default plugin goals which did things like compile and create a JAR.
What About Ivy?
Right, so someone like Steve Loughran is going to read that comparison and call foul. He's going to talk about how the answer completely ignores something called Ivy and the fact that Ant can reuse build logic in the more recent releases of Ant. This is true. If you have a bunch of smart people using Ant + antlibs + Ivy, you'll end up with a well designed build that works. Even though, I'm very much convinced that Maven makes sense, I'd happily use Ant + Ivy with a project team that had a very sharp build engineer. That being said, I do think you'll end up missing out on a number of valuable plugins such as the Jetty plugin and that you'll end up doing a whole bunch of work that you didn't need to do over time.
More Important than Maven vs. Ant
  1. Is that you use a Repository Manager to keep track of software artifacts. I'd suggest downloading Nexus. You can use Nexus to proxy remote repositories and to provide a place for your team to deploy internal artifacts.
  2. You have appropriate modularization of software components. One big monolithic component rarely scales over time. As you project developers, you'll want to have the concept of modules and sub-modules. Maven lends itself to this approach very well.
  3. You adopt some conventions for your build. Even if you use Ant, you should strive to adopt some form of convention that is consistent with other projects. When a project uses Maven, it means that anyone familiar with Maven can pick up the build and start running with it without having to fiddle with configuration just to figure out how to get the thing to compile.
http://stackoverflow.com/questions/603189/differences-between-ant-and-maven

Saturday, May 26, 2012

Maven or Ant?

Contrary to what @Joe Skora has said, with Maven 2 I have rarely needed to use ant in combination with Maven. Maven 1 was built on top of ant, so you often found yourself dropping down into ant related things. I rarely have, however, with Maven.
These are the reasons I advocate Maven:
  • Repeatable builds / Dependency Management. All it takes is a check out of your source and, if necessary, a Maven configuration file, and you can issue one command and all of the dependencies for your project will be downloaded and then the project will be built. No checking of binary jars into your source control, or manually copying things, or whatever. Also, it handles transitive dependencies. If you depend directly on one library, you don't have to list its dependencies as well. Maven automatically figures that out for you.
  • Versioned artifacts This is an extension of the above point. Any given Maven project is required to have a version number. When you deploy built resources to your internal Maven repositories, it is easy to point to any given version. After getting used to this method of development, it doesn't make sense to me any longer to not have versions of both the built artifacts and its dependencies when doing development.
  • Convention and configuration over scripting. Maven has set conventions for project layout. It constructs classpaths based upon your declared dependencies and their transitive dependencies. With ant, you have to explicitly write out XML "code" for the steps to compile, to construct jars, to set up your classpaths, etc. Maven is much more declarative.
  • IDEs Yes, many ides have Ant integration or are based upon ant. Yet, I find that many people who use ant built scripts tend to check in IDE project files (.project for Eclipse, for example) into source control. This is often bad because of pathnames and so forth. With Maven, out of the box you can generate project files for Eclipse and IDEA, and other IDE's like Netbeans can simply open existing Maven projects. No need to check configuration files into source control.
Those are my main reasons for advocating Maven. However, as others have noted, it is far from perfect:
  • The documentation is lacking in places.
  • Sometimes you have to do silly things to work around bugs in the dependency calculation mechanism.
  • It can be slow at times (though I hear this is being worked on).
The declarative dependency management and version artifacts alone have got me sold on Maven.

Unable to locate the Javac Compiler with Maven and Eclipse

Unable to locate the Javac Compiler in:
C:\Program Files\Java\jre6\..\lib\tools.jar
Please ensure you are using JDK 1.4 or above and
not a JRE (the com.sun.tools.javac.Main class is required).
In most cases you can change the location of your Java
installation by setting the JAVA_HOME environment variable.
The solution that worked for me (tested on both 32- and 64-bit Eclipse/Java) was not to change theeclipse.ini, but to instead set the Runtime JRE on the JRE tab of the Run/Debug Configuration dialog to use the appropriate JDK, either as the “Workspace default JRE” or the “Alternate JRE”


Wednesday, May 23, 2012

Why do so few people use Maven? Are there alternative tools?

I like Maven and use it almost exclusively in my company. But I'd justify my reasons for doing so:
  1. I run a team of developers and we need structure. I need most of my developers to follow a certain set of conventions down to project layouts. This is to make it easier for handovers when attrition occurs.
  2. Maven archetypes are a major blessing in this regard. The seniors would just create specific archetypes for certain project templates which all developers just base their projects on. There's a really simple generic one for those cases where we didn't manage to cater for. Checking out an ant-based layout from SVN is less intuitive in this regard as the developer will still need to remove the original .svn metadata once it's checked out.
  3. Maven helps us remain IDE-agnostic. I don't want to base any of my hiring policies on what IDE the developer prefers to use. At least 2 major IDEs (Eclipse and NetBeans) have pretty good integration to Maven already such that a pom.xml file already is the definition of an IDE project. I can tell any new developer that he can use whatever IDE he prefers as long as the build system itself is based on Maven.
  4. I found that the development bootstrap process for picking up things midway was drastically cut down when I switched to Maven. New developers, even those unfamiliar with the project at hand, was able to at least compile, package and deploy within half hour of briefing them of the project. Support staff (who are typically not as technically adept) were able to concentrate on troubleshooting and not fret about building the project, which is an unnecessary irritation.
All in all, Maven suits my needs perfectly. I do agree to a certain extent that an independent developer who has his own workflow and project management practices may not derive much benefit from it, but none of us over here work in a void by ourselves.

http://stackoverflow.com/questions/1077477/why-do-so-few-people-use-maven-are-there-alternative-tools

Sunday, October 23, 2011

Sonatype Nexus Maven Repository Manager

https://repository.sonatype.org/index.html#welcome

Sonatype Nexus™ Professional Version
Copyright © 2008-2011 Sonatype, Inc.
All rights reserved. Includes the third-party code listed at http://www.sonatype.com/products/nexus/attributions.
Sonatype and Sonatype Nexus are trademarks of Sonatype, Inc. Apache Maven is a trademark of the Apache Foundation.
M2Eclipse is a trademark of the Eclipse Foundation. All other trademarks are the property of their respective owners.

To see the full license terms for this Software: Click Here
The product EULA is: http://www.sonatype.com/products/nexus/EULA