user1684725
user1684725

Reputation: 21

maven appears to be not compiling in order - symbol not found

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.

Upvotes: 2

Views: 1914

Answers (2)

Mark Bramnik
Mark Bramnik

Reputation: 42431

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' ?

Upvotes: 1

millhouse
millhouse

Reputation: 10007

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.

Upvotes: 2

Related Questions