我將 MacOS Mojave 與 IntelliJ Ultimate 2018.2 結(jié)合使用。我寫了一個(gè) go 應(yīng)用程序,它從我的項(xiàng)目目錄加載一個(gè)配置文件。我創(chuàng)建了一個(gè)InitConfig()函數(shù)來將 JSON 文件加載到結(jié)構(gòu)中。Config.go這是我文件的代碼package mainimport ( "github.com/tkanos/gonfig" "log")type Configuration struct { WebServerPort int DbName string DbUser string DbPassword string DbPort int CertFile string KeyFile string EnableHttps bool}var AppConfiguration Configurationfunc InitConfig() { AppConfiguration = Configuration{} err := gonfig.GetConf(ExPath + "/config/config.json", &AppConfiguration) if err != nil { log.Fatalf("could not parse configuration file: %v",err) }}我使用一個(gè)名為的變量ExPath,其中包含正在運(yùn)行的二進(jìn)制文件的當(dāng)前目錄,我使用以下代碼 (Path.go) 創(chuàng)建了它:package mainimport ( "log" "os" "path/filepath")var ExPath stringfunc InitPath() { ex, err := os.Executable() if err != nil { log.Fatalf("could not get executable path: %v",err) } ExPath = filepath.Dir(ex)}當(dāng)我嘗試運(yùn)行或調(diào)試應(yīng)用程序時(shí),intellij 正在創(chuàng)建一個(gè)編譯和運(yùn)行應(yīng)用程序的目錄,我如何告訴它也復(fù)制 json 文件?當(dāng)我嘗試運(yùn)行/調(diào)試我的應(yīng)用程序時(shí),我得到:could not parse configuration file: open /private/var/folders/60/qzt2pgs173s4j_r6lby_mw1c0000gn/T/config/config.json: no such file or directory我檢查了一下,那個(gè)目錄確實(shí)不包含我的配置目錄。所以..有沒有辦法讓intellij知道它應(yīng)該在執(zhí)行我的項(xiàng)目之前復(fù)制它?
1 回答

繁星點(diǎn)點(diǎn)滴滴
TA貢獻(xiàn)1803條經(jīng)驗(yàn) 獲得超3個(gè)贊
看起來解決方案很簡單。我所需要的只是將我的運(yùn)行/調(diào)試配置的“輸出目錄”設(shè)置為我的項(xiàng)目目錄。然后 intellij 在同一目錄中執(zhí)行該文件,它可以找到/config/config.json
.
- 1 回答
- 0 關(guān)注
- 111 瀏覽
添加回答
舉報(bào)
0/150
提交
取消