74

I'm getting this warning in Eclipse:

Classpath entry org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER will not be exported or published. Runtime ClassNotFoundExceptions may result

After searching I found that I need fix export. I did it.

Eclipse Java Build Path properties

But this warning persists! What else can be done to fix it? Thanks.

Rup
  • 33,765
  • 9
  • 83
  • 112
user710818
  • 23,228
  • 58
  • 149
  • 207
  • At what "runtime" do you get the exceptions? Where do you expect that variable to be "exported or published"? – Ryan Stewart Jul 23 '11 at 13:37
  • 3
    @Ryan it's not us, it's eclipse. http://stackoverflow.com/questions/3653785/annoyance-how-to-disable-eclipse-classpath-entry-warnings – Rup Aug 23 '11 at 09:36

16 Answers16

37

You can right click on the warning, choose quickfix and choose one of the following:

  • Mark the associated raw classpath entry as a publish/export dependency.
  • Exclude the associated raw classpath entry from the set of potential publish/export dependencies.

As you will not have eclipse publishing/exporting the project it is safe to exclude it. But either way it makes no difference

Step by step screenshots:
http://publib.boulder.ibm.com/infocenter/radhelp/v8/index.jsp?topic=/com.ibm.javaee.doc/topics/tlooseclasspath.html

Alin Stoian
  • 1,122
  • 1
  • 12
  • 24
29

I had tried both of the options but only the latter is what you need:

  • Mark the associated raw classpath entry as a publish/export dependency
  • Exclude the associated raw classpath entry from the set of potential publish/export dependencies

If you export the dependency, refreshing the project configuration via Maven -> Update Project Configuration context menu will cause the warning to return. In this case you need to edit the .classpath file by hand:

<classpathentry kind="con" exported="true" path="org.maven.ide.eclipse.MAVEN2_CLASSPATH_CONTAINER">
    <attributes>
        <attribute name="org.eclipse.jst.component.dependency" value="/WEB-INF/lib"/>
    </attributes>
</classpathentry>

Simply delete have the attribute exported="true" and confirm by refreshing the project configuration.

Betlista
  • 10,327
  • 13
  • 69
  • 110
