"static interface method invocations are not supported in -source 7" despite using 1.8 - vert.x

This is the complete error message:
"static interface method invocations are not supported in -source 7
(use -source 8 or higher to enable static interface method invocations)"
Here is the class:
public class UserVerticle extends AbstractVerticle {
#Override
public void start() {
Router router=Router.router(vertx);//IDE shows error message here
}
#Override
public void stop() {
}
}
Here are the project properties:
These are my dependencies:
<groupId>io.vertx</groupId>
<artifactId>vertx-core</artifactId>
<version>4.0.0</version>
And:
<groupId>io.vertx</groupId>
<artifactId>vertx-web</artifactId>
<version>3.4.1</version>
Edit:
I changed javaee-web-api version to 8 in pom.xml (It was 7), built with dependencies, and still getting the same error.
Edit2:
I changed vertx-web version to 4.0.0 in pom.xml, built with dependencies, and still getting the same error.

Turns out I should choose source 8 in maven-compiler-plugin, this totally solved the problem:
<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>
<compilerArguments>
<endorseddirs>${endorsed.dir}</endorseddirs>
</compilerArguments>
</configuration>

Related

Spring Tool Suite: #Configuration class may not be final. Remove the final modifier to continue

I am unable to launch my spring boot kotlin app, due to the following:
org.springframework.beans.factory.parsing.BeanDefinitionParsingException: Configuration problem: #Configuration class 'TestApplication' may not be final. Remove the final modifier to continue.
I know that #configuration and #bean classes cannot be final so I add the allopen plugin in my pom file:
<build>
<sourceDirectory>${project.basedir}/src/main/kotlin</sourceDirectory>
<testSourceDirectory>${project.basedir}/src/test/kotlin</testSourceDirectory>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-maven-plugin</artifactId>
<configuration>
<args>
<arg>-Xjsr305=strict</arg>
</args>
<compilerPlugins>
<plugin>spring</plugin>
</compilerPlugins>
</configuration>
<dependencies>
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-maven-allopen</artifactId>
<version>${kotlin.version}</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>
If I package my application and run it (java -jar) it works, but when I try to launch it from STS it won't work.
Kotlin version: 1.2.71
Kotlin eclipse plugin: 0.8.13
STS: 3.9.5
This Question Can be Duplicate of :
IntelliJ Idea 2017.3 unable to start Kotlin Spring Boot App - #Configuration class may not be final
or
Used kotlin-spring plugin, still getting class not open error
.
Anyways , I Just found Solution
You Just need to add open modifier to TestApplication kotlin class
#SpringBootApplication
open class TestApplication
might Solve your Issue .
I had the same problem. You must configure the Kotlin plugin under Preferences > Kotlin > Compiler and enable Compiler plugins spring.
Kotlin Compiler Configuration Dialog

How to turn my Jersey REST API into an executable JAR?

