Browser HEAVYWEIGHT not visible on the scene - spring-boot

I'm trying to embedd the JXBrowser into a SpringBoot JavaFX Application running with Java11. My Problem is that the browser is not shown on the scene when I run the application from the created executable jar. The browser is loaded, gives feedback about the loaded website and is already part of the scene, but not visible.
Running inside IntelliJ or with Maven exec is currently working. When I switch the browser mod to LIGHTWEIGHT than all of the three run possibilities are working fine. What is the the Problem with running from jar in HEAVYWEIGHT mod?
My system: Windows10-64, Java11, SpringBoot 2.1.0.RELEASE, JXBrowser 6.21, OpenJFX 11
Main.class
#Slf4j
#SpringBootApplication
public class Main extends Application
{
private ConfigurableApplicationContext springContext;
public static void main(final String[] args)
{
Application.launch(args);
}
#Override
public void init()
{
springContext = SpringApplication.run(Main.class);
springContext.getAutowireCapableBeanFactory().autowireBean(this);
}
#Override
public void start(Stage stage)
{
final Browser browser = new Browser();
stage.setScene(new Scene(new BrowserView(browser)));
stage.show();
browser.loadURL("http://www.google.de");
}
#Override
public void stop()
{
springContext.close();
}
}
StartMain.class
public class StartMain
{
public static void main(String[] args)
{
Main.main(args);
}
}
pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://maven.apache.org/POM/4.0.0"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/xsd/maven-4.0.0.xsd">
<groupId>de</groupId>
<artifactId>app</artifactId>
<version>1.0.10-SNAPSHOT</version>
<modelVersion>4.0.0</modelVersion>
<packaging>jar</packaging>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.0.RELEASE</version>
<relativePath/>
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<java.version>11</java.version>
<maven.compiler.source>${java.version}</maven.compiler.source>
<maven.compiler.target>${java.version}</maven.compiler.target>
<jxbrowser.version>6.21</jxbrowser.version>
<javafx.version>11</javafx.version>
</properties>
<repositories>
<repository>
<id>com.teamdev</id>
<url>http://maven.teamdev.com/repository/products</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.teamdev.jxbrowser</groupId>
<artifactId>jxbrowser-cross-platform</artifactId>
<type>pom</type>
<version>${jxbrowser.version}</version>
</dependency>
<dependency>
<groupId>com.teamdev.jxbrowser</groupId>
<artifactId>jxbrowser-win64</artifactId>
<version>${jxbrowser.version}</version>
</dependency>
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-base</artifactId>
<version>${javafx.version}</version>
</dependency>
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-controls</artifactId>
<version>${javafx.version}</version>
</dependency>
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-fxml</artifactId>
<version>${javafx.version}</version>
</dependency>
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-graphics</artifactId>
<version>${javafx.version}</version>
</dependency>
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-swing</artifactId>
<version>${javafx.version}</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<includeSystemScope>true</includeSystemScope>
<mainClass>...StartMain</mainClass>
<layout>ZIP</layout>
</configuration>
<executions>
<execution>
<goals>
<goal>build-info</goal>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>

I've managed to build the project, and getting a trial license I can run it. As you mentioned, running from the IDE, or from command line mvn compile exec:exec (I've also tried with Gradle, ./gradlew run, adding the required --add-exports), works perfectly fine, the browser is displayed and the given URL loaded.
However, as you said, if you create a fat jar and run it, it doesn't display the browser, but JavaFX works, and you can see some activity going on, only no rendering.
I've tried under JDK 8, 9, 10 and 11. Only under 8 I could get the fat jar to display the browser.
Using a fat jar is a bad practice in general, and now even worse as you have to include the JavaFX classes from the JavaFX SDK.
A better way to distribute your application is by using jlink.
Given that com.teamdev.jxbrowser:jxbrowser is not modular, you can't fully use jlink with your project, but you can create a custom runtime image only with the JavaFX modules, and use that to run your app with the only dependency of jxBrowser (for convenience I'm not using SpringBoot).
So if you download the JavaFX jmods from here, unzip them and run:
export PATH_TO_FX_MODS=/path-to/javafx-jmods-11
$JAVA_HOME/bin/jlink --module-path $PATH_TO_FX_MODS \
--add-modules=java.se,javafx.web,javafx.fxml,javafx.swing \
--output jre
you will create a JRE that contains JavaFX.
Then you can run your project, including your dependencies in the classpath:
jre/bin/java -cp \
/Users/<user>/.gradle/caches/modules-2/files-2.1/com.teamdev.jxbrowser/jxbrowser/6.22/c9...6b/jxbrowser-6.22.jar:\
/Users/<user>/.gradle/caches/modules-2/files-2.1/com.teamdev.jxbrowser/jxbrowser-mac/6.22/fa...d4/jxbrowser-mac-6.22.jar:\
build/libs/browserApp.jar jxbrowser.BrowserApp
This works fine as well, the browser is displayed. So we discard that there could be any issue with JavaFX 11.
Now we can still do a small fat jar with the project and jxBrowser dependencies. And then if you run:
jre/bin/java -cp build/libs/browserApp.jar jxbrowser.BrowserApp
as you can imagine, this won't work, the browser won't show up.
So my final conclusion is that adding a fat jar even only with the two jxBrowser dependencies doesn't work.
See for instance this post about possible causes for this:
There can be files with the same path present in multiple JARs and by default the shade plugin includes the first file in the fat JAR and discards the rest.
So I'd suggest you file an issue to the project issue tracker, if exists, and I'd also suggest you find a way to run your app without fat-jars.

