Cargo run / start not working, missing Ant dependency? - maven

I've been trying to set up the cargo-maven2 plugin (although I am using Maven 3; and this is supposed to be ok) so that I can start a container during the pre-integration-test phase and shut it down in the post-integration test phase.
I'm having no luck. I keep getting this error message:
Failed to execute goal org.codehaus.cargo:cargo-maven2-plugin:1.2.4:start (start-container) on project microgivr.web: Execution start-container of goal org.codehaus.cargo:cargo-maven2-plugin:1.2.4:start failed: Unable to load the mojo 'start' in the plugin 'org.codehaus.cargo:cargo-maven2-plugin:1.2.4'. A required class is missing: org/apache/tools/ant/BuildException
Easy fix, right? Add Ant as a dependency. So I add:
<dependency>
<groupId>org.apache.ant</groupId>
<artifactId>ant</artifactId>
<version>1.8.4</version>
</dependency>
(And lord only know why this should need Ant in the first place.)
I can now find org.apache.tools.ant.BuildException on my classpath, but I STILL get this error.
So, thinking this is surely some issue with my own build, I decided to start fresh, using the maven2-cargo-plugin archetype documented here: http://cargo.codehaus.org/Maven2+Archetypes
You know what? Same problem!
I've tried different versions of the plugin. I've tried different versions of Ant. No luck.
Someone MUST have run into this before. I see mentions of this issue online, but don't see any solutions.
Any insight is appreciated!

Damnit. I guess I put the Ant dependency in the wrong spot. That dependency needs to be expressed in the plugin's OWN stanza; NOT with the rest of the dependencies.
So... moving it did the trick.

Related

maven-release-plugin - Not found

I am trying to add maven release plugin to pom.xml file but it returns
Plugin 'org.apache.maven.plugins:maven-release-plugin:' not found
What you're seeing is your IDE complaining that it doesn't know (yet) about this new plugin you've added. It looks like Intellij IDEA from Jetbrains, so my first advice would be to:
run a maven goal that includes this plugin; for example mvn release:help. This will make sure the plugin gets resolved and downloaded (it is in central so should give no problems)
you should also see the release plugin be listed in the maven tab in IDEA now under plugins
tell IDEA to update it's own state from maven. IDEA has a hard time detecting new plugins, as they're not part of the normal project build dependencies. See Force Intellij IDEA to reread all maven dependencies
If the maven goal runs fine, the plugin is working. Try refreshing in IDEA or closing + reopening the project a few times until IDEA gets it.
Regarding the "missing" version tag. If you're not specifing an exact version of the plugin to use, you're currently getting this plugin (version) from the maven super pom:
https://maven.apache.org/ref/3.8.5/maven-model-builder/super-pom.html
you can run the following maven command to view your combined effective pom; super pom, your own pom + default bindings: mvn help:effective-pom
your current configuration should be sufficient, but if you want more control you can specify a version explicitly. See the following link for available version: https://search.maven.org/artifact/org.apache.maven.plugins/maven-release-plugin
if you really want this "error" from IDEA to go away, you must specify the version. It seems IDEA doesn't understand that the version is inherited from the super pom. You can tell because the error message org.apache.maven.plugins:maven-release-plugin: is in the format of groupid:artifactid:version, and version is missing. Adding a version would look like something like this:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-release-plugin</artifactId>
<version>2.5.3</version>
</plugin>
(this is the default for maven 3.8.5, you can pick a newer version if you want)

A required class was missing while executing org.apache.axis2:axis-wsdl2code-maven-plugin:1.3

I am trying to upgrade my project running in 1.5 to 1.8(jdk), and I am using Maven 3.0.4 in conjunction. While trying to execute command "mvn build" I get the error "The required class was missing while executing org.apache.axis2:axis2-wsdl2code-maven-plugin:1.3:wsdl2code: org/apache/neethi/policy".
I have tried installing fresh jars and pom files, added them to the build path, also added it to POM dependencies. I even added axis2-codegen jar as suggested in some answer in this site. I've even tried "mvn -U clean install", also as suggested in one the answers. But so far nothing seems to work. I am fairly new to Maven, so any help will be appreciated.
P.S.: I cannot post any actual code or snapshots of the errors as it is a corporate project. I have tried to put up as much data as possible without breaching my NDA.
Thanks.
Since you did not get a compile error, I am assuming there should be conflicting transient dependencies.
Try executing,
mvn dependency:tree -Dincludes=org.apache.axis2
If you have multiple versions of the same dependency, have the unintended versions excluded in your pom file.
Note: You can do this operation in your IDE too. "IntelliJ Idea", has a really nice interface for this operation.

