2015-10-18 69 views
0

我正在與另外兩個人一起開發一個項目。我們都使用相同版本的Eclipse(Mars.1),但是我們偶爾會在我們的機器上安裝不同版本的Java庫,僅僅是因爲我們中的一個人升級了,其他人還沒有(尚未)。這是暫時的,但很明顯會導致構建問題。在沒有指定構建的類路徑中包含Java 1.8

這裏是的.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> 

正如你所看到的,行指定構建。是否有可能以特定構建不包含的方式來指定它?

回答

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上。

+0

你是如何解決構建問題的?我們使用.classpath指向像/ res這樣的文件夾(包含圖像等資源)。當進行更改時,是否必須手動讓所有「團隊」分別更新他們的類路徑?注:我意識到我們應該使用Maven或Ant或其他東西,但我的兩個合作伙伴對這些工具沒有經驗,我們沒有時間介紹它(這是一個學期的項目) – Greg

+0

@Greg我們使用Maven 。你應該嘗試一下,這很容易得到一個最小的設置。您只需將一個最小的'pom.xml'文件添加到項目的根目錄並告訴Eclipse這是一個Maven項目。選項2:轉到新建項目> Maven項目,選擇一個默認原型並導入代碼。 – ESala