'Vaadin20: Scan Java code from Pom dependency

I want to put a Java class in a Maven artifact that uses the Vaadin @Endpoint annotation (from com.vaadin.flow.server.connect.Endpoint), to use this class in multiple Vaadin projects.

Here is a simple example of such a class:

import com.vaadin.flow.server.connect.Endpoint;
import lombok.RequiredArgsConstructor;
import java.util.Optional;

@Endpoint
@RequiredArgsConstructor
public class SupportInfoEndpoint {

  public Optional<String> getSupportInfo(){
    return Optional.of("mailto:[email protected]");
  }
}

The Maven artifact includes the source code of the class. What do I have to do so this class is scanned in the using project, by the Vaadin build process, so that

  • the corresponding TypeScript code for the frontend is generated
  • the class is included in the Spring-Boot application (so the endpoint is actually available at run time)

Is it possible at all?



Solution 1:[1]

Like Erik said, it will be implemented with #9010.

But there is a workaround depending on some restrictions. If you have every class that the endpoint needs in the same jar, you could trigger the typescript generation in same the jar by calling the goal "build-frontend" of vaadin-maven-plugin, then the typescript is generated and it's just a matter of some maven magic to move them to META-INF/resources/frontend (something similar of what is being done here). Then you just can package the endpoints in the jar.

For registering the endpoint in the project, you need to do something similar to what this class is doing, basically a ServiceInitListener that will execute the method registerEndpoint of the EndpointRegistry by using reflection.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Dharman