Eclipse error "JAX-RS (REST Web Services) 2.1 can not be installed" / "...requires Java 1.8 or newer" - eclipse

When I try to build one of the modules within our application I keep getting two errors related to JAX-RS showing up in the "Problems"-view:
JAX-RS (REST Web Services) 2.1 can not be installed : One or more constraints have not been satisfied.
JAX-RS (REST Web Services) 2.1 requires Java 1.8 or newer.
The module that causes this error is the web-interface of a GWT (Google Web Toolkit) project that still uses GWT 2.7 which indeed requires Java 1.7 code. While we do compile using Java 1.8 we have set the compiler version (just for that GWT module) like so:
...
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
...
What I don't get here is:
Why does JAX-RS interfere or come into play here at all?
That project (or maven "module") has neither a "Dynamic Web Module" facet nor a "JAX-RS (REST Web Service)"-facet. It also has no GWT-related facet, since the GWT plugin doesn't work anymore with the latest eclipse version.
Any idea anyone, where this JAX-RS error comes from? Or how to find out, what is causing this?
This is using the very latest Eclipse version as of today (Eclipse for WebDevelopers / v2022-12) freshly downloaded and installed and the projects imported into it.

Related

Eclipse Project can't find Java 13 classes after conversion to Maven

I have an old project in Eclipse that runs fine with Java 13. I'm using Eclipse 2019-09 (4.13.0), I have the Java 13 JRE on the build path and as the default JRE, the compliance level set to 13, and the Eclipse Java 13 patch installed. No problems.
When I convert this to a Maven project, some of the JRE classes are no longer found. BitArray (found in java.xml com.sun.org.apache.xalan.internal.xsltc.dom), DocumentImpl (found in java.xml com.sun.org.apache.xerces.internal.dom), BevelBorder (found in java.desktop com.sun.java.swing.plaf.motif.MotifBorders) and others.
If I hover over one of the fields - say BitArray - Eclipse will prompt me to Import 'BitArray' (com.sun.org.apache.xalan.internal.xsltc.dom), but when I do I simply get an error saying The import com.sun.org.apache.xalan cannot be resolved
I have the following lines in pom.xml:
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
<configuration>
<release>13</release>
</configuration>
</plugin>
I've done many Clean&Builds and Maven updates. I've tried changing the order in the build path (read that was a bug in earlier releases). I've even used the Hello World Maven project example with the same result - as soon as I add BitArray, it fails.
Any suggestions would be greatly appreciated. I've been googling this for half a day now, and still haven't found the solution.

Eclipse - How to add Kotlin to a Tomcat Project - Compile Kotlin AND Java Files

