Response status code 500 on JAX-RS 3.0 application deployed to Tomcat 10 - jax-rs

I have a JAX-RS 3.0 application that is run in Tomcat 10.
The pom.xml:
<properties>
<endorsed.dir>${project.build.directory}/endorsed</endorsed.dir>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
</properties>
<dependencies>
<!-- the REST API -->
<dependency>
<groupId>jakarta.ws.rs</groupId>
<artifactId>jakarta.ws.rs-api</artifactId>
<version>3.0.0</version>
</dependency>
<!-- These next two are needed because we are using Tomcat, which -->
<!-- is not a full JEE server - it's just a servlet container. -->
<!-- the Jersey implementation -->
<dependency>
<groupId>org.glassfish.jersey.containers</groupId>
<artifactId>jersey-container-servlet</artifactId>
<version>3.0.2</version>
</dependency>
<!-- also needed for dependency injection -->
<dependency>
<groupId>org.glassfish.jersey.inject</groupId>
<artifactId>jersey-hk2</artifactId>
<version>3.0.2</version>
</dependency>
<!-- support for using Jackson (JSON) with Jersey -->
<dependency>
<groupId>org.glassfish.jersey.media</groupId>
<artifactId>jersey-media-json-jackson</artifactId>
<version>3.0.2</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<source>15</source>
<target>15</target>
<compilerArguments>
<endorseddirs>${endorsed.dir}</endorseddirs>
</compilerArguments>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>3.3.1</version>
<configuration>
<failOnMissingWebXml>false</failOnMissingWebXml>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>3.1.2</version>
<executions>
<execution>
<phase>validate</phase>
<goals>
<goal>copy</goal>
</goals>
<configuration>
<outputDirectory>${endorsed.dir}</outputDirectory>
<silent>true</silent>
<artifactItems>
<artifactItem>
<groupId>javax</groupId>
<artifactId>javaee-endorsed-api</artifactId>
<version>7.0</version>
<type>jar</type>
</artifactItem>
</artifactItems>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
and the config class for application path:
import jakarta.ws.rs.ApplicationPath;
import jakarta.ws.rs.core.Application;
#ApplicationPath("api")
public class App extends Application {
// the entry class - deliberately empty in this basic demo
}
and DemoResource:
import jakarta.ws.rs.Consumes;
import jakarta.ws.rs.GET;
import jakarta.ws.rs.POST;
import jakarta.ws.rs.Path;
import jakarta.ws.rs.PathParam;
import jakarta.ws.rs.Produces;
import jakarta.ws.rs.core.MediaType;
import jakarta.ws.rs.core.Response;
//
// Pingable at:
// http://localhost:8080/JaxRsDemo/api/demo/ping
//
#Path("/demo")
public class DemoResource {
#GET
#Path("/ping")
public String ping() {
System.out.println("%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%");
return "Service online";//Response.ok("Service online", MediaType.APPLICATION_JSON).build();
}
}
So I make it as .war file and put it in webapp of tomcat 10 and it is deployed successfully.
I request such http://localhost:8080/JaxRsDemo-1.0-SNAPSHOT/api/demo/ping, the ping() method of DemoResource is fired and System.out.println("%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%"); is shown in console of tomcat but there is no response-body in client side like browser and the status of response in browser is 500.
Where is wrong and something is missed in my sample application?

Related

Karate : Visual Studio Code: java.lang.ClassNotFoundException: com.intuit.karate.cli.Main

Error when I run the file.
An exception occured while executing the Java class. Using visual studio code for api tets
com.intuit.karate.cli.Main ->
java.lang.ClassNotFoundException: com.intuit.karate.cli.Main
at java.net.URLClassLoader.findClass (URLClassLoader.java:471)
at java.lang.ClassLoader.loadClass (ClassLoader.java:588)
at java.lang.ClassLoader.loadClass (ClassLoader.java:521)
at org.codehaus.mojo.exec.ExecJavaMojo$1.run (ExecJavaMojo.java:270)
at java.lang.Thread.run (Thread.java:834)
Running karate feature file in visual studio code.
This is how my pom.xml file looks
<?xml version="1.0" encoding="UTF-8" ?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.allegion.engage</groupId>
<artifactId>Engage</artifactId>
<version>0.0.1</version>
<name>Engage</name>
<!-- FIXME change it to the project's website -->
<url>http://www.example.com</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>com.intuit.karate</groupId>
<artifactId>karate-apache</artifactId>
<version>0.9.4</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.intuit.karate</groupId>
<artifactId>karate-junit4</artifactId>
<version>0.9.4</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.8</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>net.masterthought</groupId>
<artifactId>cucumber-reporting</artifactId>
<version>3.8.0</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<testResources>
<testResource>
<directory>src/test/java</directory>
<excludes>
<exclude>**/*.java</exclude>
</excludes>
</testResource>
</testResources>
<pluginManagement>
<!-- lock down plugins versions to avoid using Maven defaults (may be moved to parent pom) -->
<plugins>
<!-- clean lifecycle, see https://maven.apache.org/ref/current/maven-core/lifecycles.html#clean_Lifecycle -->
<plugin>
<artifactId>maven-clean-plugin</artifactId>
<version>3.1.0</version>
</plugin>
<!-- default lifecycle, jar packaging: see https://maven.apache.org/ref/current/maven-core/default-bindings.html#Plugin_bindings_for_jar_packaging -->
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>3.0.2</version>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.1</version>
<configuration>
<skipTests>true</skipTests>
</configuration>
</plugin>
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<version>3.0.2</version>
</plugin>
<plugin>
<artifactId>maven-install-plugin</artifactId>
<version>2.5.2</version>
</plugin>
<plugin>
<artifactId>maven-deploy-plugin</artifactId>
<version>2.8.2</version>
</plugin>
<!-- site lifecycle, see https://maven.apache.org/ref/current/maven-core/lifecycles.html#site_Lifecycle -->
<plugin>
<artifactId>maven-site-plugin</artifactId>
<version>3.7.1</version>
</plugin>
<plugin>
<artifactId>maven-project-info-reports-plugin</artifactId>
<version>3.0.0</version>
</plugin>
</plugins>
</pluginManagement>
</build>
</project>
package com.allegion.engage.Login;
import com.intuit.karate.KarateOptions;
#KarateOptions(features = "classpath:Login/Login.feature")
public class LoginRunner{
}
Feature: Login and get the token
Scenario: Login and get the token
Given url loginUrl
And request {username: 'someusername', password: 'test' }
When method POST
Then status 200
And def authToken = response
Then print authToken
Kindly helo if I have missed any run configurations. I am using vscode in mac.
com.intuit.karate.cli.Main is only in 0.9.5 onwards, so can you point your dependencies to karate version 0.9.5.RC3
This is mentioned in the docs BTW: https://marketplace.visualstudio.com/items?itemName=kirkslota.karate-runner

How using parameter "-Dsurefire.skipAfterFailureCount=1" to skip tests after the first crash

I have a Maven test project. In which I use context-related tests. I use maven-surefire-plugin to run tests.
I need to make the test stop running after the first failed test. I found a way to do this through -Dsurefire.skipAfterFailureCount=1, but it doesn't work. Maybe I'm doing something wrong? Below is my pom.xml:
<properties>
<selenide.version>5.3.0</selenide.version>
<junit.jupiter.version>5.5.1</junit.jupiter.version>
<selenium.java.version>3.141.59</selenium.java.version>
<allure.junit5.version>2.12.1</allure.junit5.version>
<aspectj.version>1.8.10</aspectj.version>
<maven.surefire.plugin.version>3.0.0-M3</maven.surefire.plugin.version>
<junit.platform.launcher>1.5.2</junit.platform.launcher>
<junit.jupiter.engine>5.5.2</junit.jupiter.engine>
<junit.vintage.engine>5.5.2</junit.vintage.engine>
<allure.maven.version>2.10.0</allure.maven.version>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>${maven.surefire.plugin.version}</version>
<configuration>
<argLine>-javaagent:"${settings.localRepository}/org/aspectj/aspectjweaver/${aspectj.version}/aspectjweaver-${aspectj.version}.jar"
-Dsurefire.skipAfterFailureCount=1
</argLine>
<systemProperties>
<property>
<name>allure.results.directory</name>
<value>${project.build.directory}/allure-results</value>
</property>
</systemProperties>
</configuration>
</plugin>
</plugins>
</build>
Also I tried this option:
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>${maven.surefire.plugin.version}</version>
<configuration>
<skipAfterFailureCount>1</skipAfterFailureCount>
<argLine>-javaagent:"${settings.localRepository}/org/aspectj/aspectjweaver/${aspectj.version}/aspectjweaver-${aspectj.version}.jar"</argLine>
<systemProperties>
<property>
<name>allure.results.directory</name>
<value>${project.build.directory}/allure-results</value>
</property>
</systemProperties>
</configuration>
</plugin>
</plugins>
</build>
Does anyone know how to solve this problem? Why is my code not working? Did I make a mistake somewhere?
This works in jUnit 4. I don't know why your code isn't working, but maybe this will help.
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M4</version>
<configuration>
<skipAfterFailureCount>1</skipAfterFailureCount>
</configuration>
</plugin>
</plugins>
</build>
add the plugin.
<dependencies>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>5.7.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M5</version>
<type>maven-plugin</type>
</dependency>
</dependencies>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M5</version>
<configuration>
<skipAfterFailureCount>1</skipAfterFailureCount>
</configuration>
</plugin>
</plugins>
don't use #TestMethodOrder in your code.
import java.util.HashMap;
import jp.co.nisshinsci.saas.framework.dto.Member;
import org.junit.jupiter.api.MethodOrderer;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestMethodOrder;
// #TestMethodOrder(MethodOrderer.DisplayName.class)
public class test {
#Test
void test01() throws Exception {
HashMap stringHashMap = new HashMap();
long xxx = ((Member) stringHashMap.get("xxx")).photoVersion;
}
#Test
void test02() throws Exception {
HashMap stringHashMap = new HashMap();
long xxx = ((Member) stringHashMap.get("xxx")).photoVersion;
}
#Test
void test03() throws Exception {
HashMap stringHashMap = new HashMap();
long xxx = ((Member) stringHashMap.get("xxx")).photoVersion;
}
}
test by maven, not by Intellij Idea.

Commons Logging - ClassNotFoundException

For whatever reason I can't seem to run my jar file without receiving a ClassNotFound Exception. I am new to Maven, so I believe the issue could be caused by my POM.XML file. Allow me to elaborate. I have isolated the problem to an example HelloWorld log.
package com;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
public class HelloLog {
public static Log log = LogFactory.getLog(HelloLog.class);
public static void main(String[] args){
log.info("Hello World!");
}
}
I have also simplified my pom.xml to only two dependencies.
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>--MygroupId--</groupId>
<artifactId>--MyArtID--</artifactId>
<version>--MyVer--</version>
<dependencies>
<dependency>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
<version>1.1.3</version>
</dependency>
<dependency>
<groupId>org.hibernate.javax.persistence</groupId>
<artifactId>hibernate-jpa-2.0-api</artifactId>
<version>1.0.1.Final</version>
</dependency>
</dependencies>
<build>
<sourceDirectory>src</sourceDirectory>
<resources>
<resource>
<directory>src</directory>
<excludes>
<exclude>**/*.java</exclude>
</excludes>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.4</version>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<classpathPrefix>lib</classpathPrefix>
<mainClass>com.HelloLog</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<verbose>true</verbose>
<fork>true</fork>
<compilerVersion>1.6</compilerVersion>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.5.1</version>
<executions>
<execution>
<id>copy-dependencies</id>
<phase>package</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<outputDirectory>
${project.build.directory}/dependency-jars/
</outputDirectory>
<overWriteReleases>false</overWriteReleases>
<overWriteSnapshots>false</overWriteSnapshots>
<overWriteIfNewer>true</overWriteIfNewer>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
<pluginManagement>
<plugins>
<!--This plugin's configuration is used to store Eclipse m2e settings only. It has no influence on the Maven build itself.-->
<plugin>
<groupId>org.eclipse.m2e</groupId>
<artifactId>lifecycle-mapping</artifactId>
<version>1.0.0</version>
<configuration>
<lifecycleMappingMetadata>
<pluginExecutions>
<pluginExecution>
<pluginExecutionFilter>
<groupId>
org.apache.maven.plugins
</groupId>
<artifactId>
maven-dependency-plugin
</artifactId>
<versionRange>
[2.5.1,)
</versionRange>
<goals>
<goal>copy-dependencies</goal>
</goals>
</pluginExecutionFilter>
<action>
<ignore></ignore>
</action>
</pluginExecution>
</pluginExecutions>
</lifecycleMappingMetadata>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
</project>
When I run the HelloLog class in Eclipse all is good and I get the expected output. However, when I execute java -jar on the Jar file I receive the ClasNotFoundException on LogFactory at line 7. The jar file is accompanied in the target folder with the dependency-jars folder. The dependency-jars folder holds these two dependencies.
Found the problem, it was Maven related. Hadn't noticed my classpathPrefix was set as lib. Where as I outputted the dependencies to dependency-jars.

