這兩天發現有個maven項目抽風了,一個是右擊項目找不到Build Path了,一個是依賴的lib庫沒了,maven引入的依賴包導不了。後來發現是eclipse搞的鬼,出問題的是項目下的.classpath文件變更了。第一個問題是.classpath沒了,而.project文件被改動了;第二個問題這個文件.classpath被改動了。java
先看這兩個文件被改動後的樣子:api
.projecteclipse
<?xml version="1.0" encoding="UTF-8"?> <projectDescription> <name>ms-navigation-api</name> <comment></comment> <projects> </projects> <buildSpec> <buildCommand> <name>org.eclipse.m2e.core.maven2Builder</name> <arguments> </arguments> </buildCommand> </buildSpec> <natures> <nature>org.eclipse.m2e.core.maven2Nature</nature> </natures> </projectDescription>
.classpathmaven
<?xml version="1.0" encoding="UTF-8"?> <classpath> <classpathentry kind="src" output="target/classes" path="src/main/resources"/> <classpathentry kind="src" output="target/classes" path="src/test/java"/> <classpathentry kind="src" output="target/classes" path="src/main/java"/> <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/jdk1.8.0_131"/> <classpathentry kind="output" path="target/classes"/> </classpath>
改動前的樣子ui
.projectspa
<?xml version="1.0" encoding="UTF-8"?> <projectDescription> <name>ms-navigation-api</name> <comment></comment> <projects> </projects> <buildSpec> <buildCommand> <name>org.eclipse.jdt.core.javabuilder</name> <arguments> </arguments> </buildCommand> <buildCommand> <name>org.eclipse.wst.common.project.facet.core.builder</name> <arguments> </arguments> </buildCommand> <buildCommand> <name>org.eclipse.m2e.core.maven2Builder</name> <arguments> </arguments> </buildCommand> <buildCommand> <name>org.eclipse.wst.validation.validationbuilder</name> <arguments> </arguments> </buildCommand> </buildSpec> <natures> <nature>org.eclipse.jem.workbench.JavaEMFNature</nature> <nature>org.eclipse.wst.common.modulecore.ModuleCoreNature</nature> <nature>org.eclipse.jdt.core.javanature</nature> <nature>org.eclipse.m2e.core.maven2Nature</nature> <nature>org.eclipse.wst.common.project.facet.core.nature</nature> <nature>org.eclipse.wst.jsdt.core.jsNature</nature> </natures> </projectDescription>
.classpath debug
<?xml version="1.0" encoding="UTF-8"?> <classpath> <classpathentry kind="src" output="target/classes" path="src/main/java"> <attributes> <attribute name="optional" value="true"/> <attribute name="maven.pomderived" value="true"/> </attributes> </classpathentry> <classpathentry excluding="**" kind="src" output="target/classes" path="src/main/resources"> <attributes> <attribute name="maven.pomderived" value="true"/> </attributes> </classpathentry> <classpathentry kind="src" output="target/test-classes" path="src/test/java"> <attributes> <attribute name="optional" value="true"/> <attribute name="maven.pomderived" value="true"/> </attributes> </classpathentry> <classpathentry kind="src" path="src/test/resources"/> <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"> <attributes> <attribute name="maven.pomderived" value="true"/> </attributes> </classpathentry> <classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER"> <attributes> <attribute name="maven.pomderived" value="true"/> <attribute name="org.eclipse.jst.component.dependency" value="/WEB-INF/lib"/> </attributes> </classpathentry> <classpathentry kind="output" path="target/classes"/> </classpath>
各個maven項目.classpath文件都是同樣的,因此這兩個問題都須要找到另外一個.classpath文件,複製到有問題的項目,而第二個問題還要作一件事:參考另外一個.project文件,把缺失的內容補上(內容都是同樣的,除了項目名)。改好後重啓Eclipse,Build Path和Maven Dependecies終於又回來了。code