I need help adding Kotlin compiling to an existing eclipse java tomcat project.
For the record I am on Eclipse Oxygen 4.7, and have installed the Kotlin plugin. I have successfully created and ran gradle based spring boot Kotlin rest api demo and can compile and run "Kotlin Only Projects" and use my other java libs - AWESOME.
However now that I have Kotlin I want to use it in work for my other 'legacy' Tomcat 8 projects that are Java J2EE - Dynamic WTP ... new servlets I want to write in Kotlin.
I want to be able to add a Kotlin class in the java src folder in any of my previous packages so when I build a war it all logically together.
The IDE seems ok with this - I created a Kotlin class in a package (in a tomcat project java src package folder) and it have no issues on resolving, imports, or dependency...
I was thinking WOW!, Ok now to restart the Tomcat server in WTP and I'll be able to execute my Kotlin Servlet. No - 404 404 404.
I inspected the WEB-INF/classes build folder and along all the Java class files... guess what I saw?! A file called KotlinServlet.kt ( thats the name of my test servlet, the source version not a compile class version)
So for some reason the build /package/ deployment did not bother to compile the *.kt file and just copied it over (maybe that is the default for general WTP deploy).
I wonder if this would be solved by "Add Kotlin Nature" , the strange part is that none of the eclipse Kotlin menu functions are available to me. If I right click my project I get no Kotlin menu options.
Eclipse states the plugin is installed.
So my question is:
Given an existing conventional WTP Tomcat servlet project, HOW can we get it to identify and a compile *.kt files? How and why do I not have the Kotlin menu functions? (I downloaded and tested both the Oxygen Java and J2EE version - installed the Kotlin plugin - and no menus there either to add a Kotlin Nature. I also then tried the nightly build of the plugin. No menus appeared. Obviously the puglin is installed compiling other Kotlin projects and works in the editor.
From my research - "Add Kotlin Nature" is supposed to do the trick for joint Java / Kotlin compiling but that menu function is not available anywhere???
If this is a "Kotlin Project" eclipse compiles Kotlin fine.
Any Ideas? Seems like an IntelliJ conspiracy.
Thanks,
You need add correspond dependencies. The easiest way to manage project dependencies is to use build tools (maven, gradle, Ant+Ivy...). In maven example you need:
<properties>
<!-- your properties... and define version fir kotlin -->
<kotlin.version>1.1.4</kotlin.version>
</properties>
<dependencies>
<!-- your project dependencies... and add one for kotlin -->
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-stdlib-jre8</artifactId>
<version>${kotlin.version}</version>
</dependency>
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-test</artifactId>
<version>${kotlin.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<!-- your project plugins... and add one for kotlin -->
<plugin>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-maven-plugin</artifactId>
<version>${kotlin.version}</version>
<executions>
<execution>
<id>compile</id>
<phase>compile</phase>
<goals>
<goal>compile</goal>
</goals>
</execution>
<execution>
<id>test-compile</id>
<phase>test-compile</phase>
<goals>
<goal>test-compile</goal>
</goals>
</execution>
</executions>
<configuration>
<jvmTarget>1.8</jvmTarget>
</configuration>
</plugin>
</plugins>
</build>
If you use IDE you need to install kotlin language support plugin to make kotlin compile or test run more user friendly.
OK I am narrowing in on this. I found that the kotlin classes are being compiled to this location under runtime lib? Maybe this will be something I can figure to build to my normal classes folder.
OK - To get all the Kotlin menus - turns out you need to be on PACKAGE EXPLORER tab not PROJECT EXPLORER . arggh just found that by fluke.
The creation of a .kt file will automatically add the runtime and libs for Kotlin to your project.
Now on the the issue of the build / compile now. Still outstanding.
OK Update - Downloaded IntelliJ, and "IT" works out of the box, in 15 min I had a Hybrid Java/Kotlin Tomcat Project running.
Still Interested in the Eclipse solution but I am probably just going to shell out the cash for IntelliJ. Time is money.

Eclipse - maven - what goal should I execute to actually deploy to Wildfly from maven (achieve the same result as the "run on server" eclipse command)

New to maven - I have an eclipse project that I can Right click > Run as... > Run on server and it runs successfully on my local Wildfly installation. Is there a way to RClick> Run as... and choose an appropriate maven goal to achieve the same effect (ie package as a war, copy to the servers dir (re)staring the server) ? Do I need to use a "wildfly maven plugin" ?
Similar question for tomcat: maven deploy goal failing
I am on eclipse Luna Java EE pack, maven 3.1 (the one that comes with eclipse) and using Wildfly 8.1.0.Final
Related:
One click build and deploy using Eclipse/Maven/JBoss AS 7
EDIT: I am now on Wildfly - so I edited accordingly
The closest I got was:
<plugin>
<groupId>org.wildfly.plugins</groupId>
<artifactId>wildfly-maven-plugin</artifactId>
<version>1.0.2.Final</version>
<configuration>
<jbossHome>C:/_/wildfly-8.1.0.Final</jbossHome>
</configuration>
</plugin>
but I would like to avoid hardcoding the path there - how should I proceed ?
You can use jboss plugin
<plugin>
<groupId>org.jboss.as.plugins</groupId>
<artifactId>jboss-as-maven-plugin</artifactId>
<version>7.5.Final</version>
</plugin>
Then set goal as: “jboss-as:deploy clean”
It will deploy war on JBoss server.

Eclipse 4.3.2 with Java 8 patches doesn't recognize source level 1.8

I'm using Eclipse 4.3.2 with the patches for Java 8 from, along with m2e and Subclipse, completely updated to the latest versions of everything.
I went into the Maven POMs for our project and changed the maven-compiler-plugin to:
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.5.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
I updated all my Maven projects tried to do a complete clean and build. Errors all over the place. Ignoring the internal compiler error for the moment, the error I see most is:
Syntax error, static imports are only available if source level is 1.5 or greater
I'm running Java 1.8---why am I getting this message? Is m2e to blame? The maven-compiler-plugin? Or is Eclipse Java 1.8 support simply not ready for prime time?
If you don't want to use an early 1.5 milestone, please note that m2e 1.4.1 ALSO supports Java 8, and you can install it from this update site:
http://download.eclipse.org/technology/m2e/releases/1.4/1.4.1.20140328-1905
It's also on the Eclipse Marketplace:
https://marketplace.eclipse.org/content/java%E2%84%A2-8-support-m2e-eclipse-kepler
And if you happen to be a fan of JBoss Tools, it's coming directly to JBoss Central:
https://issues.jboss.org/browse/JBIDE-17002
Apparently m2e doesn't yet support Java 8.
According to Eclipse Bug 420848, you have to install m2e 1.5 M6 from the http://download.eclipse.org/technology/m2e/milestones/1.5 software site. I did this and the source level 1.5 errors went away.

Eclipse WTP not publishing Maven dependencies

I'm trying to set up a basic hello world project using Eclipse Indigo and a Tomcat server. I created a dynamic project with a simple servlet. Tested the servlet and that worked fine. Then I enabled Maven support and added logback to my pom. I put a logging statement in the servlet's doGet method. When running the servlet, it complains it cannot find any bindings because the logback jars are not being copied into the Eclipse tomcat instance. I expected to find the jars published somewhere in here:
${workspace}\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\
How do I get Eclipse to work with WTP/Maven properly? I also tried installing the m2e-wtp connector with no difference.
Check Deployment Assembly (context menu on project), there must be mapping Maven Dependencies -> WEB-INF/lib.
Coming from an ASP.NET background, I find it shocking how much work it takes to get a webapp running with Eclipse WTP and Maven especially if you are learning on your own. Hopefully this quick start guide will help someone else get up to speed quickly.
There are two ways to get a hello world project working in Eclipse WTP with Maven. You can create a Dynamic web project and then add the Maven nature or you can do the opposite.
Pre-requisites for Eclipse with update sites
"Web, XML, Java EE and OSGi Enterprise Development"
http://download.eclipse.org/releases/indigo
"Maven Integration For Eclipse"
http://download.jboss.org/jbosstools/updates/m2eclipse-wtp/
"Maven Integration for WTP"
http://download.jboss.org/jbosstools/updates/m2eclipse-wtp/
Startup configuration
Install copy of Tomcat 7 from http://tomcat.apache.org/download-70.cgi
Window -> Preferences -> Server -> Runtime Environment
Add Apache Tomcat 7.0 and select local installation directory
Option 1: Create Dynamic Web Project then add Maven Nature
Create new Maven project, select archetype
org.apache.maven.archetypes:maven-archetype-webapp
Change to Java EE perspective.
Create a new source folder, src\main\java. Notice how Eclipse is not smart enough to do this for you and also the ordering of the folders is incorrect.
src\main\java folder is listed after src\main\resources. This can be manually fixed later in the project properties.
Create a new servlet. Notice how Eclipse defaults this file in the wrong folder src\main\resources because the order is wrong. Instead, manually select src\main\java.
Change the URL mapping on the second page of the wizard to /* to make testing easier.
Now our servlet is ready but the dependencies on the servlet api are unbound. A) we can add the servlet api as a dependency to our project or B) we can bind to the Eclipse server config for Apache 7.0.
For option A, add this dependency to the pom:
.
<dependency>
<groupId>org.apache.tomcat</groupId>
<artifactId>tomcat-api</artifactId>
<version>7.0.${set this}</version>
<scope>provided</scope>
</dependency>
For option B:
Project properties -> Java Build Path -> Libraries -> Add Library -> Server Runtime -> Apache Tomcat 7.0
Right click and run on server:
A blank page should come up in the internal browser like http://localhost:8080/${artifact}
Test of dependency publishing:
Add joda-time to the pom.
Add this line in the servlet created earlier for the doGet method and import the necessary dependencies:
.
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
response.getWriter().println("The time is now: " + new DateTime().toString());
}
Reload the test page and the output should now be:
The time is now: 2012-03-03T14:14:29.890-05:00
Now if you want to play with Servlet 3.0 and annotations this is not enabled by default, for what reason I don't know.
First force Maven to use Java 1.6 by adding this to your pom, otherwise each time you update your pom the configuration will revert to Java 1.5.
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
Open Project Properties -> Project Facets. Change the Version under "Dynamic Web Module" to 3.0, change java version 1.6
Create a new Servlet with class name AnnotatedServlet in src\main\java and notice how the #WebServlet annotation is auto created.
Option 2: Create Dynamic Web Project then add Maven Nature
Select Tomcat Runtime and Dynamic Module Version 3.0
Create source folder src\main\java
Set default output target\classes
Set context directory src\main\webapp
Check generate web.xml
Create servlet with mapping /* for quick testing
Add an output statement to the doGet method
response.getWriter().println("Another test");
Double click the "Deployment descriptor" and add this attribute to the root web-app element metadata-complete="false"
Right click project and select Run As -> Run On Server
Right click project -> Configure -> Convert To Maven Project
Select packaging as war
Edit pom and set compiler to use java 1.6 and add joda-time dependency:
.
<dependencies>
<dependency>
<groupId>joda-time</groupId>
<artifactId>joda-time</artifactId>
<version>2.1</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
</plugins>
</build>
Right click on the web project in Project Explorer then choose Maven -> Update Project
I faced a similar problem and although I had configured Deployment Assembly correctly it still didn't work. Then I found that under Window -> Preferences -> My Eclipse -> Java Enterprise Project -> Web Project, under the Deployment tab, the management of Dependent projects was turned off. I changed it to deploy jars of dependent projects to the lib folder and then everything worked like a charm. I could even turn off the Deployment Assembly option.