maven plugin execution issue

I am using aspectj in a project. when i add the aspectj-maven-plugin to the build, the aspects are woven in and things work as expected. however, i get an error in the POM saying that the plugin execution is not covered by lifecycle configuration.
from what i've read in other problems, it says the solution is to simply wrap the plugin in a pluginManagement tag. that does seem to get rid of the error, however, when i do a mvn clean install, the aspectj plugin no longer runs. any idea on how to solve that problem?

Maven can't discover workspace projects, junit, other libraries

so I have started using maven (with eclipse, and a local implementation of Sonatype) not that long ago, after getting through the initial pain I though everything was working.... apparently not !
I have my main project POM and all my child POM (I am using a 'flat' hierarchy, so all the sub projects are in the same folder as the parent POM). This seems to be working OK.
The sub project where all started and 'released' and tested before I started using Maven. I went to maven to solve my 'dependencies' problems... or rather make them more complicated in this instance.
Most of the 'Maven' stuff seems to work fine, but I can't resolve the dependencies of my 'sub projects' that have been released into my local ms/repository
Each day I start up eclipse and have the same problems, I have 'unable to resolve imports' on all my personal libraries, and all those that I use for them (such as Log4j, DDlUtils etc).
I thought the whole point of maven was that I would be able to put in an import declaration for a library, add the 'groupID' and other stuff to the child POM (or parent POM). And then have all the jars downloaded automagically when I run
mvn install
against the parent.
However each day I find I have to re-insert the build path to the libraries (internal and external) via the eclipse workspace and point them to the location of the libraries that I have downloaded as maven can't seem to find them anywhere.
Specifically with running Junit test, I can run them from the workspace (using run as junit) and they all pass fine. But if I try to run them with
mvn test
I get an message saying
java.lang;NoClassDefFoundError: org/junit/Assert
(and this is the same from within eclipse running the mvn test or from CLI)
with an error message in the output of
failed to execute goal org.apache.maven.plugins:maven.surfire-plugin:2.10:test
the POM and jar are in my M2_REPO, and I can find it when I search in sonatype, why can't maven find something that is part of its own system, exists in its repo.
but this obviously works just fine when I run via eclipse and point it to an independently downloaded junit library.
I don't know what extra info you may require, and I'm obviously missing something in either the m2e plugin, my maven install or in sonatype.
please help I'm begining to loose my hair!
and may soon be forced to return to an ant/ivy solution (but don't want to have to learn 'yet another tool' (in this case ivy).
Thanks in advance
David.
ps. i'm on a windows XP platform
edit...
can I get maven to build and release the jar and pom even though it thinks it is failing the tests (which is itn't as I'm doing them manually, and they pass just fine).
If I look in the 'effective POM' tab of my parent POM, the plugin stated above is not in there. I guess this means it is a maven config setting, but where do I add it, and why isn't it automatic when I run my first set of maven tests?
edit 2....
I just found this on the apache plugin comments page (http://maven.apache.org/plugins/maven-surefire-plugin/plugin-info.html), so I ran the code on the CLI, mvn surefire:help -Ddetail=true -Dgoal=test lots of stuff was downloaded, and now the tests run, but they fail within maven ? (remember they pass when run from eclipse using 'run as junit test)... so this is nearly a solution...
It sounds like you need make eclipse aware that the projects in question are Maven projects. You may have POMs set up for your projects, but for the m2e plugin to work you need to have either created the project as a Maven project ('New' -> 'Project...' -> 'Maven' -> 'Maven Project...'), or converted it into a Maven project by right clicking it then selecting 'Configure' -> 'Convert to Maven Project'. You will know that a project has been recognised as a Maven project because there will be a little blue 'M' in the top left of its icon, as shown in the screenshot below:
The main thing to note in the above picture is the 'Maven Dependencies' library. This is set up automatically by the m2e plugin. Whenever you add a dependency to a POM then the project's build path will be configured automatically, although sometimes you may need to force it to do so by right clicking the project and selecting 'Maven' -> 'Update Maven Configuration'. The important thing is that if everything is working then you should never have to update the build path yourself. Moveover, if you do update it yourself then any changes you make will likely get overwritten the next time you run the 'Update Maven Configuration' command.
Also worth noting from the picture is that the two dependencies 'mavenProjectTest' and 'primes' have folder icons next to them. This means that they have been picked up as workspace projects. For this to work the project must have 'workspace resolution' enabled, and the projects to be picked up need to be configured as m2e Maven projects as well.
You mention downloading external libraries. You shouldn't need to download any libraries yourself - by adding the right dependency declaration for an external library then Maven will download it from your configured remote repository (the first time anyway - afterwards it will then be able to get it from your local repository). By default, this is the Maven Central repository. To add an external library to your project just follow that link, enter the library in the search box, click on the version link for the version you require, then you will be taken to a page where there will be the dependency XML declaration that you can just copy and paste into your POM.
One more thing that may help is that you should make sure that your source folders follow the Maven default directory structure. That is, your test packages should be contained in a source folder called 'src/test/java', and the main project packages should go in 'src/main/java'. Otherwise Maven will not know where to find your source code. It is possible to configure a POM to tell Maven to expect your source code to be in different source folders, but it is highly recommended that you follow the standard Maven directory structure.
Since you have child modules, my suggestion would be to simplify things by creating a new Maven project from scratch that you can have a play around with. Once you are comfortable with that then try getting m2e to work for your multi-module project.
I remember your pain when first getting to grips with Maven, but it's great once you understand what it's doing and everything is working. I highly recommend reading through the free online book Maven: The Complete Reference - it helped me out a lot when I was getting started with Maven.
I have experienced the same messages and have found a working solution, thanks to one of my organization's Maven experts.
Here was my pom.xml that reproduces your error:
<dependencies>
<dependency>
<groupId>org.junit4</groupId>
<artifactId>org.junit4</artifactId>
<version>4.3.1</version>
</dependency>
</dependencies>
With it, I would get package org.junit does not exist messages and NoClassDefFoundError: org/junit/Assert. Similar to your experience, it worked great from Eclipse, green bars and all.
Here is the pom.xml that works:
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.8.1</version>
<scope>test</scope>
</dependency>
</dependencies>
I copied this from the example at the top of this Using JUnit page.

Maven not installing dependcies

i am new to maven so this could be something basic but i cant seem to get to the bottom of it.
I am running m2eclipse. I have a simple project that is trying to use the classes in the maven package for servlet-api (group id : javax.servlet artifact : servlet-api version 2.5 scope : compile ).
My repository where i assumed it would be pulled from, in my settings.xml (http://repo1.maven.org/maven2 ). I followed this url to verify that there was a jar and such at that address and there was (http://search.maven.org/#browse|-182598336)
however when i run mvn compiler:compile i get the (cannot find symbol
symbol : class HttpServletRequest )
also i looked in my repository and the jar's and poms that should be installed there are not. Other classes are but those are not.
i have looked in the debug info i got from the -X and it didnt seem to indicate anything was wrong.
I can post effective pom or whatever anyone would find helpful.
thanks in advance.
So I was able to solve the issue. It was a bit strange, but it seems to act differently if you select the pom and click to maven -> add Dependance. That will download and install the dependency.
If you add then directly to the pom (as i was doing before) there is an additional step that seems a bit strange and that is to select the project (again i am using m2eclipse) not the pom, and then click maven -> update dependencies ...
Seems odd because I am not running in offline mode, I would think that when i run mvn compiler:compile from the command line that it should notice that it needs to resolve the dependency and then go get it from the repository...
maybe there is a setting that i have to have to force this to happen?
In any event i hope this saves someone some time :)

Resources