Python_user
Python_user

Reputation: 1575

Java EE: Payara micro server not generating REST endpoints (404 error)

I am new to Java EE development. I downloaded Payara micro-server 6.2023.8 and generated a simple Java EE application through the maven archetype com.airhacks:javaee8-essentials-archetype:0.0.4 (https://github.com/AdamBien/javaee8-essentials-archetype).

However, when I deploy the war file (generated through mvn clean package) on the server through the command:

java -jar 'G:\Workspace\payara-micro-6.2023.8.jar' --deploy .\target\javaee-demo.war --port 8080

, the REST endpoint (http://localhost:8080/javaee-demo/resources/ping) is not exposed and generates a 404 error when accessed via a browser. The only URL present in the logged output against 'Payara Micro URLs' is http://localhost:8080/javaee-demo.

Here's my resource (generated automatically from the archetype used):

@Path("ping")
public class PingResource {

    @Inject
    @ConfigProperty(name = "message")
    String message;

    @GET
    public String ping() {
        return this.message + " Jakarta EE with MicroProfile 2+!";
    }
}

Here's my JAX-RS configuration file:

@ApplicationPath("resources")
public class JAXRSConfiguration extends Application {

}

And, here's the (partial) output of running the above command:

"Deployed": [
    {
        "Name": "javaee-demo",
        "Type": "war",
        "Context Root": "/javaee-demo"
    }
]

pom.xml file for reference:

<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>in.mydemoprojects</groupId>
    <artifactId>javaee-demo</artifactId>
    <version>1.0-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>javaee-demo</finalName>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-war-plugin</artifactId>
                <version>3.3.1</version>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.8.1</version>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                </configuration>
            </plugin>
        </plugins>
    </build>
    <properties>
        <maven.compiler.source>1.8</maven.compiler.source>
        <maven.compiler.target>1.8</maven.compiler.target>
        <failOnMissingWebXml>false</failOnMissingWebXml>
    </properties>
</project>

I looked into the other stackoverflow questions about this, but to no avail. Can someone please help me debug?

Upvotes: 1

Views: 577

Answers (3)

Opara Benjamin
Opara Benjamin

Reputation: 11

The issue sometimes has to do with your <jta-data-source> in persistence.xml if not properly configured, the endpoints will not be exposed.

Try removing it temporarily to see if it helps.

I had the same issue but was able to test my app with the in-memory h2 db.

Upvotes: 0

diwigo
diwigo

Reputation: 1

I had the same issue by deploying this simple Java EE application with Payara micro 6.2023.11. The REST end points are not exposed. As a workaround I switched to Payara micro 5.2021.7, ran the same command again and with this version it works.

By the way - I am using OpenJDK 11 - it seems to have nothing to do with the Java version, but that an additional setting and/or annotation is required for Payara micro server 6.2023.11 to make it work with this version too. But since I am also new to programming Java EE and using an application server, I don't know the real reason for the "inconsistency".

Upvotes: 0

adoughdough
adoughdough

Reputation: 107

I meandered my way around this same problem as below. You may want to try it too:

  1. Use jdk-1.8, confirm this by running the command java -version on command prompt.
  2. If the command returns a different version, then: 2.1. download and install jdk-1.8. 2.2. go to the bin folder created as a result of the installation. 2.3. copy at least (and perhaps, javac, javaw) the file "java.exe" and paste it in the folder (let's call it "folderA") where java looks for executables. 2.4. on my windows machine, the "folderA" is in "C:\Program Files\Common Files\Oracle\Java\javapath". 2.5 run the command in #2 above again, ensure Jdk-1.8.xxx is returned.
  3. Download Payara Microedition 5.181 (not version 6.0) from here: https://jar-download.com/artifacts/fish.payara.extras/payara-micro/5.181/source-code
  4. In your POM file, add the following dependencies:

dependencies

<dependency>
    <groupId>jakarta.xml.bind</groupId>
    <artifactId>jakarta.xml.bind-api</artifactId>
    <version>3.0.0</version>
</dependency>
<dependency>
    <groupId>org.glassfish.jaxb</groupId>
    <artifactId>jaxb-runtime</artifactId>
    <version>2.3.2</version>
</dependency>
<dependency>
        <groupId>com.sun.xml.bind</groupId>
        <artifactId>jaxb-impl</artifactId>
        <version>3.0.0</version>
</dependency>
  1. Attempt to deploy your app on payara again, it should work. There's probably a better solution out there though.

Upvotes: 0

Related Questions