开发者

Eclipse "this compilation unit is not on the build path of a java project"

开发者 https://www.devze.com 2022-12-19 01:13 出处:网络
I can\'t get autocompletion to work in Eclipse. I\'m working on the project on svn. I set up the project in Eclipse by going into

I can't get autocompletion to work in Eclipse.

I'm working on the project on svn. I set up the project in Eclipse by going into

File -> Import -> Checkout As a Project -> New Project Wizard.

开发者_C百科I chose Enterprise Java Application. Everything seemed to work fine except instead of autocompletion working as I expected I got a popup dialog displaying the message

This compilation unit is not on the build path of a java project.

I've Googled it and everyone says that the project must be a Java project, but it is! What is the problem?

Update

The catalog structure on svn looks like this:

-Project_name
  -application
     -META-INF
       application.xml
       MANIFEST.MF
  +build
  +db
  +deploy
  +dist
  +lib
  +properties
  +script
  -src
     -META-INF
        someother.xml (datasource info)
        persistence.xml
        folder hierarchy with source files (should be package)
  -web
     some folders
          .
          .
     files
       .
       .
     -WEB-INF
        faces-config.xml
        jboss-web.xml
        web.xml
     build_win.xml

How do I tell Eclipse where the source files folder, application.xml, and other configuration xml files are?


When you have a multimodules maven project under a parent project, make sure you're not editing the file in the maven parent project.


What I did to make one of my projects to check out properly is by

1) Import your project from svn

      file-->import-->SVN-Checkout Projects From SVN

2) Find your Project and then in the "Check Out As" dialogue make sure you have the radio button selected "Check out as a project configured using the New Project Wizard"

3) Go through regular steps.

The wizard pulls the project properly and then setups your eclipse....

without using the wizard I find that all hell breaks loose.....

Hope this helps...


This is what was missing in my .project file:

    <projectDescription>
        ...
        <buildSpec>
            <buildCommand>
                <name>org.eclipse.jdt.core.javabuilder</name>
                <arguments>
                </arguments>
            </buildCommand>
        </buildspec>
        ...
        ...
        ...
        <natures>
            <nature>org.eclipse.jdt.core.javanature</nature>
            <nature>org.eclipse.m2e.core.maven2Nature</nature>
        </natures>
        ...
    </projectDescription>


I have this issue from time-to-time and often it's because the project wasn't marked as a java project. You can change this by going to the properties for the project > Project Facets > and selecting java. You may then need to properly configure that project, but this is probably part of the problem


I also had this problem after converting my java project into a maven project. I solved it as follows:

Right click on your project ->Project Facets -> click on Java, then Apply.


Did you have your .project file in your folders?

I got the same problem. Than i realized that I didn't have the .project file.


I might be picking up the wrong things from so many comments, but if you are using Maven, then are you doing the usual command prompt build and clean?

Go to cmd, navigate to your workspace (usually c:/workspace). Then run "mvn clean install -DskipTests"

After that run "mvn eclipse:eclipse eclipse:clean" (don't need to worry about piping).

Also, do you have any module dependencies in your projects?

If so, try removing the dependencies clicking apply, then readding the dependencies. As this can set eclipse right when it get's confused with buildpath sometimes.

Hope this helps!


I did copy the .classpath and .project from another project and adjusted the values properly.

Close the project before editing those files, when you are sure they reflect the reality (your reality anyway), re-open the project in Eclipse.

The workspace is rebuilt and all should work from then on.


in my case it's a maven project

delete the project from eclipse leaving the sources close eclipse delete from filesystem

.target/ .classpath .project .settings/ open eclipse Again Import Maven Projects

This solved the problem


You may want to try running eclipse with the -clean startup option - it tries re-building eclipse's metadata of the workspace.


mvn eclipse:eclipse

solved my problem


Here the steps for creating a source folder in eclipse.

  1. Right click on the project and go to properties
  2. Select "Java Build Path" from the properties dialog box
  3. Select the source tab and check that the source folders are correct if not click on the remove button to remove source folders, or the add button to add source folders.

You can control the order in which source folders appear in a project on order and export tab on the configure build path option.


Had the same problem (but with Maven). The reason was incorrect choice of executor: my project used global settings that are not avilable from Embedded installation of Maven. Changed it to external (Window -> Preferences -> Maven -> Installations) and that fixed the problem.


What i did is after importing the project from svn , deleted the project from workspace and imported it as a maven project from local . Then in preferences->maven->usersettings->in usersettings box gave path of settings.xml which will be in apache maven folder-> conf->settings.xml

and it solved the issue for me.


Your source files should be in a structure with a 'package' icon in the Package Explorer view (in the menu under Window > Show View > Package Explorer or press Ctrl+3 and type pack), like this:

Eclipse "this compilation unit is not on the build path of a java project"

If they are not, select the folder containing your root package (src in the image above) and select Use as Source Folder from the context menu (right click).


Like the message says, is the file somewhere on the project's Java Build Path (e.g. a Source folder)?


Had the same problem. Solution: Context menu -> Maven -> Enable dependency management

Do not know why that was lost, when checking out.


I found that I was getting this error due to having my files, including my main class, outside of the .src folder.


What worked for me was copping the .settings/ directory from another project.


Run "mvn eclipse:eclipse" from terminal.


If you're a beginner (like me), the solution may be as simple as making sure the parent folder that the file you're working in is a Java project.

I made the mistake of simply creating a Java folder, then creating a file in the folder and expecting it to work. The file needs to live in a project if you want to avoid this error.


I had same issue after importing maven project consisting of nested micro services. This is how I got it resolved in Eclipse:

  1. Right Click on Project
  2. Select Configure
  3. Select "Configure and Detect Nested Projects"


I solved this by adding projects in Java Build Path

Right click on the project -> properties -> java build path -> Add

Eclipse "this compilation unit is not on the build path of a java project"


For example if there are 4 project and a root project, add the other child projects to build path of root project. If there is not selection of build path, add below codes to .project file.

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

精彩评论

暂无评论...
验证码 换一张
取 消