简体   繁体   English

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

[英]Including Java 1.8 in classpath without specifying build

I am working on a project with two other people. 我正在与另外两个人进行一个项目。 We are all on the same version of Eclipse (Mars.1), but we occasionally have different versions of the Java library on our machines solely because one of us has upgraded and the others haven't (yet). 我们都在同一版本的Eclipse(Mars.1)上,但是有时候我们的机器上有不同版本的Java库,仅仅是因为我们中的一个已经升级,而另一个还没有升级。 This is transient, but clearly causes build problems. 这是暂时的,但显然会导致构建问题。

Here is what the .classpath looks like (NOTE: I manually inserted a line break on the line that references the JRE_CONTAINER to help you avoid scrolling the line): .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>

As you can see, the line specifies the build. 如您所见,该行指定了构建。 Is it possible to specify it in such a way that specific build is not included? 是否可以以不包括特定内部版本的方式指定它?

Yeah, that happened to us as well, the solution was to remove the .classpath file from the code repository (Git, SVN, etc) and put it in the ignored files list ( .gitignore file or whatever you use). 是的,这也发生在我们身上,解决方案是从代码存储库(Git,SVN等)中删除.classpath文件,并将其放入忽略的文件列表( .gitignore文件或您使用的任何文件)中。

Also remove the .classpath file from every developer's workspace, and Eclipse will regenerate this file specifically for your environment. 还要从每个开发人员的工作区中删除.classpath文件,Eclipse会专门为您的环境重新生成该文件。

This will avoid any further issues with different minor java versions. 这样可以避免使用其他次要Java版本的任何其他问题。

Edit : Since you mentioned you are not using any build system, here is a minimal pom.xml so that you can convert your project into a Maven project: 编辑 :由于您提到您没有使用任何构建系统,因此这里是最小的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>

Here's an Introduction to the standard directory layout and here's a guide on Specifying resource directories . 这是标准目录布局简介,也是有关指定资源目录的指南。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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