Related

Spring boot index page not mapped to / in Tomcat deployment

Yet another issue with deploying Spring Boot WAR to Tomcat... I have read the dozen of similar questions but have not found any fix for my issue.
I have a Spring Boot web app which is working fine when using the embedded tomcat web server (I can reach the index.html page using localhost:8080).
However when I deploy the WAR to Tomcat (the war is called ROOT.war so am I deploying the app at Tomcat's root), localhost:8080 returns 404. I need to call localhost:8080/index.html to get an answer. I just cannot figure out why!
pom.xml
<modelVersion>4.0.0</modelVersion>
<groupId>...</groupId>
<artifactId>...</artifactId>
<version>...</version>
<packaging>war</packaging>
<properties>
<java.version>11</java.version>
</properties>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.7.5</version>
</parent>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>
...
</dependencies>
<build>
<finalName>ROOT</finalName>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</pluginManagement>
<plugins>
<plugin>
<groupId>com.github.eirslett</groupId>
<artifactId>frontend-maven-plugin</artifactId>
<version>1.12.1</version>
<executions>
...
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>${java.version}</source>
<target>${java.version}</target>
</configuration>
</plugin>
</plugins>
</build>
</project>
Application.java
#SpringBootApplication
public class Application extends SpringBootServletInitializer {
#Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
return application.sources(Application.class);
}
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}
I have one #RestController which does not override "/", and that's it.
In the generated WAR, the index.html is located at the top level (so same level as WEB-INF).
I also noticed that when Tomcat starts the web app, it prints:
INFO ServletWebServerApplicationContext ServletWebServerApplicationContext.prepareWebApplicationContext(ServletWebServerApplicationContext.java:292) [main] Root WebApplicationContext: initialization completed in 1674 ms
INFO WelcomePageHandlerMapping WelcomePageHandlerMapping.<init>(WelcomePageHandlerMapping.java:53) [main] Adding welcome page: ServletContext resource [/index.html]
I find the second line strange: it looks like Spring Boot is choosing to default back to a WelcomePageHandlerMapping instead of using the expected spring boot context. No idea where that comes from.
Maybe another indication: it does not print
Initializing Spring embedded WebApplicationContext
while this is printed when I start the app using the embedded Tomcat web server. But maybe it is fine if it is not there.
Tomcat version: 9.0.65
Tomcat config: default config: did not change anything there since installation.
Help!
I could reproduce!
With:
Dockerfile:
FROM tomcat:9.0.69-jre17-temurin-jammy
ARG WAR_FILE=target/ROOT.war
RUN addgroup --system tomcat \
&& adduser --system --ingroup tomcat tomcat \
&& chown -Rfh tomcat:tomcat $CATALINA_HOME
USER tomcat:tomcat
COPY ${WAR_FILE} $CATALINA_HOME/webapps/
CMD ["catalina.sh", "run"]
pom.xml:
<?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>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<!-- max spring boot version for tomcat 9 (servlet-api): -->
<version>2.7.6</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.example</groupId>
<artifactId>traditional</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>
<description>Demo project for Spring Boot</description>
<properties>
<java.version>17</java.version>
<!-- latest tomcat9 version, property controls spring dependency management: -->
<tomcat.version>9.0.69</tomcat.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<finalName>ROOT</finalName>
<!-- no spring-boot plugin!(?) -->
</build>
</project>
App/Entry:
package com.example.traditional;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
#SpringBootApplication
public class TraditionalApplication extends SpringBootServletInitializer {
public static void main(String[] args) {
SpringApplication.run(TraditionalApplication.class, args);
}
#Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) {
return builder.sources(TraditionalApplication.class);
}
}
(Some /custom controller, (mockMvc) tests)
and a "static index.html" in src/main/webapp (maven war default):
<html>
<body>
<h1>Hello</h1>
Hello World!
</body>
</html>
the (embedded tomcat) test succeeds:
#WebMvcTest
public class WebTest {
#Autowired
MockMvc mockMvc;
#Test
void testRoot() throws Exception {
mockMvc
.perform(
get("/")
).andExpectAll(
status().isOk(),
forwardedUrl("index.html")
);
} // ...
}
but after:
mvn clean install \
&& docker build -t my/tomcat9-app . \
&& docker run -p 8080:8080 my/tomcat9-app,
we get:
404 (tomcat error page) from http://localhost:8080
(http://localhost:8080/index.html, http://localhost:8080/custom work as expected ;(#
Simplest Solution
Move index.html from src/main/webapp to src/main/resources/static ! (stop running container, repeat mvn clean install && docker build ... && docker run);p #

Executing unit tests (and applications) under Java-9 with Maven 3.5

I've found a lot of information about how to coax Maven to compile Java-9 source code, but I haven't run into compiler issues. Instead, I have trouble running under Java-9. Running mvn clean install will compile my code fine, but the build still fails with an exception when it runs unit tests. I can't figure out how to run either the unit tests or the application, under Java 9. I suspect that the --add-modules java.xml.bind is getting added to the compiler options but not the runtime options.
I have a simple Spring-Boot 2.0.1 project with one small java source file, one empty java test source, and a pom.xml file. Here's the exception:
java.lang.IllegalStateException: Failed to load ApplicationContext
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaConfiguration.class]: Invocation of init method failed; nested exception is java.lang.NoClassDefFoundError: javax/xml/bind/JAXBException
Caused by: java.lang.NoClassDefFoundError: javax/xml/bind/JAXBException
Caused by: java.lang.ClassNotFoundException: javax.xml.bind.JAXBException
I already know that I can add a jaxb-api dependency to fix this, but that doesn't solve the more general problem of using Maven with Java 9 modules.
Version Info
When I type mvn -v, this is what I get:
Apache Maven 3.5.2 (138edd61fd100ec658bfa2d307c43b76940a5d7d; 2017-10-18T00:58:13-07:00)
Maven home: /custom/apache-maven-3.5.2
Java version: 9.0.1, vendor: Oracle Corporation
Java home: /Library/Java/JavaVirtualMachines/jdk-9.0.1.jdk/Contents/Home
Default locale: en_US, platform encoding: UTF-8
OS name: "mac os x", version: "10.11.6", arch: "x86_64", family: "mac"
(I've read that I need at least maven version 3.5, so this is supposed to work.)
What doesn't work
Here's what I've already tried, that doesn't work:
Neither of these works:
export MAVEN_OPTS="--add-modules java.xml.bind"
export MAVEN_OPTS="--add-modules=java.xml.bind"
Adding a .mvn/jvm.config file with --add-modules java.xml.bind didn't work.
I didn't expect it to help to add the maven compiler plug-in to the pom.xml file, because compiling the code isn't an issue. I tried it anyway, but it didn't help. This is what I added to the project/build/plugins portion of the pom.xml file:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<compilerArgs>
<arg>--add-modules=java.xml.bind</arg>
</compilerArgs>
<source>1.9</source>
<target>1.9</target>
<fork>true</fork>
</configuration>
<version>3.7.0</version>
</plugin>
Building under Java 10 didn't help at all.
Source Code
I have an empty application.properties file.
My source file looks like this:
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
#SpringBootApplication
public class AngularSpringBootApplication {
public static void main(String[] args) {
SpringApplication.run(AngularSpringBootApplication.class, args);
}
}
My test file looks like this, in the same package on the test tree:
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
#RunWith(SpringRunner.class)
#SpringBootTest
public class AngularSpringBootApplicationTests {
#Test
public void contextLoads() {
}
}
Here's my pom.xml file, which comes from the Spring Boot generator at http://start.spring.io/ (Some of this isn't necessary. This is a stripped-down version of a slightly larger project.)
<?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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.neptunedreams.tutorial</groupId>
<artifactId>SpringBootBuildBug</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>
<name>SpringBootBuildBug</name>
<description>Demo project for Spring Boot</description>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.1.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>9</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-rest</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<!--This is the solution to the Jax bug at execution time, but I don't like it. -->
<!--<dependency>-->
<!--<groupId>javax.xml.bind</groupId>-->
<!--<artifactId>jaxb-api</artifactId>-->
<!--<version>2.3.0</version>-->
<!--</dependency>-->
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<compilerArgs>
<arg>--add-modules=java.xml.bind</arg>
</compilerArgs>
<source>1.9</source>
<target>1.9</target>
<fork>true</fork>
</configuration>
<version>3.7.0</version>
</plugin>
</plugins>
</build>
</project>
It turns out there was a simple fix. I didn't have the latest version of Maven. When I upgraded from 3.5.2 to 3.5.3, the problem went away.