scalatest selenium example compile error

I'm new to scala but want very much to use ScalaTest with Selenium. I copy and pasted the example directly from http://www.scalatest.org/user_guide/using_selenium. But got the an error in the statement below
"The blog app home page" should "have the correct title" in {
go to (host + "index.html")
pageTitle should be ("Awesome Blog")
}
The error being on the 'in' keyword just before '{', which says:
Multiple markers at this line
- Implicit conversions found: "The blog app home page" should "have the correct title" =>
convertToInAndIgnoreMethods("The blog app home page" should "have the correct title")
- overloaded method value in with alternatives: (testFun: BlogSpec.this.FixtureParam => Any)Unit
(testFun: () => Any)Unit cannot be applied to (Unit)
- overloaded method value in with alternatives: (testFun: BlogSpec.this.FixtureParam => Any)Unit
(testFun: () => Any)Unit cannot be applied to (Unit)
- Implicit conversions found: "The blog app home page" => convertToStringShouldWrapper("The
blog app home page")
I believe I'm picking up all the right versions via maven:
<dependency>
<groupId>org.scala-lang</groupId>
<artifactId>scala-library</artifactId>
<version>2.10.2</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.specs2</groupId>
<artifactId>specs2_2.10</artifactId>
<version>1.13</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.scalatest</groupId>
<artifactId>scalatest_2.10</artifactId>
<version>2.0.M6-SNAP8</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>2.37.0</version>
</dependency>
...
<plugin>
<!-- see http://davidb.github.com/scala-maven-plugin -->
<groupId>net.alchim31.maven</groupId>
<artifactId>scala-maven-plugin</artifactId>
<version>3.1.3</version>
<executions>
<execution>
<goals>
<goal>compile</goal>
<goal>testCompile</goal>
</goals>
<configuration>
<args>
<arg>-make:transitive</arg>
<arg>-dependencyfile</arg>
<arg>${project.build.directory}/.scala_dependencies</arg>
</args>
</configuration>
</execution>
</executions>
</plugin>
Tried lots to get around this but failed. Any help would be much appreciated. Tried also https://bitbucket.org/olimination/hello-scalajava.git, but failed to get that running due to maven errors.
This one seems to be quite an old question and maybe you've already managed to get through, but the sample compiles for me.
I think the problem was in the import statements, for example IntelliJ Idea seems to suggest wrong ones and it all seems ok when using import org.scalatest._, else I would get exactly your compilation error.
This is the full source:
import org.openqa.selenium.WebDriver
import org.openqa.selenium.htmlunit.HtmlUnitDriver
import org.scalatest.selenium.WebBrowser
import org.scalatest._
class BlogSpec extends FlatSpec with ShouldMatchers with WebBrowser {
implicit val webDriver : WebDriver = new HtmlUnitDriver
val host = "http://localhost:9000/"
"The blog app home page" should "have the correct title" in {
go to (host + "index.html")
pageTitle should be("Awesome Blog")
}
}
I suggest using the latest versions of the frameworks and plugin (and Scala too if you can, here I'm keeping 2.10 anyway), this is my pom.xml:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>test</groupId>
<artifactId>scalatest-selenium</artifactId>
<version>1.0-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>org.scala-lang</groupId>
<artifactId>scala-library</artifactId>
<version>2.10.2</version>
</dependency>
<dependency>
<groupId>org.scalatest</groupId>
<artifactId>scalatest_2.10</artifactId>
<version>2.2.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>2.42.2</version>
</dependency>
</dependencies>
<build>
<plugins>
<!-- disable surefire -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.7</version>
<configuration>
<skipTests>true</skipTests>
</configuration>
</plugin>
<!-- enable scalatest -->
<plugin>
<groupId>org.scalatest</groupId>
<artifactId>scalatest-maven-plugin</artifactId>
<version>1.0</version>
<configuration>
<reportsDirectory>${project.build.directory}/surefire-reports</reportsDirectory>
<junitxml>.</junitxml>
<filereports>WDF TestSuite.txt</filereports>
</configuration>
<executions>
<execution>
<id>test</id>
<goals>
<goal>test</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<!-- see http://davidb.github.com/scala-maven-plugin -->
<groupId>net.alchim31.maven</groupId>
<artifactId>scala-maven-plugin</artifactId>
<version>3.1.7-SNAPSHOT</version>
<executions>
<execution>
<goals>
<goal>compile</goal>
<goal>testCompile</goal>
</goals>
<configuration>
<args>
<arg>-make:transitive</arg>
<arg>-dependencyfile</arg>
<arg>${project.build.directory}/.scala_dependencies</arg>
</args>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>

maven custom lifecycle is not recognized

I am trying to test a simple custom plugin with custom lifecycle.
Here is my EchoMojo.java file:
package org.sonatype.mavenbook.plugins;
import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
/**
* Echos an object string to the output screen.
* #goal echo
* #execute lifecycle="custom-echo" phase="package"
*/
public class EchoMojo extends AbstractMojo
{
/**
* Any Object to print out.
* #parameter expression="${echo.message}" default-value="Hello World..."
*/
private Object message;
public void execute()
throws MojoExecutionException, MojoFailureException
{
getLog().info( message.toString() );
}
}
My pom.xml looks like this:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven- v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.sonatype.mavenbook.plugins</groupId>
<artifactId>echotest-maven-plugin</artifactId>
<packaging>maven-plugin</packaging>
<version>1.0-SNAPSHOT</version>
<name>echotest-plugin Maven Mojo</name>
<url>http://maven.apache.org</url>
<build>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
</build>
<dependencies>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-plugin-api</artifactId>
<version>2.0</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
I added this in my settings.xml:
<pluginGroups>
<pluginGroup>org.sonatype.mavenbook.plugins</pluginGroup>
</pluginGroups>
I created META-INF/maven/lifecycle.xml
<lifecycles>
<lifecycle>
<id>custom-echo</id>
<phases>
<phase>
<id>package</id>
<executions>
<execution>
<goals>
<goal>echo</goal>
</goals>
</execution>
</executions>
</phase>
</phases>
</lifecycle>
</lifecycles>
I have created META-INF/plexus/components.xml
<component-set>
<components>
<component>
<role>org.apache.maven.lifecycle.mapping.LifecycleMapping</role>
<role-hint>custom-echo</role-hint>
<implementation>org.apache.maven.lifecycle.mapping.DefaultLifecycleMapping</implementation>
<configuration>
<phases>
<package>org.sonatype.mavenbook.plugins:echotest-maven-plugin:echo</package>
</phases>
</configuration>
</component>
</components>
</component-set>
When i do mvn echotest:echo, I get "Build Sucessfull".
When i do mvn custom-echo, I get "[ERROR] Unknown lifecycle phase "custom-echo"."
All i wanted is to active my custom plugin when i execute "mvn custom-echo", where custom-echo is a custom lifecycle name
Can someone help me out please.