0

Most recently I am working with maven 3.x, Eclipse Juno JavaEE IDE with JDK 1.6.0_26. Some where in my project I used enum both inside and outside of a class. When I run clean build it appear an error

[ERROR] found   : my.package.MyClass.MyEnum
[ERROR] required: my.package.MyClass.MyEnum

Then I ensured that my/package/MyClass.java need to compile first so I added

<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>
    </configuration>
    <executions>
        <execution>
            <id>default-compile</id>
            <goals>
                <goal>compile</goal>
            </goals>
            <configuration>
                <excludes>
                    <exclude>**/*.*</exclude>
                </excludes>
                <includes>
                    <include>**/MyClass.java</include>
                </includes>
            </configuration>
        </execution>
        <execution>
            <id>second</id>
            <goals>
                <goal>compile</goal>
            </goals>
            <configuration>
                <includes>
                    <include>**/*</include>
                </includes>
                <excludes>
                    <exclude>**/MyClass.java</exclude>
                </excludes>
            </configuration>
        </execution>
    </executions>
</plugin>

After that it is not work hopefully. It's very much annoying to me. If I had to use enum in my application how do I will overcome it. Someone trying to prove in their blog it is the bug java 1.6.0_26 and fixed in JDK 7. If so it is not possible to migrate to JDK 7.x. Any way to solve this problem with maven 3.x with Eclipse JNO Java EE.

package com.formativesoft.mcserp.validator;

public class Validator {

    public enum Lang {
        EN, BN;
    }
}
Śhāhēēd
  • 1,812
  • 6
  • 23
  • 44
  • why do you want to exclude everything from compilation? and compile only enum class? – WeMakeSoftware Mar 30 '13 at 10:02
  • As the enum class not compiled first so I trying to compile enum class only. After enum class compiled then I trying to compile rest of class those are depend on enum class. – Śhāhēēd Mar 30 '13 at 10:05
  • could be something is messed up with cross-dependencies or maven caches. try cleaning ~/.m2 directory and run a maven build. also, do you run maven from command line or from eclipse? in questionable situations it is always best to run maven from command line. – Denis Tulskiy Mar 30 '13 at 17:41
  • @ShahedHossain Out of context, but Why you are writing, Eclipse Juno as >> Eclipse JNO ? – ajduke Mar 30 '13 at 17:45
  • You are using an ancient and insecure version of Java 6. Upgrade to 6u43 – artbristol Apr 02 '13 at 11:55

1 Answers1

2

You don't need the compile execution gimmicks. If your enum is used in the same artifact in which it is defined, there is nothing special you need to do. I would guess it is just some temporary glitch. Remove the goal definition exclusion madness from the config of your pom, run mvn clean install on your project from console and almost certainly you won't have a problem. If you do, include the error message so we can help you further.

Nikola Yovchev
  • 9,498
  • 4
  • 46
  • 72
  • `[INFO] ------------------------------------------------------------- [ERROR] COMPILATION ERROR : [INFO] ------------------------------------------------------------- [ERROR] D:\Workspaces\MCSWorksapces\SpringWorkspace\mcserp\spring-validator\src\ main\java\com\formativesoft\mcserp\validator\NickName.java:[20,25] incompatible types found : com.formativesoft.mcserp.validator.Validator.Lang required: com.formativesoft.mcserp.validator.Validator.Lang` – Śhāhēēd Mar 30 '13 at 11:39
  • Actually it was tried as you mentioned, While unable to get fruitful result then `executions` node are added. First it was assumed that it could be problem of eclipse then I tried it directly from maven console and still trying. Error message as above written by me – Śhāhēēd Mar 30 '13 at 11:46
  • Can you post the code of mcserp.validator.Validator.Lang ? How is it defined? Does code look compilable in eclipse? Is it possible you define your enum as a subclass of some other class? Then you need to pass in an instance of the parent class as well, or look at this so question: http://stackoverflow.com/questions/2097982/is-it-possible-to-create-an-instance-of-nested-class-using-java-reflection – Nikola Yovchev Mar 30 '13 at 17:07
  • I just edited my post where at the end of the post you will find the enum definition. – Śhāhēēd Apr 02 '13 at 09:59
  • As I stated, if your enum is defined as a subclass of another class, you might be in a problem. Define the enum as a separate class and it should be no problem. – Nikola Yovchev Apr 02 '13 at 11:32
  • First It was separate class. While it unable to compile then I made it subclass but both are same. – Śhāhēēd Apr 02 '13 at 11:41
  • It should be a separate class if you want to use it outside of its parent class without passing the parent instance. – Nikola Yovchev Apr 02 '13 at 12:41
  • You have two choices: either define your enum as a static in which case it becomes a nested class, or you can omit the static modifier in which case it becomes an inner class which requires an instance of the parent class, in your case: Validator in order to be constructed and passed around. – Nikola Yovchev Apr 02 '13 at 14:31