简体   繁体   中英

Include source folder to classpath in Eclipse

Eclipse complains if I add source folder as a class folder in Java Build Path / Library.

I need this for GWT that requires sources to be in the classpath. One solution is to manually add source folders of all projects to classpath of the launch configuration, but this is not suitable for me because of specific reasons.

Another solution would be to tell Eclipse to copy all *.java files to bin folder (as it does for other resources), but I can't achieve this too.

Are you using the GWT plug-in by Google (http://code.google.com/eclipse/docs/getting_started.html). Although I have not used it, a collegue of mine did, and I am reasonably sure it handles this kind of java code in the classpath issue.

I've found the solution - to add Ant builder to all projects pointing to the following ant file:

<project name="Copy Sources" basedir="." default="copy-src">
    <target name="copy-src">
        <copy todir="bin">
            <fileset dir="src" includes="**/*.java"/>
        </copy>
    </target>
</project>

My .project files look like this:

<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
    <name>my-project1</name>
    <comment></comment>
    <projects>
    </projects>
    <buildSpec>
        <buildCommand>
            <name>org.eclipse.jdt.core.javabuilder</name>
            <arguments>
            </arguments>
        </buildCommand>
        <buildCommand>
            <name>org.eclipse.ui.externaltools.ExternalToolBuilder</name>
            <triggers>auto,full,incremental,</triggers>
            <arguments>
                <dictionary>
                    <key>LaunchConfigHandle</key>
                    <value>&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
&lt;launchConfiguration local=&quot;false&quot; path=&quot;/gwt-dev-support/Copy Sources.launch&quot;/&gt;</value>
                </dictionary>
                <dictionary>
                    <key>incclean</key>
                    <value>true</value>
                </dictionary>
            </arguments>
        </buildCommand>
    </buildSpec>
    <natures>
        <nature>org.eclipse.jdt.core.javanature</nature>
    </natures>
</projectDescription>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM