Maven project not being treated as Java in Eclipse

后端 未结 14 1014
星月不相逢
星月不相逢 2021-02-05 04:30

I\'m working on a project that has lots of different Maven projects. I\'ve been doing a bunch of JUnit testing on these projects, and usually this goes well. I open up Eclipse

14条回答
  •  萌比男神i
    2021-02-05 05:10

    Several of the existing answers should work, but those suggesting to add a Java facet will only work if your project already is of (or you want to convert it to) a faceted nature, and the one suggesting you change your pom.xml will only work if you then re-import your project as a maven project.

    If you'd like to "fix" your existing project, i.e. add a Java nature without converting it to faceted form and without deleting and re-importing, just edit your .project file (externally, or with the Navigator view in eclipse, as it won't show up in your package explorer) and add the java builder and java nature to the existing maven builder/nature:

    
    
        yourprojectname
        
        
        
        
            
            
                org.eclipse.jdt.core.javabuilder
                
                
            
            
            
                org.eclipse.m2e.core.maven2Builder
                
                
            
        
        
            
            org.eclipse.jdt.core.javanature
            
            org.eclipse.m2e.core.maven2Nature
        
    
    

    Note the different capitalisation (javabuilder but maven2Builder, javanature but maven2Nature).

    As soon as you save, it should re-build automatically. You may have to manually add any source folders (Project properties -> Java Build Path -> Source tab -> Add Folder....

提交回复
热议问题