2016-07-14 51 views
0

我在Windows上使用Scala-IDE,我的項目文件處於流浪狀態。我使用vagrant建立項目sbt並運行服務器進行測試。爲了部署,我創建了具有sbt eclipse的eclipse配置文件並導入到Scala-IDE中。我的問題是,當我嘗試運行項目時,無法訪問我的.ivy2文件,因爲它們位於流浪家庭文件夾中。我怎麼解決這個問題 ?如何從Windows訪問vagrant .ivy2目錄?

Description Resource Path Location Type Project 'test-api' is missing required library: '\home\vagrant\.ivy2\cache\com.google.guava\guava\bundles\guava-18.0.jar' test-api Build path Build Path Problem 

回答

0

我解決了我的問題。 sbt eclipse命令爲Eclipse創建兩個文件。他們是.classpath.project。您的.ivy2路徑在.classpath文件中給出。所以首先,我在我的vagrant目錄中創建了一個新文件夾,並將我的主文件夾同步到這個新文件夾中。將此添加到您的Vagrantfile

config.vm.synced_folder "data", "/home/vagrant" 

然後我在我的項目文件夾中運行sbt eclipse。它在我的data文件夾中創建了新的.classpath文件。我寫了一個python腳本,它可以讀取和替換.classpath文件中的路徑。您應該在您的項目文件夾中運行此腳本,它會獲取所有子目錄並搜索.classpath文件。然後它用正確的路徑替換錯誤的路徑。

import os 
    import glob 

    #variables 
    current_dir = "/home/vagrant/" 
    dest_dir = "C:/Users/Test/Desktop/vm/data/" 

    #list for directories 
    filesDepth1 = glob.glob('*/') 
    dirsDepth1 = list(filter(lambda f: os.path.isdir(f), filesDepth1)) 
    print(dirsDepth1) 

    #list for files 
    for directory in dirsDepth1: 
      print(directory) 
      root = os.path.dirname(os.path.realpath(__file__)) + "/" + directory 
      for item in os.listdir(root): 
        if os.path.isfile(os.path.join(root, item)): 
          print(item) 
          if(item == ".classpath"): 
            FileName = root + "/" + item 
            with open(FileName) as f: 
              newText=f.read().replace(current_dir,dest_dir) 
            with open(FileName, "w") as f: 
              f.write(newText)