Spring Boot - Spring Rest - Build Package

I am learning Spring Boot. I have just created my first project using maven, Spring Boot, Spring Rest support and MongoDB. It compiles successfully, but it resolves all the dependencies, but do not compile the java classes at all.
After compilation, jar file is correctly created, it contain lib folder, metadata etc, but it do not contain project class file at all.
Hence when i run the project with mvn spring-boot:run, it throws an exception that class not found (Main method class for Spring boot initialization).
Please suggest, what I am doing wrong here, here is my maven configuration class:
<?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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<properties>
<java.version>1.6</java.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<start-class>com.assignment.BootInitializer</start-class>
</properties>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.1.9.RELEASE</version>
</parent>
<groupId>com.assignment</groupId>
<artifactId>spring-assignment</artifactId>
<version>1.0</version>
<packaging>jar</packaging>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-mongodb</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
And here is the main initializer class:
package com.assignment;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
#Configuration
#EnableAutoConfiguration
#ComponentScan
public class BootInitializer {
public static void main(String[] args) {
SpringApplication.run(BootInitializer.class, args);
}
}
What I need to do, to ensure that maven is compiling the java classes and including them in the jar file.
Thanks.
I am learning Spring Boot.
Okay, good. Let's do one step at a time. Go to start.spring.io and generate a template project with whatever dependencies you want and whatever build tool (maven / gradle) you like. Build it and run it and see whether it is coming up or not. Then incrementally build on top of it.