I am using Jersey, Maven; and could use Jetty, Tomcat or J2EE Preview (is that embeddable?).
What is the easiest way to port my REST API as a standalone/executable JAR?
Can I do it without Spring Boot?
Follow these steps to create a standalone application with Jersey and Tomcat:
Adding Maven dependencies
Add the following dependencies and properties to your pom.xml:
<properties>
<tomcat.version>8.5.23</tomcat.version>
<jersey.version>2.26</jersey.version>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-core</artifactId>
<version>${tomcat.version}</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.containers</groupId>
<artifactId>jersey-container-servlet</artifactId>
<version>${jersey.version}</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.inject</groupId>
<artifactId>jersey-hk2</artifactId>
<version>${jersey.version}</version>
</dependency>
</dependencies>
Creating JAX-RS resource classes
Define your JAX-RS resource class(es). The following is just an example:
#Path("hello")
public class HelloWorldResource {
#GET
#Produces(MediaType.TEXT_PLAIN)
public Response helloWorld() {
return Response.ok("Hello World").build();
}
}
Creating a Jersey configuration class
Create a class to configure your Jersey application:
public class JerseyConfiguration extends ResourceConfig {
public JerseyConfiguration() {
packages("com.example");
}
}
Creating a launcher class for Tomcat
Create a class to launch Tomcat and deployment your application:
public class Launcher {
private static final String JERSEY_SERVLET_NAME = "jersey-container-servlet";
public static void main(String[] args) throws Exception {
new Launcher().start();
}
void start() throws Exception {
String port = System.getenv("PORT");
if (port == null || port.isEmpty()) {
port = "8080";
}
String contextPath = "";
String appBase = ".";
Tomcat tomcat = new Tomcat();
tomcat.setPort(Integer.valueOf(port));
tomcat.getHost().setAppBase(appBase);
Context context = tomcat.addContext(contextPath, appBase);
Tomcat.addServlet(context, JERSEY_SERVLET_NAME,
new ServletContainer(new JerseyConfiguration()));
context.addServletMappingDecoded("/api/*", JERSEY_SERVLET_NAME);
tomcat.start();
tomcat.getServer().await();
}
}
Adding Maven plugin for creating an executable JAR
Finally add the Maven Shade plugin to create an executable JAR, where the mainClass attribute references the launch class:
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>2.4.3</version>
<configuration>
<finalName>tomcat-embedded-example-${project.version}</finalName>
</configuration>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<transformers>
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<mainClass>com.example.Launcher</mainClass>
</transformer>
</transformers>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
Compiling and running the application
To compile and run the application, follow these steps:
Open a command line window or terminal.
Navigate to the root directory of the project, where the pom.xml resides.
Compile the project: mvn clean compile.
Package the application: mvn package.
Look in the target directory. You should see a file with the following or a similar name: tomcat-embedded-example-1.0-SNAPSHOT.jar.
Change into the target directory.
Execute the JAR: java -jar tomcat-embedded-example-1.0-SNAPSHOT.jar.
The application should be available at http://localhost:8080/api/hello.
See more
How to deploy a JAX-RS application on a Java SE environment?
Follow these steps to create a standalone application with Jersey and Jetty:
Adding Maven dependencies
Add the following dependencies and properties to your pom.xml:
<properties>
<jetty.version>9.4.7.v20170914</jetty.version>
<jersey.version>2.26</jersey.version>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-server</artifactId>
<version>${jetty.version}</version>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-servlet</artifactId>
<version>${jetty.version}</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.containers</groupId>
<artifactId>jersey-container-jetty-servlet</artifactId>
<version>${jersey.version}</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.inject</groupId>
<artifactId>jersey-hk2</artifactId>
<version>${jersey.version}</version>
</dependency>
</dependencies>
Creating JAX-RS resource classes
Define your JAX-RS resource class(es). The following is just an example:
#Path("hello")
public class HelloWorldResource {
#GET
#Produces(MediaType.TEXT_PLAIN)
public Response helloWorld() {
return Response.ok("Hello World").build();
}
}
Creating a Jersey configuration class
Create a class to configure your Jersey application:
public class JerseyConfiguration extends ResourceConfig {
public JerseyConfiguration() {
packages("com.example");
}
}
Creating a launcher class for Jetty
Create a class to launch Jetty and deployment your application:
public class Launcher {
private static final String JERSEY_SERVLET_NAME = "jersey-container-servlet";
public static void main(String[] args) throws Exception {
new Launcher().start();
}
void start() throws Exception {
String port = System.getenv("PORT");
if (port == null || port.isEmpty()) {
port = "8080";
}
Server server = new Server(Integer.valueOf(port));
ServletContextHandler context = new ServletContextHandler(server, "/");
ServletHolder servlet = new ServletHolder(JERSEY_SERVLET_NAME,
new ServletContainer(new JerseyConfiguration()));
context.addServlet(servlet, "/api/*");
try {
server.start();
server.join();
} finally {
server.destroy();
}
}
}
Adding Maven plugin for creating an executable JAR
Finally add the Maven Shade plugin to create an executable JAR, where the mainClass attribute references the launch class:
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>2.4.3</version>
<configuration>
<finalName>jetty-embedded-example-${project.version}</finalName>
</configuration>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<transformers>
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<mainClass>com.example.Launcher</mainClass>
</transformer>
</transformers>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
Compiling and running the application
To compile and run the application, follow these steps:
Open a command line window or terminal.
Navigate to the root directory of the project, where the pom.xml resides.
Compile the project: mvn clean compile.
Package the application: mvn package.
Look in the target directory. You should see a file with the following or a similar name: jetty-embedded-example-1.0-SNAPSHOT.jar.
Change into the target directory.
Execute the JAR: java -jar jetty-embedded-example-1.0-SNAPSHOT.jar.
The application should be available at http://localhost:8080/api/hello.
See more
How to deploy a JAX-RS application on a Java SE environment?

