In eclipse I receive this error: "Endorsed directory ... is missing. You may need to perform a Maven command line build to create it."
It seems to be related to this plugin in my pom:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
<compilerArguments>
<endorseddirs>${project.build.directory}/endorsed</endorseddirs>
</compilerArguments>
</configuration>
</plugin>
The project builds successfully on the command line. I did a clean build in Eclipse but still have this error.
What is wrong with my setup?
I think the problem is with
<endorseddirs>${project.build.directory}/endorsed</endorseddirs>
Refer to Link - Pass Compiler Arguments
Related
When I was building my project like :-
mvn clean install -DskipTests
, then it was giving some error.
After that, I just added, -Djdk.version=1.8, then it works fine.
Can someone tell what is the reason for this?
Try something like this in your pom:
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.3</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</pluginManagement>
....
</build>
It may be because you might be missing the maven-compiler-plugin.
Try the following:
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.3</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</pluginManagement>
....
</build>
From Maven 3, it defaults to JDK 1.5. So if you do not include the version, it will take JDK 1.5 as default compiler version.
Since, you mentioned that you used JDK 1.8, and the error disappeared. So if you had maven-compiler-version defined in the pom.xml, the error might be because the version would had not been defined.
So by default, it pointed to JDK 1.5 and it was trying to compile the code which would be defined for JDK 1.8 and not for JDK 1.5.
So, it is better to define the correct java version in the pom.xml
Why to specify java version in maven build?
Because Maven won't try to guess the Java version your project was created with (the one you probably only configured in your IDE).
You need to specify the earliest version supported in your pom.xml with:
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.3</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>
I'm trying to add the debug symboles by using mave-compiler-plugin (so that I'll be able to access the method parameters names).
Following the available configurations that can be found here,
Here is my maven-compiler-plugin configuration
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>${java.version}</source>
<target>${java.version}</target>
<compilerArgument>-Xlint:all</compilerArgument>
<showWarnings>true</showWarnings>
<showDeprecation>true</showDeprecation>
<debug>true</debug>
<debugLevel>lines,vars,source</debugLevel>
</configuration>
</plugin>
Untill now, I have no success.
Can someone please let me know how to add the debug symboles by using maven?
You may need to add <fork>true</fork> according to the maven-compiler-plugin documentation for compilerArgument.
Sets the unformatted single argument string to be passed to the compiler if fork is set to true.
Not sure if it's required but you may want to add <groupId>org.apache.maven.plugins</groupId> and <version>#.#.#<\version>.
Also, as #JonK mentioned in the comments, you need source instead of sources for debugLevel.
In case of my project I need to create new classes after each compilation. For compilation I'm using maven compiler plugin 3.1. I tried to use compilerReuseStrategy = alwaysNew option but it didn't make any affect, it always compile only changed classes. Here is plugin declaration in pom.xml:
<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>
<compilerReuseStrategy>alwaysNew</compilerReuseStrategy>
</configuration>
</plugin>
An I doing something wrong or that's a bug and this option really doesn't work?
If you are talking about the incremental feature fo the maven-compiler-plugin you can change this behaviour by the following configuration:
<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>
<useIncrementalCompilation>false</useIncrementalCompilation>
</configuration>
</plugin>
The compileReuseStrategy in contradiction is intended to define the behaviour in relationship with multi-threaded running of the compiler.
What about using mvn clean install?
I have a Maven webapp that uses the maven-compiler-plugin . A few days ago I could compile and run the app just fine, however something happened and compilation now fails with the following error:
[ERROR] Failure executing javac, but could not parse the error:
javac: -endorseddirs requires an argument
Usage: javac <options> <source files>
It has something to do with the compiler but I can't understand it. Here's my pom.xml (just the plugins):
<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>
<compilerArguments>
<endorseddirs>${endorsed.dir}</endorseddirs>
</compilerArguments>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.1.1</version>
<configuration>
<failOnMissingWebXml>false</failOnMissingWebXml>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.1</version>
<executions>
</executions>
</plugin>
</plugins>
I have tried some solutions like this.
As far as I know, ${endorsed.dir} is not a standard Maven property. Have you copied this example from somewhere without replacing ${endorsed.dir} with an actual value? Or did you have this value defined elsewhere in your pom.xmlbut it has been removed?
If this is the case, Maven would treat the field as blank and I can imagine the compiler would receive no argument for the -endorseddirs parameter.
Java compiler is not able to locate property ${endorsed.dir} in you POM, Make sure it is defined in you POM. To check configuration of POM by mvn help:effective-pom, That will show actual POM after factoring all configuration.
I have one jar dependency in my java project that contains sources as well and when I run mvn compile, these java sources appear as class files in my compiled maven output :(...
How can I exclude these files.. (I only want my own compiled files in the compiled output)
I tried something like:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.1-SNAPSHOT</version>
<configuration>
<excludes>
<exclude>**/bv/**/*.java</exclude>
</excludes>
</configuration>
</plugin>
Played with it but they keep appearing in my maven compiled output :( ..
Any idea's ?
My understanding is that this is a normal behavior of javac that searches the whole classpath for source files to compile unless the -sourcepath option is given (and this would be the solution here).
Unfortunately, there is a Jira issue about -sourcepath not being passed to javac by the Maven Compiler Plugin (see MCOMPILER-98) but there is a workaround. So, could you please try this:
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<compilerArguments>
<sourcepath>${project.basedir}/src/main/java</sourcepath>
</compilerArguments>
</configuration>
</plugin>
Would the provided scope work?
From: http://maven.apache.org/guides/introduction/introduction-to-dependency-mechanism.html:
This is much like compile, but
indicates you expect the JDK or a
container to provide the dependency at
runtime.
You can pass the -implicit:none parameter to the compiler
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<compilerArgument>-implicit:none</compilerArgument>
</configuration>
</plugin>