CopyPastor

Detecting plagiarism made easy.

Score: 1; Reported for: Exact paragraph match Open both answers

Possible Plagiarism

Reposted on 2024-09-04
by Basil Bourque

Original Post

Original - Posted on 2024-09-04
by Basil Bourque



            
Present in both answers; Present only in the new answer; Present only in the old answer;

## Update for *Jakarta EE 11*, in year 2024
Oracle has donated Java EE technologies to the Eclipse Foundation where it became [Jakarta EE][1].
Jakarta EE defines specifications and interfaces for enterprise-oriented technologies. Jakarta EE does *not* provide any implementations. Implementing is left to third-parties such as other projects at the Eclipse Foundation, or at the Apache Foundation, or by vendors, or by anyone who cares to write an implementation.
[*Jakarta RESTful Web Services*][2] (formerly JAX-RS) makes it very easy to write [REST][3] oriented servers or clients.
## Web app
For a Web app, specify the library of interfaces provided by the Jakarta EE project.
```xml <!-- https://mvnrepository.com/artifact/jakarta.ws.rs/jakarta.ws.rs-api --> <dependency> <groupId>jakarta.ws.rs</groupId> <artifactId>jakarta.ws.rs-api</artifactId> <version>4.0.0</version> <scope>provided</scope> </dependency> ```
In the [POM][4] snippet above, note the `scope` of `provided` (see [manual][5]). The value `provided` means you want a copy of the library downloaded for your project to use when compiling, but do *not* want the library included in your final software artifact (your WAR file).
Notice that you do *not* need to specify an implementation. Your code you write will address only the Jakarta interfaces, without any direct knowledge of the implementation. When you run your Web app, you will run within a Jakarta EE compliant server. Being Jakarta EE compliant means that web server will bring its own copy of the Jakarta interfaces, and will bring some implementation of those interfaces. For example:
- *Glassfish* server brings [*Eclipse Jersey*][6] as its implementation. - *Wildfly* server brings [*RESTEasy*][7]. - *TomEE* server brings [*Apache CXF*][8].
## Desktop app
If you are writing a desktop app rather than Web app, either as a console app or with a GUI, then you need to obtain and include both the interfaces and an implementation. A desktop app runs without any Jakarta EE server.
You will research the [various implementations available][9], and decide which best meets your needs. Then add a depending in your POM for your product of choice.
```xml <!-- https://mvnrepository.com/artifact/jakarta.ws.rs/jakarta.ws.rs-api --> <dependency> <groupId>jakarta.ws.rs</groupId> <artifactId>jakarta.ws.rs-api</artifactId> <version>4.0.0</version> <scope>compile</scope> </dependency>
… add another dependency here for implementation of your choice … ```
Notice the `scope` here is `compile` which means you want the dependency library available during compilation *and* you want a copy included in your final software artifact (likely a JAR file).
For more details, see my related Answers on other Questions, [here][10] and [here][11].

