I've added:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-configuration-processor</artifactId>
<optional>true</optional>
</dependency>
to my pom.xml per intellij's request/warning.
Now I'm seeing "Re-run Spring Boot Configuration Annotation Processor to update generated metadata".
How do I do what intellij is asking me to do?
This link, B.2 Generating your own meta-data using the annotation processor, does not have instructions.
Following these instructions worked for me: http://www.mdoninger.de/2015/05/16/completion-for-custom-properties-in-spring-boot.html
That message about having to Re-run the Annotation Processor is a bit confusing as it appears it stays there all the time even if nothing has changed.
The key seems to be rebuilding the project after adding the required dependency, or after making any property changes. After doing that and going back to the YAML file, all my properties were now linked to the configuration classes.
You may need to click the 'Reimport All Maven Projects' button in the Maven pane as well to get the .yaml file view to recognise the links back to the corresponding Java class.
None of these options worked for me. I've found that the auto detection of annotation processors to be pretty flaky. I ended up creating a plugin section in the pom.xml file that explicitly sets the annotation processors that are used for the project. The advantage of this is that you don't need to rely on any IDE settings.
<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>
<version>3.7.0</version>
<configuration>
<compilerVersion>1.8</compilerVersion>
<source>1.8</source>
<target>1.8</target>
<annotationProcessors>
<annotationProcessor>org.springframework.boot.configurationprocessor.ConfigurationMetadataAnnotationProcessor</annotationProcessor>
<annotationProcessor>lombok.launch.AnnotationProcessorHider$AnnotationProcessor</annotationProcessor>
<annotationProcessor>org.hibernate.jpamodelgen.JPAMetaModelEntityProcessor</annotationProcessor>
</annotationProcessors>
</configuration>
</plugin>
You can enable annotation processors in IntelliJ via the following:
Click on File
Click on Settings
In the little search box in the upper-left hand corner, search for "Annotation Processors"
Check "Enable annotation processing"
Click OK
None of the answers worked for me. If you just want to disable the message, go to Intellij Preferences -> Editor -> General -> Appearance, uncheck "Show Spring Boot metadata panel".
However, you can also live with that message, if it does not bother you too much, so to make sure you don't miss any other Spring Boot metadata messages you may be interested in.
I had the same issue. The problem is that the Spring Boot annotation processor generates the spring-configuration-metadata.json file inside your /target/classes/META-INF folder.
If you happen to have ignored this folder in IntelliJ like me (because what the heck, who cares about classes files?), the file won't be indexed by your IDE. Therefore, no completion, and the annoying message.
Just remove target from the ignore files/folders list, located in Settings > Editor > File Types > Ignore files and folders.
For me, other answers didn't work. I had to go to open Files and do Invalidate caches and restart on Intellij. After that, everything worked fine again.
Include a dependency on spring-boot-configuration-processor
Click "Reimport All Maven Projects" in the Maven pane of IDEA
Rebuild project
Having included a dependency on spring-boot-configuration-processor in build.gradle:
annotationProcessor "org.springframework.boot:spring-boot-configuration-processor:2.4.1"
the only thing that worked for me, besides invalidating caches of IntelliJ and restarting, is
Refresh button in side panel Reload All Gradle Projects
Gradle task Clean
Gradle task Build
I just needed
#EnableConfigurationProperties({MY_PROPS_CLASS.class})
in Main Application class and it helped me to resolve this issue
I had a similar issue using Gradle and Kotlin.
You should modify the build.gradle.kts file to include the following:
//build.gradle.kts
plugins {
// ...
kotlin("kapt") version "1.5.31"
}
dependencies {
// ...
kapt("org.springframework.boot:spring-boot-configuration-processor")
}
Then, to generate the annotations:
./gradlew kaptKotlin
References: https://spring.io/guides/tutorials/spring-boot-kotlin/#_configuration_properties
I had the same problem. In my case I was missing the spring-boot-maven-plugin.
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
as well as the #Data Lombok annotation
#Configuration
#ConfigurationProperties("logging.web")
#Data
public class LoggingWebConfiguration {
// ...
}
Obviously you can also just create the getter/setters yourself.
Then you must also remember to re-import and re-compile your project.
None of the above worked in my case, but brought me close. In the end explicitly defining all required annotationProcessors in the maven-compiler-plugin solved it for me. In my case this was: Spring-Boot + Lombok + MapStruct
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<annotationProcessorPaths>
<annotationProcessorPath>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-configuration-processor</artifactId>
<version>${spring-boot-configuration-processor.version}</version>
</annotationProcessorPath>
<annotationProcessorPath>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>${lombok.version}</version>
</annotationProcessorPath>
<annotationProcessorPath>
<groupId>org.mapstruct</groupId>
<artifactId>mapstruct-processor</artifactId>
<version>${mapstruct.version}</version>
</annotationProcessorPath>
</annotationProcessorPaths>
</configuration>
</plugin>
Before that I always got some warnings in the Class + in the application.properties some properties were marked as "unusued", even when they were defined in a class with #ConfigurationProperties
In the maven panel of Idea, clean and compile in the maven lifecycle worked for me.
Related
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
<configuration>
<release>11</release>
</configuration>
</plugin>
</plugins>
</build>
What is the point of using maven in intellij if it dose not work without setting the correct JDK under various intellij options?
What I mean is that now with intellij I have to set the JDK in 3 different places.
File->Setting->Build->Compiler
File->Project Structure->Project
File->Project Structure->Modules
While I aspect expect that when i compiler on the right side where are the maven options it works just by watching the pom file.
i think that depends on what type of project you want to make but personally i find maven nice to use because you can set up several actions in the pom file (for example when compiling Less files, excluding them from the build and just using the resulting css files).
another feature would be the easy way to add dependency's from the maven rep http://mvnrepository.com/
Trying to use Maven to organize my project and I keep running into the following error. I know that this error means the file is present at compile time but for some reason it can't be found at runtime.
Error: A JNI error has occurred, please check your installation and try again
Exception in thread "main" java.lang.NoClassDefFoundError: org/json/simple/parser/ParseException
So I'm working on a project in Java that will take a user query, search Google Images and then download some of the results onto my computer. To that end I've had to use some third party libraries like JSoup, Json-Simple, and Gson.
I initially added Jsoup to my classpath manually and it worked, but then I heard about Maven and started using it instead. My issue is that when I try to run my code I get the error above.
I'm just not sure how to resolve this. I've seen a bunch of other posts about similar errors and I've tried to modify my pom.xml accordingly but
I just can't get it to work. I've tried removing the ~/.m2 file, ran mvn clean, mvn install, mvn package, mvn compile, and it all works fine. But when it comes time to run, I keep getting that error.
Here's most of my pom.xml file.
<repositories>
<repository>
<id>central</id>
<name>Maven repository</name>
<url>http://repo1.maven.org/maven2</url>
</repository>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<dependency>
<!-- jsoup HTML parser library # https://jsoup.org/ -->
<groupId>org.jsoup</groupId>
<artifactId>jsoup</artifactId>
<version>1.11.3</version>
<scope>provided</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/com.googlecode.json-simple/json-simple -->
<dependency>
<groupId>com.googlecode.json-simple</groupId>
<artifactId>json-simple</artifactId>
<version>1.1.1</version>
</dependency>
<!-- https://mvnrepository.com/artifact/com.google.code.gson/gson -->
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.8.5</version>
</dependency>
<build>
<plugins>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<archive>
<manifest>
<mainClass>fully.qualified.MainClass</mainClass>
</manifest>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
</plugin>
</plugins>
</build>
FOUND SOLUTION: So I left out some parts of the pom.xml file to make it easier to read, and because all the other parts were generated by Maven itself so I figured there couldn't be an issue with anything there. But it adds a tag called "pluginManagement" that encloses all other plugins and apparently this does not allow the Shade plugin to run.
Between ngueno's guidance and this post Maven shade plugin is not called automatically for goal "package"
I was able to figure out my issue, though I'm still not entirely sure why it is an issue. Anyways, I figured I'd update this post in case someone else with a similar problem stumbles across it. This was on Mac OS btw, in case it makes a difference. Thanks for your help everyone.
Usually NoClassDefFound errors are related to missing libraries at runtime.
Since you are running using the terminal I supose you are building your project using Maven, and running the generated JAR,
I would recommend to you to use the maven-shade-plugin and generate an uber-jar as I explained on this question.
The purpose generating a uber-jar is to carry all the needed dependencies inside of it (available on the application classpath).
Implement the plugin and try to run using the new JAR.
PS: Remember to check this section related to Executable Jars
UPDATE: Remove the <scope>provided</scope> of your jsoup dependency, to enforce Maven to package it along your app, with the provided scope you are saying that this dependency will be provided by the JDK at runtime.
The jars that you identify in your dependencies must be present in the Runtime classpath.
This is not the classpath that is available when you compile the code;
it is the classpath on the host where you run the application.
You must install these jars on the target host.
Edit: More details
You must do the following:
Identify the runtime host.
Create a directory on the runtime host into which you will install the dependent jar files.
Include every jar in the classpath.
Consider abandoning the "roll-your-own" path.
If you use Spring Boot
(I like it,
I don't work for them).
One feature of spring boot is a reinvented "Fat Jar" that will include the dependencies inside one deliverable artifact (the fat jar) and will add them to the classpath at startup.
Edit:
The Spring boot executable jar file is not a "Fat Jar",
instead it includes the dependencies in a directory in the
executable jar and adds said jars to the classpath on startup.
I wanted to update my project from java 8 to java 10. Hitting the well known problems of java 9 module system. However after some fiddling, researching and back and forth I was able to compile everything in maven. I added a module-info.java to my project. See also this snippet of my pom.
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.7.0</version>
<configuration>
<source>10</source>
<target>10</target>
<release>10</release>
<optimize>true</optimize>
<debug>true</debug>
</configuration>
<dependencies>
<dependency>
<groupId>org.ow2.asm</groupId>
<artifactId>asm</artifactId>
<version>6.2</version>
</dependency>
</dependencies>
</plugin>
However Intellij is reporting 100 errors saying
unnamed module ready package X from both A and B
and similar. I'm using Intellij Community Edition 1018.1.5. I tested it in eclipse photon and there it compiles fine. I think that IntelliJ is putting the maven dependencies differently on the module path/classpath than how maven or eclipse puts them.
However, I'm at a loss and have no idea how to convince IntelliJ to compile my project.
I'd prefer to put this in a comment, since I can't really give an answer until I have more info, but you can't add screenshots to comments. In any case, did you tweak the appropriate settings under File > Project Structure > Project as in:
And also under File > Project Structure > Modules:
I have couple of maven projects:
mainProject(WAR)
- messages.properties
- messages_pt.properties
- messages_ja.properties
projectForTesting(JAR)
Any of the above knows nothing about the other one.
My goal is to provide internationalization with ResourceBundleMessageSource for projectForTesting based on messages.properties from mainProject.
I've tried to play with:
maven-war-plugin
but, I am not sure whether it will be correct one.
It will be good to know how can I correctly add dependency for projectForTesting that all properties from mainProject will be accessible.
I've already fixed this stuff in the following way:
I've added to pom.xml of mainProject
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>2.1.1</version>
<configuration>
<packagingIncludes>**/*.properties,**/*.class</packagingIncludes>
<attachClasses>true</attachClasses>
</configuration>
</plugin>
Then add dependency for projectForTesting:
<dependency>
<groupId>com.project.test</groupId>
<artifactId>mainProject</artifactId>
<version>${project.version}</version>
<classifier>classes</classifier>
</dependency>
I'm trying to use the <packagingExcludes> of the Maven war-plugin.
This is my configuration:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.2</version>
<configuration>
<archive>
<manifestEntries>
<Implementation-Version>${project.artifactId}-${project.version}-r${buildNumber}</Implementation-Version>
<Implementation-Buildtime>${timestamp}</Implementation-Buildtime>
</manifestEntries>
</archive>
<packagingExcludes>WEB-INF/lib/jaxb*.jar</packagingExcludes>
</configuration>
</plugin>
In my understanding this line:
<packagingExcludes>WEB-INF/lib/jaxb*.jar</packagingExcludes>
Should exclude all jars starting with 'jaxb' from the built .war file.
However after I run clean install I get both:
jaxb-api-2.1.jar
jaxb-impl-2.1.3.jar
Packaged in my .war WEB-INF/lib dir.
I'm using Maven 3.
Any help greatly appreciated.
Thanks in advance,
To answer gkamal's comment.
When I run mvn war:war -X I can see:
[DEBUG] Processing: jaxb-api-2.1.jar
[DEBUG] + WEB-INF/lib/jaxb-api-2.1.jar has been copied.
[DEBUG] Processing: jaxb-impl-2.1.3.jar
[DEBUG] + WEB-INF/lib/jaxb-impl-2.1.3.jar has been copied.
Also
[DEBUG] Excluding [WEB-INF/lib/jaxb*.jar] from the generated webapp archive.
No, exceptions, warning or errors or nothing that looks suspicious, anything specific I should look for ?
For a transitive dependency, you can use the exclusions element to exclude it.
<dependency>
<groupId>...</groupId>
<artifactId>...</artifactId>
<version>...</version>
<exclusions>
<exclusion>
<groupId>javax.xml.bind</groupId>
<artifactId>jaxb-api-2.1</artifactId>
</exclusion>
</exclusions>
</dependency>
As gkamal commented, you could also add an explicit dependency on jaxb and set its scope to provided, this will override the scope of the transitive dependency so it is no longer packaged.
Another alternative, the war plugin also allows to exclude based on regular expressions, but the syntax is a bit more involved, the following snippet should exclude everything under lib whose filename starts with "jaxb":
<packagingExcludes>%regex[WEB-INF/lib/jaxb.*]</packagingExcludes>
This means you have them as dependency in your project so they will be packaged into the war. Just remove the dependencies so they wont be packaged anymore.
Based on the documentation of the option you used you have to use regex which means you should write:
<packagingExcludes>WEB-INF/lib/jaxb.*</packagingExcludes>
instead of
<packagingExcludes>WEB-INF/lib/jaxb*.jar</packagingExcludes>
Further to #gkamal's comment to your question (08/05/12#11:52), check your maven-war-plugin's version. I've just spent 2hrs looking at this issue myself to exclude an unknown transient to javaee-api*.jar.
With maven 3.0.4, I was defaulted to maven-war-plugin version 2.1 (you can tell if you run your build in debug - e.g. mvn clean package -X). One of your other comments is correct in saying package-excludes came in after this. See the war plugin page for details (although the actual page describing the entry doesn't indicate version info which is pretty poor as that's what you first search for).
If you update to maven-war-plugin to 2.3 (add <version>2.3</version>, your packaging-excludes should be used. Note though you will only see this in the built war's WEB-INF/lib, not in the transient war directory (which includes the excluded jars even if debug says they're to be excluded, which is very confusing when looking at this issue).
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.3</version>
...
<packagingExcludes>
WEB-INF/lib/whatever-*.jar,
WEB-INF/lib/javaee-api-*.jar
</packagingExcludes>
...
</plugin>
...
However, in terms of best practice, this is probably a last gasp effort to exclude jars fromo the war and the dependency-level exclusions for transient jars is probably the most precise and correct way. That said, what if a transient jar is being brought in by multiple dependencies?
So, with the version upgrade, I think #khmarbaise's solution is fine (and the comment indicating it won't work is wrong). However, I think best practice is to use dependency-level exclusions as per your accepted answer.
You can do this by specifying inside <packagingExcludes></packagingExcludes> inside </configuration><configuration>.
<project>
...
<build>
<plugins>
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>3.2.0</version>
<configuration>
<packagingExcludes>
WEB-INF/lib/ex1-*.jar,
WEB-INF/lib/ex2-logging-*.jar
</packagingExcludes>
</configuration>
</plugin>
</plugins>
</build>
...
</project>
You can specify path by wild cards and regular expressions too. See this link for more info.