Absent Code attribute in method that is not native or abstract in class file javax/ws/rs/core/Application - jax-rs

I have developed RESTful web service and use org.restlet.ext.servlet.ServerServlet.createApplication to load class javax.ws.rs.core.Application.
However it threw this Exception:Absent Code attribute in method that is not native or abstract in class file javax/ws/rs/core/Application
This is the dependency:
<groupId>javax</groupId>
<artifactId>j2ee6</artifactId>
<version>1.0</version>
<scope>system</scope>
<systemPath>${project.basedir}/WebContent/WEB-INF/lib/j2ee6.jar</systemPath>
</dependency>
This jar file is under /WebContent/WEB-INF/lib/
And my project run with jdk11 & wildfly22
I don't know why this error happed, anyone can help?

Related

Using MaterialFX in IntelliJ

I've been trying to use MaterialFX (which is a JavaFX design library (like jFoenix)) in IntelliJ but I didn't succeed to do so. I've added the required dependency:
Also, I've added the requires org.glavo.materialfx.adapter; in module-info.java:
module org.example {
requires javafx.controls;
requires javafx.fxml;
requires com.jfoenix;
requires org.glavo.materialfx.adapter;
opens org.example to javafx.fxml;
exports org.example;
}
Does anyone have an idea how can I use this library because the author didn't really explain well how to do so. I would like to mention that it works perfectly in Scene Builder's latest version so I just wonder why it doesn't do so in IntelliJ.
Use Maven (or Gradle) for dependency management
You are using Maven (at least that is what the screenshot shows in Idea, though it could be Gradle making use of a Maven repository).
You should define the dependency as a maven dependency in your pom.xml (or build.gradle) then reimport the build file into Idea.
You should not manually set library dependencies in Idea.
Idea and Maven will recognize that you have a modular project and, when you have the dependency defined in Maven, they will automatically put the new dependent module on the modulepath for compilation and execution.
The maven artifact can be found by searching the maven repository:
https://search.maven.org/artifact/io.github.palexdev/materialfx/11.13.5/jar
The dependency info is:
<dependency>
<groupId>io.github.palexdev</groupId>
<artifactId>materialfx</artifactId>
<version>11.13.5</version>
</dependency>
The module-info for MaterialsFX requires VirtualizedFX. The VirtualizedFX module also needs to be on your module path. The pom.xml file for MaterialsFX has a includes a dependency on io.github.palexdev:virtualizedfx:11.2.6. So the dependent module will be accessible for your build and runtime automatically via Mavan and Idea's inbuilt integration with the Java Platform Module System.
Require the correct module name
The module name for the library is not org.glavo.materialfx.adapter, it is MaterialFX, so you should use:
requires MaterialFX;
NOT:
requires org.glavo.materialfx.adapter;
I recommend that you spend some time studying tutorials for your build tool and the Java Platform Module System.
Example app
Example was created by running the idea new JavaFX project wizard, then modifying the resultant project.
pom.xml
In addition to having a dependency for the MaterialFX library, you also need to have dependencies for both javafx-controls and javafx-fxml.
MaterialFX requires both of these transitively at build and runtime (even if you don't use fxml in your application).
The MaterialFX pom.xml does not have an explicit dependency configuration for JavaFX, so you need to define those dependencies in your project pom.xml (which you would want to do in any case to ensure that your application is using a specific JavaFX version).
<?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>com.example</groupId>
<artifactId>material</artifactId>
<version>1.0-SNAPSHOT</version>
<name>material</name>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-controls</artifactId>
<version>18</version>
</dependency>
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-fxml</artifactId>
<version>18</version>
</dependency>
<dependency>
<groupId>io.github.palexdev</groupId>
<artifactId>materialfx</artifactId>
<version>11.13.5</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.9.0</version>
<configuration>
<source>18</source>
<target>18</target>
</configuration>
</plugin>
</plugins>
</build>
</project>
module-info.java
module com.example.material {
requires MaterialFX;
exports com.example.material;
}
MaterialApplication.java
package com.example.material;
import io.github.palexdev.materialfx.controls.MFXButton;
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.stage.Stage;
public class MaterialApplication extends Application {
#Override
public void start(Stage stage) {
stage.setScene(new Scene(new MFXButton("mfx")));
stage.show();
}
public static void main(String[] args) {
launch();
}
}

How to use Bean Validation in a Helidon App?

I'm trying to create a simple Rest Resource using Helidon-MP but for some reason it doesn't work when I add the bean validation annotations on my method.
#POST
public Response generatePlan(#Valid #ValidPlan JsonObject payload) {
// some logic here
}
Is this the expected behavior? Or Should I add some dependency or configuration?
I tried to find something on the documentation, but I couldn't.
Thanks
I ended up doing as #LairdNelson answered and added the following dependencies in my pom.xml:
<dependency>
<groupId>org.hibernate.validator</groupId>
<artifactId>hibernate-validator</artifactId>
<version>6.1.5.Final</version>
</dependency>
<dependency>
<groupId>org.hibernate.validator</groupId>
<artifactId>hibernate-validator-cdi</artifactId>
<version>6.1.5.Final</version>
</dependency>
<dependency>
<groupId>jakarta.el</groupId>
<artifactId>jakarta.el-api</artifactId>
</dependency>
<dependency>
<groupId>org.glassfish</groupId>
<artifactId>jakarta.el</artifactId>
</dependency>
Bean validation is not part of the MicroProfile set of specifications, so by default it is not part of Helidon MP, which is a MicroProfile implementation.
You may of course add an implementation of Bean Validation on your compile or runtime classpath provided it is a CDI portable extension (which is how you add arbitrary capabilities to any MicroProfile-compliant implementation). One such portable extension is the Hibernate Validator-backed one. There may certainly be others.

Unable to run a simple cucumber feature file in intelliJ

I've just installed the community edition of IntelliJ and the Cucumber integration. When I try to run a feature, I get the error below. How do I fix this? I have cucumber-core 4.7.2 and gherkin 7.0.4.
Feature: OrangeHRM Login
Scenario: Logo presence on OrangeHRM home page
Given I launch chrome browser
When I open orangeHRM homepage
Then I verify that the logo present on page
And close the browser
Error :
WARNING: You are using deprecated Main class. Please use io.cucumber.core.cli.Main
Exception in thread "main" java.lang.NoClassDefFoundError: gherkin/IGherkinDialectProvider
at io.cucumber.core.options.CommandlineOptionsParser.parse(CommandlineOptionsParser.java:24)
at io.cucumber.core.options.CommandlineOptionsParser.parse(CommandlineOptionsParser.java:29)
at io.cucumber.core.cli.Main.run(Main.java:29)
at cucumber.api.cli.Main.run(Main.java:28)
at cucumber.api.cli.Main.main(Main.java:15)
Caused by: java.lang.ClassNotFoundException: gherkin.IGherkinDialectProvider
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:583)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521)
... 5 more
Process finished with exit code 1
As stated by #mpkorstanje, you are using the wrong version of Gherkin with this version of Cucumber.
You don't need to add a Gherkin dependency yourself; this can be managed by your build tool (Maven/Gradle).
As stated in the docs, you only need the cucumber-java or cucumber-java8 dependency. Which one you need, depends on whether you want to write annotated methods or lambdas, respectively:
If you are going to use the lambda expressions API (Java 8) to write the step definitions, add the following dependency to your pom.xml:
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-java8</artifactId>
<version>4.7.1</version>
<scope>test</scope>
</dependency>
Otherwise, to write them using annotated methods, add the following dependency to your pom.xml:
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-java</artifactId>
<version>4.7.1</version>
<scope>test</scope>
</dependency>

