WFLYEE0040: A component named '...' is already defined in this module

Viewed 5807

I get this error in a Java maven project. The weird thing is, it doesn't appear on every machine so I assume it has something to do with a configuration issue.

The class RoleKeyCacheImpl is a @Startup @Singleton:

@Startup
@Singleton
public class RoleKeyCacheImpl implements RoleKeyCache { ... }

That's the error Wildfly triggers when deploying the service.

Caused by: java.lang.IllegalArgumentException: WFLYEE0040: A component named 'RoleKeyCacheImpl' is already defined in this module at org.jboss.as.ee.component.EEModuleDescription.addComponent(EEModuleDescription.java:167) at org.jboss.as.ejb3.deployment.processors.EJBComponentDescriptionFactory.addComponent(EJBComponentDescriptionFactory.java:58)

I've tried:

  • installing a new Wildfly (V10, V13) on the same machine -> doesn't help
  • installing a completely new Eclipse on this machine -> doesn't help
  • cleaning & rebuilding all related projects
  • making sure the deployments-folder is empty and doesn't contain old versions of the same WAR
  • read the related question here which also didn't help (they use Spring): A component named 'XXX' is already defined in this module in JBoss 7.1.1
  • read and tried this q&a: Wrong dependencies with EJB in JBoss Wildfly (server-clean) -> doesn't help
  • deleted and rebuilt the local maven rep (".m2") -> no effect

  • checking out the same source on another computer -> does work on one machine, on another it gives the same error

I have absolutely no clue what the issue is or even could be. On one machine, we check it out and it runs without errors. On others, the exact same error happens.

Does anybody have an idea?

4 Answers

I had this same issue multiple times with EAP 7.1 and now again with WildFly 21.0.0. I know by experience this is an issue caused by Eclipse who tries to deploy automatically to a configured WildFly instance. During the deployment (or undeployment) some concurrent file issue arises and files who should be removed, are still on the filesystem, causing this error that a component is already defined.

In fact it is not already defined, it is just WildFly that is confused because it finds in his temporary directories some old files which shouldn't be there and reference your exact same component.

Solution: remove in the WildFly standalone directory the content in the 'deployments' directory and the 'tmp' directory. Rest assured, all what is there is okay to remove safely. Reboot and the error message will be gone ;-)

Looks like the class already exists. Check if it does...you may have to rewrite that part of EEModuleDescription to use its own private methods (which would be what you would write) rather than overriding methods in RoleKeyCacheImpl. If the class actually does not exist then right-click on the project -> Maven 2 Tools -> Generate Eclipse Artifacts (Check for Updates). That will regenerate all of the dependencies that the project uses. Also please be sure that you have not added any new projects to the classpath by mistake as that may also cause this error.

I just ran into this today when a colleague added a maven dependency. Turns out this dependency was a jar with a nasty classpath entry or "../" in the manifest. I edited the jar's manifest.mf that was cached in my local maven repository using 7-zip and removed the "../" classpath entry. Then re-packaged my war file (maven clean install) and bingo, it works!

In my case it was caused by org.libreoffice jurt version 5.4.2 (but other versions I checked also have the classpath nastiness).

Unfortunately I was lucky we pinpointed it to a dependency, YMMV!

You should pay attention to not have two @Stateless EJB annotations on top of two classes with the same name - in the same module. You may differentiate them by using the name attribute in the annotation and put different values in each class

Related