I just converted a project from ant to maven and have am getting an error building a jar that behaves like the source files are not being compiled in the correct order. I have an enumerated type that looks like this:
public enum LmsError implements ILmsError {
UC0001() {
#Override
public String msg() {
return this.getClass().getName() + "-" + this + ": constructor failed: ";
}
},
The interface looks like this:
public interface ILmsError {
public abstract String msg();
}
... and this is an example of the code that uses it. The 'throws' line is the one the error message below is complaining about, but if I comment out the statement it just gets a similar error the next time the msg() method is referenced. It doesn't matter which element of the enum is being used.
} catch (Exception e) {
throw new RuntimeException(LmsError.UC0001.msg() + "Unable to construct status based on " + codeEnumeration + ":" + e.getMessage(), e);
}
mvn clean compile
[compiler:compile]
Compiling 129 source files to C:\bsaastad\workspaces\theportaltree\redirect\redirect-ejb\target\classes
-------------------------------------------------------------
COMPILATION ERROR :
-------------------------------------------------------------
com/theportaltree/redirect/status/RedirectStatus.java:[156,58] cannot find symbol
symbol : method msg()
location: class com.theportaltree.lms.LmsError
1 error
If I compile again without the clean, I get something similar to this (sometimes it takes two additional compiles to get through all the files):
[compiler:compile]
Compiling 89 source files to C:\bsaastad\workspaces\theportaltree\redirect\redirect-ejb\target\classes
[resources:testResources]
A clean compile.
If I look at the output directory after the failure I see that none of the generated enum classes are present, which explains the error. As soon as I get a successful compile, the enum classes are there as expected.
This is all in the same project, so I don't believe it is a dependency issue. I just converted this from an ant build to maven (maven newbie), where it has been compiling without issues for a couple of years. Here's the plugin section from the pom.xml. Is there something missing? Wrong version of something? I'm stumped:
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.5.1</version>
<configuration>
<!-- put your configurations here -->
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-ejb-plugin</artifactId>
<version>2.3</version>
<configuration>
<ejbVersion>3.1</ejbVersion>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>2.8.1</version>
<configuration>
<!-- javadoc configuration options here -->
</configuration>
</plugin>
</plugins>
</build>
Any help/ideas would be greatly appreciated.
Are you running an IDE at the same time as executing the command-line Maven build?
I've found that sometimes if your IDE is Maven-aware (e.g. Eclipse with the m2Eclipse plugin) you might get an undesired interaction between the two "racing" Maven engines.
If closing your IDE results in reliable clean builds, check its configuration options - it may be polling the filesystem for changes, which will in turn kick off a (clean?) build.
Try to run maven from the command line (the same mvn clean compile as you're running now).
BTW does the interface ILmsError, enum LmsError and the code that throws a runtime exception and uses the message reside in the same module?
Maybe its just lack of 'dependency' ?
Related
Currently, I'm using maven pligin to grab eclipse warnings and print them on the console, for example
HashMap<T, V> list = new HashMap<>();
The variable list has never been used, so the eclipse will underline it with yellow line as a warning. And when I compile with maven plugin, this warning will be reported on the console.
> <plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<compilerId>eclipse</compilerId>
<source>1.7</source>
<target>1.7</target>
<optimize>true</optimize>
<showWarnings>true</showWarnings>
<showDeprecation>true</showDeprecation>
</configuration>
<dependencies>
<dependency>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-compiler-eclipse</artifactId>
<version>2.3</version>
</dependency>
</dependencies>
</plugin>
And when I input the command like 'mvn clean compile', it will print
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) # iqunxing-cep ---
[INFO] Changes detected - recompiling the module!
[WARNING] D:\XXX.java:[42,1412] The value of the local variable list is not used
I'm using Eclipse, and as you all know, there are quite a lot of warnings that you can set in preference - java - compiler - error/warning.
Based on my current setting, codes like parameter assignment is also underlined.
Like in the following case, the variable i is underlined, too.
public void name(int i) {
i = 3;
}
So my question is, how can I make the maven compiler print all the warnings on the console? Because right now, I have several warnings in my codes. But it only prints part of the warnings. For example: I have a variable called 'list' that never been used which will be printed. I also assign the parameter 'i' within a method which is a warning. However, it won't be printed on the console. Should I add more tags into the pom.xml as parameters of maven-compiler-plugin?
If your project is already a Maven project and you've imported it into Eclipse as a Maven Project, you can right click it, Run As ... / Maven Build... and then enter you goals, e.g. clean compile, or select from the typical goals in the menu. It will use Maven to execute your goals and output to the console.
May u check following link?If yes, please confirm this answer.
http://maven.apache.org/plugins/maven-compiler-plugin/compile-mojo.html#showWarnings
BUILD FAILURE
Hi,
I successfully set up everything to apply changes to my application located on Openshift server. Suddenly I decided to use some of my Java classes from other project and when I try to commit changes I get this error.
I am really hopeless with the error as I was researching for about a day and google just go blank on me with this and related questions. The problem is that I can't figure out what the "-source 7" stands for and if it related to the "-source 1.6" that is mentioned in the line above it in the error message.
Error message:
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler- plugin:2.3.2:compile (default-compile) on project organizer: Compilation failure: Compilation failure:
[ERROR] /var/lib/openshift/56c42c687628e1f0a2000073/app-root/runtime/repo/src/main/java/organizer/DataOperations.java:[185,9] error: strings in switch are not supported in -source 1.6
[ERROR] (use -source 7 or higher to enable strings in switch)
This error is repeated for every instance of using String in switch statement.
EDIT: I am looking for a solution not only explanation. Trying to configure pom file atm.
I appreciate any help at all..
Thank you,
Ondrej
As noted above, String in Switch statements are only supported in Java 7+.
Looking at the error message you should update your POM to include the following i.e. explicitly compile against Java 7.
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>7</source>
<target>7</target>
</configuration>
</plugin>
</plugins?
</pluginManagement>
<build>
How can I write equivalent maven plugin for the following gradle plugin defined?
/*
* Plugin to copy system properties from gradle JVM to testing JVM
* Code was copied from gradle discussion froum:
* http://forums.gradle.org/gradle/topics/passing_system_properties_to_test_task
*/
class SystemPropertiesMappingPlugin implements Plugin{
public void apply(Project project){
project.tasks.withType(Test){ testTask ->
testTask.ext.mappedSystemProperties = []
doFirst{
mappedSystemProperties.each{mappedPropertyKey ->
def systemPropertyValue = System.getProperty(mappedPropertyKey)
if(systemPropertyValue){
testTask.systemProperty(mappedPropertyKey, systemPropertyValue)
}
}
}
}
}
}
It really depends on what exactly you want to achieve.
In case you want to help with writing a maven plugin in general, you'll have to read the documentation.
In case you want to filter system properties that Maven JVM passes to your test JVM, I don't see any other option than extending the maven-surefire-plugin plugin and add there an option to do such mapping. (Note that by default Maven passes all its System Properties to the test JVM.) That is definitely doable but maybe you can achieve your goal with something maven already offers.
You can definitely pass additional system properties to your test JVM from Maven by using:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.19</version>
<configuration>
<systemPropertyVariables>
<propertyName>propertyValue</propertyName>
<anotherProperty>${myMavenProperty}</buildDirectory>
</systemPropertyVariables>
</configuration>
</plugin>
as documented http://maven.apache.org/surefire/maven-surefire-plugin/examples/system-properties.html.
In this case you can set the value of anotherProperty from command line by invoking maven
mvn test -DmyMavenProperty=theValueThatWillBePassedToTheTestJVMAsProperty_anotherProperty
You can also use Surefire argline to pass multiple properties to the JVM. For instance
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.19</version>
<configuration>
<argLine>${propertiesIWantToSetFromMvnCommandLine}</argLine>
</configuration>
</plugin>
and execute maven as follows
mvn test -DpropertiesIWantToSetFromMvnCommandLine="-Dfoo=bar -Dhello=ahoy"
in this case, you'll see properties foo and hello with values bar and ahoy, respectively, in your test JVM.
I'm interested in learning JBox2D, but I seem to have stumbled at the first hurdle - building the library.
The Quick-start instructions specify the following simple steps:
Check out the project through Subversion:
Import to your IDE as a Maven project (using the pom.xml descriptor in the root folder)
Run the org.jbox2d.testbed.framework.TestbedMain class
I've checked out the code and imported the project in to IntelliJ IDEA (12.1.4), however, when I try to run the TestbedMain class (and it subsequently compiles the code) I get the following errors:
java: duplicate class: org.jbox2d.common.PlatformMathUtils
java: duplicate class: org.jbox2d.common.Timer
What am I doing wrong/have I missed?
Thanks
Looking at the POM for the jbox2d-library module, I see that there is a build section which explicitly ignores the classes under the gwtemul package:
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<excludes>
<exclude>**/gwtemul/**</exclude>
</excludes>
</configuration>
</plugin>
</plugins>
</build>
It seems to me that I should probably be building this library through MVN and attaching the built JAR as a dependency for the jbox2d-testbed module.
However, I found that modifying the package declaration for these classes also solves the problem:
package org.jbox2d.gwtemul.org.jbox2d.common;
/**
* A GWT-compatible implementation of the platform math utilities.
*/
class PlatformMathUtils {
public static final float fastPow(float a, float b) {
return (float) Math.pow(a, b);
}
}
And since they would have been ignored by the build anyway, I don't see that it causes any harm.
Once I did this, I was able to run the org.jbox2d.testbed.framework.TestbedMain class and I get the expected GUI:
I run command like this:
mvn tomcat:redeploy
as see a lot of errors like "...of type ImageDaoImpl must override a superclass method"
But after this I do nothing, just run this command again and this time it compiles ok!
Could anyone tell me how to fix that?
Every odd compilation time I get this error, it's quite annoying..
I can't immediately tell you why the issue goes away, but typically this compiler error indicates that you're attempting to compile Java 6-compliant code (which allows #Override on implementations of interfaces) with a compiler set to Java 5 compliance (which only allows #Override when overriding a concrete method from a super class).
I've just resolved my issue)
I have two plugins:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>aspectj-maven-plugin</artifactId>
<configuration>
<source>1.5</source>
<complianceLevel>1.5</complianceLevel>
</configuration>
...
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>${jdk.version}</source>
<target>${jdk.version}</target>
</configuration>
</plugin>
The first plugin was configured for 1.5 java the other was configured by ${jdk.version} which is 1.6
It's still a mystery for me why it compiles at all, but after setting 1.5 to 1.6 my issue has gone.