在类路径中包含Java 1.8而不指定构建

时间:2015-10-18 22:25:37

标签: java eclipse classpath

我正和另外两个人一起开展一个项目。我们都在相同版本的Eclipse(Mars.1)上,但我们偶尔会在我们的机器上拥有不同版本的Java库,因为我们其中一个已升级而其他人尚未升级。这是暂时的,但显然会导致构建问题。

这是.classpath的样子(注意:我在引用JRE_CONTAINER的行上手动插入换行符以帮助您避免滚动行):

<?xml version="1.0" encoding="UTF-8"?>
<classpath>
    <classpathentry kind="src" path="src"/>
    <classpathentry kind="src" path="res"/>
    <classpathentry exported="true" kind="lib" path="lib/swingx-all-1.6.4.jar"/>
    <classpathentry exported="true" kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/
        org.eclipse.jdt.internal.launching.macosx.MacOSXType/Java SE 8 [1.8.0_25]">
            <attributes>
                <attribute name="owner.project.facets" value="java"/>
            </attributes>
        </classpathentry>
        <classpathentry kind="output" path="build/classes"/>
    </classpath>

如您所见,该行指定了构建。是否可以以不包含特定构建的方式指定它?

1 个答案:

答案 0 :(得分:2)

是的,这也发生在我们身上,解决方法是从代码库(Git,SVN等)中删除.classpath文件并将其放入忽略的文件列表(.gitignore文件中或者你用的任何东西)。

同时从每个开发人员的工作区中删除.classpath文件,Eclipse将专门为您的环境重新生成此文件。

这将避免使用不同的次要Java版本的任何进一步问题。

编辑:由于您提到您没有使用任何构建系统,因此这是一个最小pom.xml,以便您可以将项目转换为Maven项目:

<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>your-organization</groupId>
    <artifactId>your-project-or-module-name</artifactId>
    <version>1.0.0</version>
    <packaging>jar</packaging>

    <name>NameOfTheProject</name>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <java.version>1.8</java.version>
    </properties>

    <dependencies>

        <!-- Reference your libraries here -->
        <!-- Maven will download them automatically :O -->

        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.12</version>
            <scope>test</scope>
        </dependency>

    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.1</version>
                <configuration>
                    <source>${java.version}</source>
                    <target>${java.version}</target>
                </configuration>
            </plugin>
        </plugins>
    </build>

</project>

以下是Introduction to the standard directory layout,此处是Specifying resource directories的指南。