How to integrate dagger2 in GWT application?

I am trying to add dagger2 in my gwt application to have DI. So far I have followed following steps
1) Added following dependencies in pom.xml
<dependency>
<groupId>com.google.dagger</groupId>
<artifactId>dagger-gwt</artifactId>
<version>2.4</version>
</dependency>
<dependency>
<groupId>com.google.dagger</groupId>
<artifactId>dagger-compiler</artifactId>
<version>2.4</version>
</dependency>
<dependency>
<groupId>com.google.auto.factory</groupId>
<artifactId>auto-factory</artifactId>
<version>1.0-beta3</version>
</dependency>
2) Inherits dagger dependency in gwt module MyApp.gwt.xml by adding following line of code.
<inherits name="dagger.Dagger" />
3) Created Component Class.
import javax.inject.Singleton;
import com.google.gwt.event.shared.EventBus;
import dagger.Component;
#Singleton
#Component(modules = AppModule.class)
public interface AppComponent {
EventBus eventBus();
}
4) Created Module class
import javax.inject.Singleton;
import com.google.gwt.event.shared.EventBus;
import com.google.gwt.event.shared.SimpleEventBus;
import dagger.Module;
import dagger.Provides;
#Module
public class AppModule {
#Provides
#Singleton
SimpleEventBus provideSimpleEventBus() {
return new SimpleEventBus();
}
#Provides
EventBus provideEventBus(SimpleEventBus bus) {
return bus;
}
}
Finally, when I am trying to build module in AppEntryPoint
AppComponent component = DaggerAppComponent.builder()....build();
I can't find generated class DaggerAppComponent anywhere after mvn compile or mvn gwt:compile. I am using gwt-maven-plugin from org.codehaus.mojo. Its clear I am missing something in configuration but can't figure out what exactly.
First, you need to make sure the annotation processor is triggered by the maven-compiler-plugin. I highly suggest using version 3.5.1 (at least) of the maven-compiler-plugin which fixes a number of issues that made it really impractical to use annotation processors with Maven.
With the default configuration, sources will be generated in target/generated-sources and added as project sources so they'll be correctly picked up by the gwt-maven-plugin later on.
You should change your dagger-compiler dependency to be <optional>true</optional> or <scope>provided</scope>; or even better, declare it in the annotationProcessorPath of the maven-compiler-plugin.
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.5.1</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
<annotationProcessorPaths>
<path>
<groupId>com.google.dagger</groupId>
<artifactId>dagger-compiler</artifactId>
<version>${dagger.gwt.version}</version>
</path>
</annotationProcessorPaths>
</configuration>
</plugin>
For dev mode, you'll need to re-run the annotation processor every time you make a change to the processed classes; this will generally be done by your IDE, but can be triggered from the command-line using mvn compile or mvn process-classes.
You can see a full setup in my gwt-maven-archetypes

jboss fuse 6.2 rest cxf org.apache.cxf.service.factory.ServiceConstructionException: "No resource classes found"

Just started using Fuse 6.2 from 6.1. This deployed on 6.1 and I can't seem to get it to deploy in the new Fuse 6.2.
This simple Rest service keeps getting the following error when I deploy to the Fuse environment.
Any ideas would be greatly appreciated.
THis issue suggests removing the javax.ws.rs/javax.ws.rs-api/2.0.1 bundle file from Fuse. The bundle start cleanly without error however the REST service is not accessible for some reason.
This link might be applicable:
https://issues.apache.org/jira/browse/CXF-5654
I need to investigate the feature Swagger as it starts automatically.
Error :
Caused by: org.apache.cxf.service.factory.ServiceConstructionException: No resource classes found
at org.apache.cxf.jaxrs.AbstractJAXRSFactoryBean.checkResources(AbstractJAXRSFactoryBean.java:317)
at org.apache.cxf.jaxrs.JAXRSServerFactoryBean.create(JAXRSServerFactoryBean.java:159)
... 29 more
Code :
#Path("/configservice")
public class ConfigurationServiceImpl
{
public ConfigurationServiceImpl()
{
}
#GET
#Path("/event0")
#Consumes({MediaType.APPLICATION_XML})
#Produces({MediaType.APPLICATION_XML})
public RestConcreteResult process()
{
logger.info("************************************** process has been processed");
RestConcreteResult result = new RestConcreteResult("test ::: ");
return result;
}
}
Pom.xml
...
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-frontend-jaxrs</artifactId>
</dependency>
</dependencies>
I got the same error. It was caused by a dependency on an old version of javax.ws.rs:
javax.ws.rs;version="[1.1,2)",
javax.ws.rs.core;version="[1.1,2)",
https://issues.apache.org/jira/browse/CXF-5654 states CXF 3.x needs java rs api 2.0. So I added that explicitly:
javax.ws.rs;version="[2.0,3)",
javax.ws.rs.core;version="[2.0,3)",
In the Maven pom.xml:
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<executions>
<execution>
<id>Create OSGi bundle</id>
<goals>
<goal>bundle</goal>
</goals>
<configuration>
<instructions>
<Import-Package>
META-INF.cxf,
org.apache.cxf.bus.spring,
javax.ws.rs;version="[2.0,3)",
javax.ws.rs.core;version="[2.0,3)",
*
</Import-Package>
</instructions>
</configuration>
</execution>
</executions>
</plugin>

Why does eclipse not resolve the maven plugin dependencies after it being added to the dependencies section?

I just installed the maven eclipse plugin and all is great. I have tried creating my first mojo. After the setup, it has downloaded all the required dependencies.
Now what is troubling me is that Eclipse isn't able to resolve the org.apache.maven.plugins classes.
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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.blah.dalm.mojo</groupId>
<artifactId>assembly-mojo</artifactId>
<packaging>maven-plugin</packaging>
<name>Assembly Mojo</name>
<version>0.0.1-SNAPSHOT</version>
<build>
<sourceDirectory>${basedir}</sourceDirectory>
<!-- Plugin Configurations -->
<plugins>
<!-- Compiler plugin to use 1.6 -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.0.2</version>
<executions>
<execution>
</execution>
</executions>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
</plugins>
</build>
<!-- Dependencies -->
<dependencies>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-plugin-api</artifactId>
<version>2.0</version>
</dependency>
</dependencies>
</project>
My mojo file AssemblyMojo.java:
package com.blah.dalm.mojo;
import java.util.List;
import org.apache.maven.plugin.MojoExecutionException; // <-- This is where it says it cannot resolve the class or package.
/**
* "Assemble Goal"
* #goal assemble-goal
* #author Husain Khambaty
*
*/
public class AssemblyMojo {
/**
* #parameter expression="${assembly.sourcePath}"
* #required
*/
private String sourcePath;
/**
* #parameter expression="${assembly.outputPath}"
* #required
*/
private String outputFilePath;
/**
* #parameter
*/
private List<String> excludeList;
/**
* #parameter
*/
private String filterRule;
public void execute() throws MojoExecutionException { // <-- And here
}
}
It is unable to resolve the MojoExectionException class (therefore I believe it isn't able to find the rerquired jars, which I guess it is supposed to automatically fetch after the Eclipse-Maven integration).
When I build it, it builds just fine.
Solution :
Thanks to #yorkw - his answer led me to the solution.
After installing the Maven-Eclipse plugin, and adding the dependencies in the pom.xml, it is automatically supposed to find those jars from the maven repository and add them in a "Maven Dependencies" section. This didn't happen when I did it (probably did something wrong).
After #yorkw answer, I added the jar and it worked. Just then I figured that I had already enabled the Dependencies. So just for the heck of it, I disabled them and enabled them again and suddenly out of no where the "Maven Dependenices" appeared. Phew.
(Note : I did try putting up screenshots - but I'm a newbie on StackOverflow and it wont allow me to post images yet.. I shall in time edit this post back and put the screen shots for others).