[1]: https://jakarta.ee/ [2]: https://jakarta.ee/specifications/restful-ws/ [3]: https://en.wikipedia.org/wiki/REST [4]: https://en.wikipedia.org/wiki/Apache_Maven#Project_Object_Model [5]: https://maven.apache.org/guides/introduction/introduction-to-dependency-mechanism.html#Dependency_Scope [6]: https://en.wikipedia.org/wiki/Eclipse_Jersey [7]: https://docs.resteasy.dev/ [8]: https://en.wikipedia.org/wiki/Apache_CXF [9]: https://en.wikipedia.org/wiki/Jakarta_RESTful_Web_Services#Implementations [10]: https://stackoverflow.com/a/78946546/642706 [11]: https://stackoverflow.com/a/78947104/642706
## Interface vs Implementation
At compile time, you need only the interfaces (API) defined in the [*Jakarta RESTful Web Services* specification][1] (formerly JAX-RS). Those interfaces are defined in a library provided by the [*Jakarta EE*][2] project at the [Eclipse Foundation][3] (Oracle having donated *Java EE*).
You need a copy of that library of interfaces (API) for use at compile-time, so the compiler understands your calls to *Jakarta RESTful Web Services*. Include that as a dependency in your Maven POM file. Mark the dependency with a `scope` of `provided` so the library is *not* included in your final software artifact (your WAR file).
```xml <!-- https://mvnrepository.com/artifact/jakarta.ws.rs/jakarta.ws.rs-api --> <dependency> <groupId>jakarta.ws.rs</groupId> <artifactId>jakarta.ws.rs-api</artifactId> <version>4.0.0</version> <scope>provided</scope> </dependency> ```
>What Maven Artifact Contains javax.ws.rs.Path?
The artifact is `jakarta.ws.rs-api` shown in that `dependency` element quoted above. This artifact is produced by the Jakarta EE project. The Jakarta EE project does *not* produce an implementation; implementing is the job of third-parties. Those third-parties might happen to be other projects at the Eclipse Foundation, or at the Apache Foundation, or commercial vendors, or anybody who wants to write an implementation.
> How do I find out what jar, or what Maven artifact contains the necessary classes
- The **interfaces** for *Jakarta RESTful Web Services* are found in the artifact `jakarta.ws.rs-api` discussed directly above. - An **implementation** of those interfaces is provided at runtime by the Jakarta EE compliant server of your choice.
At present, multiple parties provide various implementations of the *Jakarta RESTful Web Services* interfaces. See a [list at Wikipedia][4].
## Choosing *Apache CXF* implementation
> I would like to try the Apache CXF implementation
That is irrelevant during development time. Your code only calls on the methods defined in the interfaces of the API library discussed above. Your code knows nothing about the *Apache CXF* implementation of those interfaces.
Your web app will only encounter *Apache CXF* at runtime, not compile-time. Your web app will run in some kind of Jakarta EE compliant server. That server, being Jakarta EE compliant, will provide its own copy of *both* the interfaces *and* an implementation. If you want to use *Apache CXF*, obtain a Jakarta EE compliant server product that chose *Apache CXF* as its implementation.
Notice in the POM below that we specify only the `jakarta.ws.rs-api` library of interfaces as a dependency. No mention there of an implementation. If we deploy to [*Glassfish*][5] server, [*Eclipse Jersey*][6] will be the bundled implementation. If we deploy to [*Wildfly*][7], [*RESTEasy*][8] will be the bundled implementation. If you want *Apache CXF* as your implementation, use a Jakarta EE compliant server whose creators made that choice.
### *Apache TomEE*
[*Apache TomEE*][9] is one Jakarta EE compliant server using *Apache CXF* as its choice for an implementation of *Jakarta RESTful Web Services*.
Other server products may use *Apache CXF*.
## *Hello World* example app
> Restful Java with JAX-RS … to make a "Hello World" web service
Here is the source code for two simple classes needed to make a RESTful Web Service. Code provided by the new-project template in IntelliJ 2024.2 Ultimate Edition.
This example is aimed at [Jakarta EE 11][10] generation of interfaces and implementations.
```java package work.basil.example.exjakartarestserver;
import jakarta.ws.rs.ApplicationPath; import jakarta.ws.rs.core.Application;
@ApplicationPath ( "/api" ) public class HelloApplication extends Application { } ```
… and:
```java package work.basil.example.exjakartarestserver;
import jakarta.ws.rs.GET; import jakarta.ws.rs.Path; import jakarta.ws.rs.Produces;
@Path ( "/hello-world" ) public class HelloResource { @GET @Produces ( "text/plain" ) public String hello ( ) { return "Hello, World!"; } } ```
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 https://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion>
<groupId>work.basil.example</groupId> <artifactId>ExJakartaRestServer</artifactId> <version>1.0-SNAPSHOT</version> <name>ExJakartaRestServer</name> <packaging>war</packaging>
<properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <maven.compiler.release>22</maven.compiler.release> </properties>
<dependencies>
<!-- https://mvnrepository.com/artifact/jakarta.ws.rs/jakarta.ws.rs-api --> <dependency> <groupId>jakarta.ws.rs</groupId> <artifactId>jakarta.ws.rs-api</artifactId> <version>4.0.0</version> <scope>provided</scope> </dependency>
<!-- https://mvnrepository.com/artifact/org.junit.jupiter/junit-jupiter --> <dependency> <groupId>org.junit.jupiter</groupId> <artifactId>junit-jupiter</artifactId> <version>5.11.0</version> <scope>test</scope> </dependency>
</dependencies>
<build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-war-plugin</artifactId> <version>3.4.0</version> </plugin> </plugins> </build> </project> ```
See more in-depth discussion of this example at [my Answer][11] on another Question.

[1]: https://jakarta.ee/specifications/restful-ws/ [2]: https://jakarta.ee/ [3]: https://en.wikipedia.org/wiki/Eclipse_Foundation [4]: https://en.wikipedia.org/wiki/Jakarta_RESTful_Web_Services#Implementations [5]: https://en.wikipedia.org/wiki/GlassFish [6]: https://en.wikipedia.org/wiki/Eclipse_Jersey [7]: https://en.wikipedia.org/wiki/WildFly [8]: https://docs.resteasy.dev/ [9]: https://en.m.wikipedia.org/wiki/Apache_TomEE [10]: https://jakartaee.github.io/platform/jakartaee11/JakartaEE11ReleasePlan [11]: https://stackoverflow.com/a/78946546/642706

        
Present in both answers; Present only in the new answer; Present only in the old answer;