Search code examples
javaeclipseperspective

Eclipse: Force project to be Java?


Is it possible to force an already existing project to be a "java" project? For example, I have imported an existing maven project that does not have any associated eclipse files, but the project is not associated with "java". It is hard to explain because I dont know the eclipse specific terminology. The problem I am having is that I am unable to 'src' directory as part of the build path because eclipse doesnt know that the project is a java project. In turn, I have to expand each directory of the namespace to get to the java files. The project is also not associated with any java sdk or libraries, etc.


Solution

  • Check your .project file. (This is a hidden file in your project's root directory)

        <?xml version="1.0" encoding="UTF-8"?>
        <projectDescription>
        <name>myProject</name>
        <comment></comment>
        <projects>
        </projects>
        <buildSpec>
            <buildCommand>
                <name>org.eclipse.jdt.core.javabuilder</name>
                <arguments>
                </arguments>
            </buildCommand>
        </buildSpec>
        <natures>
            <nature>org.eclipse.jdt.core.javanature</nature>
        </natures>
    </projectDescription> 
    

    You want to make sure that your project has the java "nature", and set eclipse to build the project with the javabuilder (and not the maven builder, for example). Note that this will simply make eclipse see the project as a java project, if you want it working with maven as well, I'll need some more information.

    For what its worth, I typically don't run maven builds from w/in eclipse, i switch over to the command line. My reasons for doing so are that I prefer my command line's aesthetics over eclipse' and I've had some headaches in the past with eclipse and maven projects (though I'm not blaming eclipse, I'm certain I was at fault).

    Recently, Spring Source Tool Suite (an eclipse offering from the spring guys) has had my maven projects working in eclipse without much hassle.