I am trying to run a simple app in Jakarta 9 that has a simple REST web service that returns hello world. However, when I try to access the web service using the localhost:8080/<context_root>/<application_path>/<resource_path I get 404. When I just target localhost:8080/<context_root> everything runs fine (I have an index.html in the project).
Here is some additional info. I am running the app packaged as a WAR inside Wildfly 25 running inside the Docker container.
Here's the relevant file content
pom.xml:
<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.tyuiop32</groupId>
<artifactId>TimeTracking</artifactId>
<version>1.0</version>
<packaging>war</packaging>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
<failOnMissingWebXml>false</failOnMissingWebXml>
</properties>
<dependencies>
<dependency>
<groupId>jakarta.platform</groupId>
<artifactId>jakarta.jakartaee-web-api</artifactId>
<version>9.0.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.auth0</groupId>
<artifactId>java-jwt</artifactId>
<version>3.8.3</version>
</dependency>
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-jpa</artifactId>
<version>1.11.23.RELEASE</version>
</dependency>
</dependencies>
<build>
<finalName>TimeTracking</finalName>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.10.1</version>
</plugin>
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>3.3.2</version>
<configuration>
<failOnMissingWebXml>false</failOnMissingWebXml>
</configuration>
</plugin>
</plugins>
</build>
</project>
ApplicationConfig.java:
package com.poortoys;
import jakarta.ws.rs.ApplicationPath;
import jakarta.ws.rs.core.Application;
/**
* Register Jakarta REST resources.
*
*/
#ApplicationPath("")
public class ApplicationConfig extends Application {
}
HelloResource.java:
package com.poortoys.examples;
import jakarta.enterprise.context.RequestScoped;
import jakarta.ws.rs.GET;
import jakarta.ws.rs.Path;
import jakarta.ws.rs.Produces;
import jakarta.ws.rs.core.MediaType;
/**
* Sample JAX-RS resources.
*
*/
#Path("test")
#RequestScoped
public class HelloResource {
#GET
#Path("hello")
#Produces(MediaType.APPLICATION_JSON)
public String getMessage() {
return "Hello, world";
}
}
When I try to GET http://localhost:8080/TimeTracking/test/hello I get 404
Targeting just http://localhost:8080/TimeTracking returns the content of the index.html page that is placed inside the webapp folder
PS: I went trough all the relevant threads and didn't find the asnwer
You'd need to use WildFly 27. WildFly 25 is a Jakarta EE 8 container while WildFly 27 is a Jakarta EE 10 container. You could use WildFly 25 Preview, but I would suggest using WildFly 27.
Related
I am trying to deploy a simple Rest API to Google Cloud Functions. Per this documentation, I need the target to always be org.springframework.cloud.function.adapter.gcp.GcfJarLauncher
However when I deploy it using the provided code, I get:
ERROR: (gcloud.alpha.functions.deploy) OperationError: code=3, message=Build failed:
build succeeded but did not produce the class "org.springframework.cloud.function.adapter.gcp.GcfJarLauncher"
specified as the function target: Error: class not found: org.springframework.cloud.function.adapter.gcp.GcfJarLauncher;
Error ID: d818fd83
Here is the code I am running in the Cloud CLI:
gcloud alpha functions deploy function-sample-gcp-http --entry-point org.springframework.cloud.function.adapter.gcp.GcfJarLauncher --runtime java11 --trigger-http --source target/deploy --memory 512MB
Here my code repo but I will include some relevant bits below
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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.7.5</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.divr-fx-test</groupId>
<artifactId>divr-function</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>divr-function</name>
<description>Function testing for DIVR</description>
<properties>
<java.version>11</java.version>
<spring-cloud-function.version>4.0.0-SNAPSHOT</spring-cloud-function.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-function-web</artifactId>
<version>3.2.8</version>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-function-web</artifactId>
<version>3.2.8</version>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-function-dependencies</artifactId>
<version>3.2.8</version>
<type>pom</type>
</dependency>
<dependency>
<groupId>com.google.cloud.functions</groupId>
<artifactId>functions-framework-api</artifactId>
<version>1.0.4</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-function-adapter-gcp</artifactId>
<version>3.2.8</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<!-- Build an executable JAR -->
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<classpathPrefix>lib/</classpathPrefix>
<mainClass>com.mypackage.MyClass</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<outputDirectory>target/deploy</outputDirectory>
</configuration>
</plugin>
<plugin>
<groupId>com.google.cloud.functions</groupId>
<artifactId>function-maven-plugin</artifactId>
<version>0.9.1</version>
<configuration
<functionTarget>org.springframework.cloud.function.adapter.gcp.GcfJarLauncher</functionTarget>
<port>8080</port>
</configuration>
</plugin>
</plugins>
</build>
</project>
Main:
package com.fkgcp;
import java.util.function.Function;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;
#SpringBootApplication
public class DivrFunctionApplication {
public static void main(String[] args) {
SpringApplication.run(DivrFunctionApplication.class, args);
}
// this part I don't actually want to use, but it is present
// in every tutorial, so I included it to see if it would be
// triggered instead of my REST functions
#Bean
public Function<String, String> uppercase() {
return value -> value.toUpperCase();
}
}
Also, I added a MANIFEST.MF, is it in the right location?
divr-function/src/main/resources/META-INF/MANIFEST.MF
Contents:
Main-Class: com.fkgcp.DivrFunctionApplication
What am I missing?
Reviewing your source code repository, I think the issue can be caused because you need to reference the spring-cloud-function-adapter-gcp library as a dependency of the spring-boot-maven-plugin in addition to include it as a dependency in your pom.xml file:
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<outputDirectory>target/deploy</outputDirectory>
</configuration>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-function-adapter-gcp</artifactId>
</dependency>
</dependencies>
</plugin>
According to the Spring Cloud documentation:
Notice that we also reference spring-cloud-function-adapter-gcp as a
dependency of the spring-boot-maven-plugin. This is necessary because it
modifies the plugin to package your function in the correct JAR format for
deployment on Google Cloud Functions.
In addition, and although probably unrelated, consider remove your maven-jar-plugin configuration from your pom.xml: the spring-boot-maven-plugin already provides all the necessary functionality to generate the jar you need to deploy and the configuration provided by the maven-jar-plugin may be a cause of errors.
On the other hand, your MANIFEST.MF file looks fine to me and it is placed in the right location.
I am getting below error while running application in java using jax-rs
HTTP Status 404 – Not Found
Type Status Report
Message /ajavaeeconcurrency/resources/greetUser
Description The origin server did not find a current representation for the target resource or is not willing to disclose that one exists.
Apache Tomcat/9.0.30
I am using java8 and trying to create restAPI using jax-rs
Below is the code
package com.app.rest;
import javax.ws.rs.ApplicationPath;
import javax.ws.rs.core.Application;
#ApplicationPath("resources")
public class JAXRSConfiguration extends Application {
}
Below is resource class
package com.app.rest;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
#Path("/greetUser")
public class GreetResource {
#GET
public String greetUser()
{
return "java EE concurrency starts.";
}
This is my pom.xml
<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.mycompany</groupId>
<artifactId>ajavaeeconcurrency</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>
<dependencies>
<dependency>
<groupId>javax</groupId>
<artifactId>javaee-api</artifactId>
<version>8.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.eclipse.microprofile</groupId>
<artifactId>microprofile</artifactId>
<version>2.0.1</version>
<type>pom</type>
<scope>provided</scope>
</dependency>
</dependencies>
<build>
<finalName>ajavaeeconcurrency</finalName>
</build>
<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<failOnMissingWebXml>false</failOnMissingWebXml>
</properties>
</project>
My artifactId is ajavaeeconcurrency . I am trying to access resource using below URI
GET http://localhost:8080/ajavaeeconcurrency/resources/greetUser
I am getting 404 error. How can I resolve the same
I think your URL is http://localhost:8080/resources/greetUser.
URL with artifactId part usually configuried in application server if it need.
I am trying to deploy a spring boot application as a WAR to a tomcat server. I can build and deploy the war to the tomcat server just fine. When I start the server though my spring application never runs. The server starts up just fine. I have done everything Spring says to do here,
http://docs.spring.io/spring-boot/docs/current/reference/htmlsingle/#howto-create-a-deployable-war-file
My project has its own custom Parent POM and consists of 2 modules.
I have read several other similar threads and as far as I can tell I have everything set up properly but clearly something is wrong. Any help would be much appreciated.
THank You!
Parent pom
<groupId>com.project</groupId>
<artifactId>TelematicsNotificationSystem</artifactId>
<name>TelematicsNotificationSystem</name>
<version>1.0.0-SNAPSHOT</version>
<packaging>pom</packaging>
<properties>
<java.version>1.8</java.version>
<artifact-deployer.version>2.0.0-RELEASE</artifact-deployer.version>
<cxf.version>2.5.2</cxf.version>
<start-class>com.project.TNS.TelematicsNotificationSystem</start-class>
</properties>
<modules>
<module>TelematicsNotificationSystem-wsclient</module>
<module>TelematicsNotificationSystem-web</module>
</modules>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
<version>1.5.0.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<version>1.5.0.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
<version>1.5.0.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<optional>true</optional>
<version>1.5.0.RELEASE</version>
</dependency>
<dependency>
<groupId>com.sun.mail</groupId>
<artifactId>javax.mail</artifactId>
<version>1.5.6</version>
</dependency>
<dependency>
<groupId>org.springframework.ldap</groupId>
<artifactId>spring-ldap-core</artifactId>
<version>1.3.0.RELEASE</version>
</dependency>
</dependencies>
Web Project Pom
<artifactId>TelematicsNotificationSystem-Web</artifactId>
<name>TelematicsNotificationSystem-Web</name>
<packaging>war</packaging>
<parent>
<groupId>com.project</groupId>
<artifactId>TelematicsNotificationSystem</artifactId>
<version>1.0.0-SNAPSHOT</version>
</parent>
<properties>
<start-class>com.project.TNS.TelematicsNotificationSystem</start-class>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<resources>
<resource>
<filtering>true</filtering>
<directory>src/main/resources/</directory>
</resource>
</resources>
</configuration>
</plugin>
</plugins>
</build>
My Application Class
package TNS;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.context.web.SpringBootServletInitializer;
#SpringBootApplication
public class TelematicsNotificationSystem extends SpringBootServletInitializer{
public static void main(String[] args) {
SpringApplication.run(TelematicsNotificationSystem.class, args);
}
#Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
return application.sources(TelematicsNotificationSystem.class);
}
}
Remember to refresh the application once deployed in Tomcat. It may be working well and only a refresh is needed.
Although I agree with Deinum that I needed to clean up my Pom that was not the overall fix. The fix was to simply add a component scan to my class which contained my main method.
#SpringBootApplication
#ComponentScan(basePackageClasses = DashBoardController.class)
public class TelematicsNotificationSystem extends SpringBootServletInitializer
The starting app couldn't find the Controller so it could handle any of my mapping requests.
I started to play with JavaEE stuff, especially RESTEasy and I try to put together an small service packaged by maven. The service is done, ear package is created and deployed to a WildFly 10 server. No errors, but I'm not able to reach/call the service method.
I went through a lot of questions and answers here and according to them my app should work and I should be able to call it. One thing I don't know and haven't found any documentation so far how the url to reach the application is created.
The main question here: what are the rules of this url creation? Where can I find it?
So far, I have seen the following parameters can affect the url:
war file name (which one, the original (ends with SNAPSHOT string, or the finalName parameter defined in the rest project's pom.xml or the bundleFileName in ear package's pom.xml? Does thi war file name matters if war file is packaged into an ear?)
context root value defined in pom.xml of ear project (it is copied to application.xml file)
#ApplicationPath annotation over the Application class of RestEasy
web.xml if there is any
#Path values over the service classes and methods
Let's see my application.
My app consist of 3 maven module. There is the main module (pom module) having two modules, a, ear package module, b, rest api module creates war file. Pom.xml files are below.
Maven modules:
The pom module doesn't do anything.
The ear module puts together the ear file, and importantly it renames the war file to MasterData.Rest.Api.war.
The rest api web module produces a war file.
Eventually, the ear file looks like this:
Masterdata.Dataservice.ear
Masterdata.Dataservice.ear/MasterData.Rest.Api.war
No web.xml file, and no jboss.xml file.
According to a few articles and example the Currency/Currencies method should be available using the following urls (neither of them working):
http://localhost:8080/Currency/Currencies
or http://localhost:8080/MasterData.Rest.Api.war/Currency/Currencies
Just simply deploying the war file doesn't work too. By default the file has this ugly name: digitallibrary.dataservice.masterdata.rest.api-1.0-SNAPSHOT.war. After successful deployment the endpoint should be available here:
http://localhost:8080/digitallibrary.dataservice.masterdata.rest.api-1.0-SNAPSHOT.war/Currency/Currencies
It doesn't work.
Wildfly says the following and it can mean that the application can be accessed via the following urls (I'm just guessing...), but neither of them working...
http://localhost:8080/Currency/Currencies
http://localhost:8080/MasterData.Dataservice.ear/Currency/Currencies (it doesn't have any point in my opinion)
http://localhost:8080/MasterData.Dataservice.ear/MasterData.Rest.Api.war/Currency/Currencies
http://localhost:8080/MasterData.Rest.Api.war/Currency/Currencies
Wildfly's deployment log.
19:58:17,673 INFO [org.jboss.as.server.deployment] (MSC service thread 1-5) WFLYSRV0027: Starting deployment of "MasterData.Dataservice.ear" (runtime-name: "MasterData.Dataservice.ear")
19:58:17,682 INFO [org.jboss.as.server.deployment] (MSC service thread 1-4) WFLYSRV0207: Starting subdeployment (runtime-name: "MasterData.Rest.Api.war")
19:58:17,712 INFO [org.wildfly.extension.undertow] (ServerService Thread Pool -- 111) WFLYUT0021: Registered web context: /
19:58:17,727 INFO [org.jboss.as.server] (DeploymentScanner-threads - 1) WFLYSRV0010: Deployed "MasterData.Dataservice.ear" (runtime-name : "MasterData.Dataservice.ear")
Server is running and no errors.
package app;
import endpoints.CurrencyEndpoint;
import javax.ws.rs.ApplicationPath;
import javax.ws.rs.core.Application;
import java.util.HashSet;
import java.util.Set;
/**
* Created by SayusiAndo on 6/9/2017.
*/
public class MasterDataRestEndpointApplication extends Application {
private Set<Object> singletons = new HashSet<Object>();
public MasterDataRestEndpointApplication() {
singletons.add(new CurrencyEndpoint());
}
#Override
public Set<Class<?>> getClasses() {
HashSet<Class<?>> set = new HashSet<Class<?>>();
return set;
}
#Override
public Set<Object> getSingletons() {
return singletons;
}
}
package endpoints;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import java.util.ArrayList;
/**
* Created by SayusiAndo on 6/9/2017.
*/
#Path("/currency")
public class CurrencyEndpoint {
#GET
#Path("/currencies")
#Produces(MediaType.APPLICATION_JSON)
public Response getCurrencies() {
ArrayList list = new ArrayList<String>();
list.add("currency1");
list.add("currency2");
return Response
.status(Response.Status.OK)
.entity(list)
.build();
}
}
POM module 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>com.sayusiando</groupId>
<artifactId>digitallibrary.dataservice.masterdata</artifactId>
<packaging>pom</packaging>
<version>1.0-SNAPSHOT</version>
<modules>
<module>digitallibrary.dataservice.masterdata.rest.api</module>
<module>digitallibrary.dataservice.masterdata.package.ear</module>
</modules>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.6.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.wildfly.plugins</groupId>
<artifactId>wildfly-maven-plugin</artifactId>
<version>1.2.0.Alpha4</version>
</plugin>
</plugins>
</build>
</project>
EAR module 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">
<parent>
<artifactId>digitallibrary.dataservice.masterdata</artifactId>
<groupId>com.sayusiando</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<packaging>ear</packaging>
<artifactId>digitallibrary.dataservice.masterdata.package.ear</artifactId>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.6.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-ear-plugin</artifactId>
<version>2.10.1</version>
<configuration>
<finalName>MasterData.Dataservice</finalName>
<modules>
<webModule>
<groupId>com.sayusiando</groupId>
<artifactId>digitallibrary.dataservice.masterdata.rest.api</artifactId>
<bundleFileName>MasterData.Rest.Api.war</bundleFileName>
<contextRoot>/</contextRoot>
</webModule>
</modules>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>com.sayusiando</groupId>
<artifactId>digitallibrary.dataservice.masterdata.rest.api</artifactId>
<version>1.0-SNAPSHOT</version>
<type>war</type>
</dependency>
</dependencies>
</project>
REST module 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">
<parent>
<artifactId>digitallibrary.dataservice.masterdata</artifactId>
<groupId>com.sayusiando</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<packaging>war</packaging>
<artifactId>digitallibrary.dataservice.masterdata.rest.api</artifactId>
<dependencies>
<dependency>
<groupId>javax.ws.rs</groupId>
<artifactId>javax.ws.rs-api</artifactId>
<version>2.1-m07</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.jboss.resteasy</groupId>
<artifactId>resteasy-servlet-initializer</artifactId>
<version>3.1.2.Final</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.jboss.resteasy</groupId>
<artifactId>resteasy-jaxrs</artifactId>
<version>3.1.2.Final</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.jboss.resteasy</groupId>
<artifactId>resteasy-jaxb-provider</artifactId>
<version>3.1.2.Final</version>
<scope>provided</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.6.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>3.1.0</version>
<configuration>
<failOnMissingWebXml>false</failOnMissingWebXml>
</configuration>
</plugin>
</plugins>
</build>
</project>
Generated application.xml file:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE application PUBLIC
"-//Sun Microsystems, Inc.//DTD J2EE Application 1.3//EN"
"http://java.sun.com/dtd/application_1_3.dtd">
<application>
<display-name>digitallibrary.dataservice.masterdata.package.ear</display-name>
<module>
<web>
<web-uri>MasterData.Rest.Api.war</web-uri>
<context-root>/</context-root>
</web>
</module>
</application>
I made a few mistakes, but I learned a few things.
First mistake:
For some reason I removed the #ApplicationPath() annotation over the RestEasy application path. Not having this and web.xml Wildfly didn't know what to do these classes. So they were not registered.
Putting back the #ApplicationPath() annotation, and removing the web.xml made the situation better.
Second mistake:
For some reason ( :) ), I checked the http://localhost:8000 instead of http://localhost:8080. The latter is WildFly's site. The first one is nothing.
Answering my questions:
Name of EAR and WAR files do not matter in this case
The url is created according to the following: http://{host}:{port}/{applicationPathvalue}/{pathValueOfClass}/{pathValueOfMethod}
In my case:
{host}: localhost
{port}: 8080
{applicationPathValue}: api (check the code sample below)
{pathValueOfClass}: currency (check the code in my question)
{pathValueOfMethod}: currencies (check the code in my question)
#ApplicationPath("/api")
public class MasterDataRestEndpointApplication extends Application {
private Set<Object> singletons = new HashSet<Object>();
public MasterDataRestEndpointApplication() {
singletons.add(new CurrencyEndpoint());
}
#Override
public Set<Class<?>> getClasses() {
HashSet<Class<?>> set = new HashSet<Class<?>>();
return set;
}
#Override
public Set<Object> getSingletons() {
return singletons;
}
}
I'm using Eclipse Kepler with M2E plugin for Maven.
I want to create web-app Maven project using my "Util" Maven project - this is not a multi-module project. Just want this simple .jar in project, with possibility to edit "Util" project with enhancements and fixes during work with main project.
I have added only the maven dependency in webb app (no settings like build path, deployment assembly etc.) and Eclipse figured out automatically that this is project from workspace (simply: not seen as .jar with version number but with folder icon)
Now, when I install "Util" in maven repo and close project, everything works fine and Eclipse is deploying my util-0.0.1-SNAPSHOT.jar to web-inf/lib as working .jar file.
The problem is: when util project is opened, eclipse just creates "util.jar" in deployment (not util-0.0.1-SNAPSHOT.jar) and deploy it as "jar-like-war" with classes put in WEB-INF/classes/ instead of root of jar, so I end up with something like:
...\wtpwebapps\BigProject\WEB-INF\lib\util.jar\WEB-INF\classes\ which results with simple ClassNotFoundException, because "Util" projet is not a web project - only .jar with simple classes.
How to add Maven dependency on simple util project in web app, still having an option to edit util project any time in workspace?
Have the same setup like you and it works OK. When I work on small project and do mvn install JAR is not deployed at target as projName-0.0.1-SNAPSHOT.jar though. Do both projects have same <groupID>?.
EDIT:
Had some time and also had something ready so I did some tests. I am sorry for the long post but this is what works for me. I am working with the WildFly server.
1/<groupID> doesn't have to be the same after all
2a/Here is the pom.xml of the utils jar
<?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/maven-v4_0_0.xsd">
<!-- =========================================================== -->
<!-- Basics -->
<!-- =========================================================== -->
<modelVersion>4.0.0</modelVersion>
<groupId>so.examples</groupId>
<artifactId>utils</artifactId>
<version>0.0.1</version>
<packaging>jar</packaging>
<name>WebApp Common files</name>
<description>WebApp Common files</description>
<!-- =========================================================== -->
<!-- Properties -->
<!-- =========================================================== -->
<properties>
<!-- other plugin versions -->
<version.compiler.plugin>2.3.2</version.compiler.plugin>
<version.surefire.plugin>2.4.3</version.surefire.plugin>
<!-- maven-compiler-plugin -->
<maven.compiler.target>1.7</maven.compiler.target>
</properties>
<dependencyManagement>
<dependencies>
</dependencies>
</dependencyManagement>
<dependencies>
</dependencies>
<build>
<!-- Maven will append the version to the finalName -->
<finalName>${project.artifactId}</finalName>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>${version.compiler.plugin}</version>
<configuration>
<source>${maven.compiler.source}</source>
<target>${maven.compiler.target}</target>
</configuration>
</plugin>
</plugins>
</build>
</project>
2b/ And the class file
package utils.commons;
public class PrintUtilities
{
public static String addArrowPrint(String toPrint)
{
return "--->"+toPrint+"<----";
}
}
3a/Here is the pom.xml of the webApp
<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>so.examples</groupId>
<artifactId>webapp</artifactId>
<packaging>war</packaging>
<version>0.0.1</version>
<description>Main WebApp project</description>
<properties>
<!-- Explicitly declaring the source encoding eliminates the following
message: -->
<!-- [WARNING] Using platform encoding (UTF-8 actually) to copy filtered
resources, i.e. build is platform dependent! -->
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<!-- JBoss dependency versions -->
<version.jboss.maven.plugin>7.4.Final</version.jboss.maven.plugin>
<!-- Define the version of the JBoss BOMs we want to import to specify
tested stacks. -->
<version.jboss.bom>1.0.7.Final</version.jboss.bom>
<!-- other plugin versions -->
<version.surefire.plugin>2.10</version.surefire.plugin>
<version.war.plugin>2.1.1</version.war.plugin>
<!-- maven-compiler-plugin -->
<maven.compiler.target>1.7</maven.compiler.target>
<maven.compiler.source>1.7</maven.compiler.source>
</properties>
<dependencyManagement>
<dependencies>
<!-- JBoss distributes a complete set of Java EE 6 APIs including a Bill
of Materials (BOM). A BOM specifies the versions of a "stack" (or a collection)
of artifacts. We use this here so that we always get the correct versions
of artifacts. Here we use the jboss-javaee-6.0-with-tools stack (you can
read this as the JBoss stack of the Java EE 6 APIs, with some extras tools
for your project, such as Arquillian for testing) and the jboss-javaee-6.0-with-hibernate
stack you can read this as the JBoss stack of the Java EE 6 APIs, with extras
from the Hibernate family of projects) -->
<dependency>
<groupId>org.jboss.bom</groupId>
<artifactId>jboss-javaee-6.0-with-tools</artifactId>
<version>${version.jboss.bom}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<dependency>
<groupId>org.jboss.bom</groupId>
<artifactId>jboss-javaee-6.0-with-hibernate</artifactId>
<version>${version.jboss.bom}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>so.examples</groupId>
<artifactId>jar_lib</artifactId>
<version>0.0.1</version>
</dependency>
<!-- First declare the APIs we depend on and need for compilation. All
of them are provided by JBoss AS 7 -->
<!-- Import the Common Annotations API (JSR-250), we use provided scope
as the API is included in JBoss AS 7 -->
<dependency>
<groupId>org.jboss.spec.javax.annotation</groupId>
<artifactId>jboss-annotations-api_1.1_spec</artifactId>
<scope>provided</scope>
</dependency>
<!-- Import the JAX-RS API, we use provided scope as the API is included
in JBoss AS 7 -->
<dependency>
<groupId>org.jboss.spec.javax.ws.rs</groupId>
<artifactId>jboss-jaxrs-api_1.1_spec</artifactId>
<scope>provided</scope>
</dependency>
<!-- Import the EJB API, we use provided scope as the API is included in
JBoss AS 7 -->
<dependency>
<groupId>org.jboss.spec.javax.ejb</groupId>
<artifactId>jboss-ejb-api_3.1_spec</artifactId>
<scope>provided</scope>
</dependency>
<!-- Import the JSF API, we use provided scope as the API is included in
JBoss AS 7 -->
<dependency>
<groupId>org.jboss.spec.javax.faces</groupId>
<artifactId>jboss-jsf-api_2.1_spec</artifactId>
<scope>provided</scope>
</dependency>
<!-- Now we declare any tools needed -->
</dependencies>
<build>
<!-- Maven will append the version to the finalName (which is the name
given to the generated war, and hence the context root) -->
<finalName>${project.artifactId}</finalName>
<plugins>
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>${version.war.plugin}</version>
<configuration>
<!-- Java EE 6 doesn't require web.xml, Maven needs to catch up! -->
<failOnMissingWebXml>false</failOnMissingWebXml>
</configuration>
</plugin>
<!-- The JBoss AS plugin deploys your war to a local JBoss AS container -->
<!-- To use, run: mvn package jboss-as:deploy -->
<plugin>
<groupId>org.jboss.as.plugins</groupId>
<artifactId>jboss-as-maven-plugin</artifactId>
<version>${version.jboss.maven.plugin}</version>
</plugin>
<plugin>
<groupId>org.wildfly.plugins</groupId>
<artifactId>wildfly-maven-plugin</artifactId>
<version>1.0.1.Final</version>
</plugin>
</plugins>
</build>
<profiles>
<profile>
<!-- The default profile skips all tests, though you can tune it to run
just unit tests based on a custom pattern -->
<!-- Seperate profiles are provided for running all tests, including Arquillian
tests that execute in the specified container -->
<id>default</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<build>
<plugins>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>${version.surefire.plugin}</version>
<configuration>
<skip>true</skip>
</configuration>
</plugin>
</plugins>
</build>
</profile>
</profiles>
3b/ and here are the class files:
RESTActivator
package webapp;
import javax.ws.rs.ApplicationPath;
import javax.ws.rs.core.Application;
#ApplicationPath("/root")
public class RESTActivator extends Application {
}
RestMethods
package webapp;
import javax.ejb.LocalBean;
import javax.ejb.Stateless;
import javax.ws.rs.*;
import utils.commons.PrintUtilities;
#Stateless
#LocalBean
#Path("/methods")
public class RestMethods {
#GET()
#Produces("text/plain")
public String welcomeMessage()
{
StringBuffer welcomeText = new StringBuffer();
welcomeText.append(" Called Rest Methods \n");
welcomeText.append(" ==================== \n");
welcomeText.append(PrintUtilities.addArrowPrint("Called Rest Methods") + "\n");
return welcomeText.toString();
}
}//class
4/ I first do a mvn clean install for the utils project. After it is installed in my local maven repo. Then do a update project with eclipse on my web app project and then clean package wildfly:deploy (server must be already started).
Then point your browser to http://localhost:8080/webapp/root/methods
Hope this helps.