JUnit on IntelliJ not working

I tried setting up JUnit 5 on my INtelliJ IDEA Community Edition 2018.2. The jar was downloaded but I am getting Cannot resolve symbol Assertions on importing
import static org.junit.jupiter.api.Assertions.*;
Error
Are you trying to use the JUnit assertions in a regular app class rather than a test class?
Delete <scope>test</scope>
When a Maven dependency carries a scope element with a value of test, that means you cannot use that library outside of your test-specific source package/folder.
If you are trying to call JUnit from code in your example project’s src/main/java/… folder hierarchy, you will see that error. If you call JUnit from src/test/java…, you will see success.
To enable JUnit in the src/main/java/… folder hierarchy, delete the scope element in your POM dependency. So this:
<!-- https://mvnrepository.com/artifact/org.junit.jupiter/junit-jupiter -->
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<version>5.4.0-RC1</version>
<scope>test</scope>
</dependency>
…becomes this:
<!-- https://mvnrepository.com/artifact/org.junit.jupiter/junit-jupiter -->
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<version>5.4.0-RC1</version>
</dependency>
By the way, note that as of 5.4.0 of JUnit, we can specify the new and very convenient single Maven artifact of junit-jupiter which in turn will supply 8 libraries to your project.

Specifying an ejb client as dependency in Maven

I have 2 EJBs A and B (in different jar files), EJB A calls one method of EJB B.
From the following Maven's documents, I use generateClient to create a ejb-client and use ejb-client dependency to get the jar.
http://maven.apache.org/plugins/maven-ejb-plugin/examples/generating-ejb-client.html
http://people.apache.org/~aramirez/maven-ejb-plugin/examples/ejb-client-dependency.html
It's ok to use Maven to build, deploy and run. The problem is, although project A only needs the interface class of EJB B, but Maven includes all EJB B's dependency libraries into EJB A's dependency. The result is EJB A will have lots of non-necessary jar files. Is there any solution to fix it?
I found another solution, Maven's dependency has exclude function and I use it to remove some jar files.
<dependencies>
<dependency>
<groupId>com.example</groupId>
<artifactId>ejb-project</artifactId>
<version>1.0-SNAPSHOT</version>
<type>ejb-client</type>
<exclusions>
<exclusion>
<groupId>sample.ProjectD</groupId>
<artifactId>Project-D</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
The only way is to move interface of EJB B to a separate jar. Then use it as dependency in EJBs A and B project/modules.