Spring Data JPA intelligence not working in Intellij

I have set up a spring boot project with Spring Data JPA, but I am not seeing the intelligence for Spring data jpa.
The screen shot shows the issue, my Restaurant entity has a variable call restaurantAddress, I am trying to let intelliJ help me finish the coding but no intelligence shows up.
My project set up is as follows:
Application class:
#SpringBootApplication
#ComponentScan(basePackages = {"com.mycompany"})
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}
POM:
<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.mycompany</groupId>
<artifactId>food</artifactId>
<version>1.0-SNAPSHOT</version>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.2.7.RELEASE</version>
</parent>
<dependencies>
<!-- Dependencies for RESTful Web Services -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<!-- Dependencies for JPA Data Persistence -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<!--JDBC-->
<dependency>
<groupId>postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>9.1-901-1.jdbc4</version>
</dependency>
</dependencies>
<build>
<finalName>food</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
I have Spring Data plugin installed on my IntelliJ 15, prject settings:
I solved this problem by adding JavaEE Persistence framework support. Just right click on the project, select Add Framework Support and then scroll down to find the JavaEE Persistence, then enable the checkbox and hit OK:
Adding JavaEE Persistence Facet
It will add a persistence.xml file, you can delete it. Finally your auto completions will be back:
Moment of truth
Update You can also enable JPA facet in the Project Structure. First, press Ctrl Alt Shift S or go to Files > Project Structure. Hit the Add button and in the menu, then select JPA:
Adding JPA Facet
And finally hit OK.

Maven, JUnit and Dagger - Dagger module could not be loaded

Note: I am building/testing via command line only.
I am running into an issue using Dagger, and have been able to reproduce the same issue in a very small test project. When trying to use Dagger in a unit test, I get the following error while running 'mvn clean test':
sanity(com.mycompany.app.AppTest): Module adapter for class com.mycompany.app.AppTest$TestModule could not be loaded. Please ensure that code generation was run for this module.
In the application, Dagger is compiling/building just fine, and injection is working great. The only issue is with the unit tests, and I feel that the unit tests arent picking up the results from the dagger-compiler, but am not sure how to test/fix this.
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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.mycompany.app</groupId>
<artifactId>my-app</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<name>my-app</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.7</source>
<target>1.7</target>
<compilerArgument>-proc:none</compilerArgument>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
<dependencies>
<dependency>
<groupId>com.squareup.dagger</groupId>
<artifactId>dagger</artifactId>
<version>1.2.2</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.squareup.dagger</groupId>
<artifactId>dagger-compiler</artifactId>
<version>1.2.2</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.8.2</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
AppTest.java
package com.audible.hushpuppy.dagger;
import org.junit.Before;
import org.junit.Test;
import dagger.Module;
import dagger.ObjectGraph;
import static org.junit.Assert.assertNull;
public class AppTest {
#Module(injects = AppTest.class)
public class TestModule{
}
#Before
public void setUp() throws Exception {
ObjectGraph.create(new TestModule());
}
#Test
public void sanity() throws Exception {
assertNull(null);
}
}
Aha - apparently annotation processing was completely turned off in an earlier commit, and I completely missed this line in the pom:
<compilerArgument>-proc:none</compilerArgument>

Resources