dcompiled
  • 4,762
  • 6
  • 33
  • 36
  • 4
    Since 3.7, org.maven.ide.eclipse changed to org.eclipse.m2e. – Josh Unger Mar 22 '13 at 18:59
  • 1
    with the current version of m2e (1.4.0.20130601-317) _Update Project_ does not overwrite your changes so you can just use the quickfix (see also: http://stackoverflow.com/questions/3653785/annoyance-how-to-disable-eclipse-classpath-entry-warnings) – TmTron Sep 17 '13 at 08:17
  • 3
    @MartinTrummer, I have the same version, and it does remove quick-fixed "nondependency" markers on update. – Vsevolod Golovanov Nov 19 '13 at 08:41
  • Thanks! This helped me with another issue I was having with Groovy Libraries being re-exported after unchecking and doing Maven > Update Project. – Barett Jul 17 '14 at 22:45
  • 2
    ATPIT current version of m2e is 1.5.0.20140606, and it still overwrites your changes. – muttonUp Aug 14 '14 at 22:21
  • @muttonUp The same with 1.6.0.20150526-2032. However, if that helps, if you uncheck 'Update project configuration from pom.xml' the issue doesn't come back, so apparently you have to change something in pom.xml, I guess. – Marcel Korpel Jul 23 '15 at 22:07
  • Speaking from Sept 2022, with Eclipse 4.25 (2022-09) and M2E 2.0.4.20220904-1703: Running Maven -> Update Project ALWAYS sets the attribute to ``. No combination of Quick Fix worked. Follow above direction: In text editor, replace the attribute in .classpath with `` and wait a few seconds for the problem to disappear. – Thad Sep 21 '22 at 14:35
16

I had the same problem; it vanishes after including

<packaging>war</packaging> 

in the pom. There was no packaging at all.

Frank Rünagel
  • 307
  • 3
  • 5
10

See this solution from Geert Schuring's blog:

On certain occasions Eclipse will present you with the following warning:

Classpath entry org.maven.ide.eclipse.MAVEN2_CLASSPATH_CONTAINER will not be exported or published. Runtime ClassNotFoundExceptions may result.

So solve this, do the following:

  1. Open the properties of the project that generates this warning
  2. Click on “Java Build Path”
  3. Click on the tab “Order and Export”
  4. Enable “Maven Dependencies”
  5. Click on “Ok”
  6. Open the “Problems” view
  7. Select the warning we are trying to solve, and press “Ctrl-1″
  8. Click on “Ok”

The problem is now solved. It may take some time before the warning disapears because the project needs to rebuild before it goes away.

blackgreen
  • 34,072
  • 23
  • 111
  • 129
  • This does work under windows. On Linux however, Ctrl+1 does nothing. – nagylzs Jul 10 '18 at 06:32
  • Eclipse has changed considerably since this was written (2009). I believe the order of the 2 quick fix suggestions has changed, so this used to perform "Mark the associated raw classpath entry as a publish/export dependency.", but now (Eclipse 2022-12) performs "Exclude the associated raw classpath entry from the set of potential publish/export dependencies". With current versions, to achieve what Geert did, a "7B" step should be added, i.e. 'Select "Exclude the associated raw classpath entry from the set of potential publish/export dependencies"'. – Philippe Cloutier Feb 20 '23 at 22:59
5

I wasn't able to solve the problem with the quickfix in Eclipse Luna. The problem disappeared after removing the Project Facet "Dynamic Web _Module". In Windows -> Preferences -> Project Facets.

enter image description here

P.S. Packaging as War also solved the issued but it was suppoused to be a JAR and I was puzzled why some projects worked ok and some didn't.

And by the way, the warning was real. It caused a ClassNotFoundExceptions exceptions in the server that made it unsusable when other projects referenced this.

borjab
  • 11,149
  • 6
  • 71
  • 98
  • 1
    When having actived _JavaServer Faces_ deactivating _Dynamic Web Module_ results in the error _"JavaServer Faces requires Dynamic Web Module 2.5 or higher."_ Thus I can't deactivate it. I tried all the other answers here. None of them worked for me. Do you have any further hints? – Gerold Broser Jun 13 '15 at 11:47
  • [@VonC's answer](http://stackoverflow.com/a/3653802/1744774) linked in @Rup's comment to the question didn't help either. – Gerold Broser Jun 13 '15 at 11:59
  • Got it! [@ decompiled's answer here](http://stackoverflow.com/a/9455576/1744774) solved it after applying it prior to launching Eclipse (Luna). – Gerold Broser Jun 13 '15 at 12:04
  • Lost it! After _Maven_ → _Update Project..._ the warning is there again. That's annoying! – Gerold Broser Jun 13 '15 at 12:14
  • change the packaging from jar to war solved this issue. – Alter Hu May 06 '16 at 05:13
5

Simply right click on the warning and do a quick fix

enter image description here

You can then review the .classpath file changes from source control

enter image description here

Community
  • 1
  • 1
Fangming
  • 24,551
  • 6
  • 100
  • 90
3

I have a simple way to solve this problem:

  1. Delete the project from your Eclipse.
  2. Into the work space where the project is located.
  3. Delete the items selected in the following image. Just leave src and pom.xml.

    enter image description here

  4. Re-import the project in your Eclipse.

howlger
  • 31,050
  • 11
  • 59
  • 99
Moco
  • 31
  • 1
2

None of the answers helped in my case. Every time I update the project, m2e will delete the entry from the .classpath file which disables the warnings.

I've now filed a bug report: https://bugs.eclipse.org/bugs/show_bug.cgi?id=537401

Aaron Digulla
  • 321,842
  • 108
  • 597
  • 820
1

Most answers, including the currently accepted one, only provide a temporary solution to this issue: every time I chose Maven > Update Project… and leaving the option 'Update project configuration from pom.xml' on, the warning came back.

However, after installing m2e-wtp - Maven Integration for WTP in Eclipse 4.5 (Mars) and issuing Update Project… again, while leaving the option selected, the warning (and resulting error) went away.

Marcel Korpel
  • 21,536
  • 6
  • 60
  • 80
  • Did you check the .classpath file? I selected the Quick Fix option to "Exclude the associated raw classpath...". The .classpath file reflects that change. But then after issuing Maven > Update Project... with the option 'Update project configuration from pom.xml' on, that classpath entry (in .classpath) is changed to publish/export the dependency. So, although the warning doesn't reappear (due to the fact it's set to publish/export), my quick fix choice to exclude the dependency is overwritten. – James Mar 08 '16 at 23:32
  • @James Thanks for the remark, but I'm no longer using Eclipse due to other severe issues with it (in combination with a bunch of plugins to be able to use JSF). I'm now using Netbeans, works like a charm when doing the things I want to do (using Maven, JSF, etc.). – Marcel Korpel Mar 09 '16 at 00:59
  • Thanks anyway, but this didn't help for me (for what it's worth, m2e-wtp was already installed). – Philippe Cloutier Feb 20 '23 at 17:39
1

I was in the same situation that Aaron Digulla.

I am learning Maven and noticed that this issue manifested when

  • I added a pom packaging line, for war
  • updated the project
  • removed said line and updated again

I noticed that the file ".settings/org.eclipse.wst.common.component" was one of the leftover files after this operation. When I removed this one in particular and updated the project, the Warning would go away and it wouldn't come back unless I repeated it all again.

JumBê
  • 29
  • 7
0

Using Eclipse Photon, the configuration below fixed the problem for me: Window > Preferences > Maven > Java EE Integration > Enable Java EE Configuration

Note that I disabled this option before receiving the warning Classpath entry org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER will not be exported

All other options may not be checked if you do not need them.

The warning does not reappear after a Maven update.

0

I had the same issue after updating my JDK in project and resolved it by replacing my .classpath file with previous one. I noticed the following changes in my .classpath file

    <attributes>
        <attribute name="maven.pomderived" value="true"/>
        <attribute name="org.eclipse.jst.component.dependency" value="/WEB-INF/lib"/>
    </attributes>

The second line was missing from above code

<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>

This line was missing

    <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8">
    <attributes>
        <attribute name="owner.project.facets" value="java"/>
    </attributes>
</classpathentry>

These lines were added so I manually removed them and it all worked again.

  • This answer is difficult to understand, but adding the org.eclipse.jst.component.dependency attribute to org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER did solve for me, including the runtime exceptions. Unfortunately, that seems to be equivalent to "Mark the associated raw classpath entry as a publish/export dependency" as suggested in answers from Alin Stoian and Fangming. It does not resist a Maven update, so the warning and exceptions will eventually come back. – Philippe Cloutier Feb 20 '23 at 19:15
0

I had the same problem in a maven project with dynamic web project, but I solved it like this.

  1. Right click on the project

  2. Properties

  3. Deployment Assembly and button "add".

    enter image description here

  4. Select Directive Type "Java Build Path Entries"

    enter image description here

  5. Select "Maven Dependecies" and select button finish

    enter image description here

  6. This way when the "war" file of the final project is created, all the "jar" files from the "Maven Dependencies" directory will be added.

    enter image description here

Jeremy Caney
  • 7,102
  • 69
  • 48
  • 77
Cperez
  • 1
-1

Adding to the pom.xml:

<properties>
    <java.version>1.8</java.version>
</properties>

helped me in this case and also with Dynamic Web Module and other issues.

janap
  • 1
-1

I came across this issue too! I Believe that eclipse adds the same deps twice. once in the

Maven Dependencies

Group and another in the form of

M2_REPO/ ...

You must remove the last one in the

Properties -> Java Buil Path -> Libraries

for the error to dissapear!

Biggg Jimmm
  • 67
  • 2
  • 12
-5

That's the typical problem with maven projects configured in Eclipse that are changed its configuration or saved inappropriately.

Normally I'll edit my .classpath file and check the references for the build path, etc.

So in your case, I think you'll need to delete your classpathentry with those org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER reference inside.

Nacho Cougil
  • 552
  • 6
  • 15
  • 1
    You can't just delete that from your classpath. I did it and my project threw 1000 errors because Maven dependencies are not on the classpath anymore. – Dave Dec 14 '11 at 16:30
  • i have no idea how this answer was approved. this completely is not the was and does not work. if it should it defiantly needs further explenations – Gleeb Jan 29 '12 at 21:19
  • If you just delete it from the classpath you will not have the referenced maven dependencies. Solves the warning, but you get error because of missing dependencies. – Alin Stoian Feb 12 '12 at 10:55
  • The idea behind my approach is that you need to use the good configuration between your project using the right maven plug-in in Eclipse to avoid changes in your .classpath file. For example, if you change your pom.xml you don't need to change your .classpath file, in fact, you must not do it! The idea is that your maven plug-in does what it needs without modify this file, for example, everytime you add or remove dependencies. – Nacho Cougil Apr 26 '12 at 09:39