I have a Go program which I'm working on in IntelliJ IDEA on a Windows machine. The program's structure is a little unconventional (don't want to go into detail here as its besides the point) because of which I first have to compile the program using the following command:
go build -o cli.exe
And then I can run cli.exe directly in the command prompt.
But how do I configure the run configuration in IntelliJ IDEA so that it doesn't mind running a Windows executable ? Because if I try to tell it to run an EXE file as it's run configuration, it gives me error "Main file is invalid"
How do I solve this ?
Make sure you have a file name (not a folder name) in field File on Run/Debug Configuration window (In IntelliJ IDEA go to menu Run->Edit Configuration...->your_configuration). That was my case.
You may be able to install the Bash plugin on Windows, then create a run configuration using the Bash plugin, and just run your executable from a script.
Create a Go Application run configuration and that should work. You can choose to run either a file or a package. If you would share more details then the answer would be more complete. If you still have an issue with this, please open an issue to the bug tracker and I'll be able to help out (please follow the issue template there).
Related
I recently downloaded the latest version of IntelliJ Ultimate (at this time, it is 2017.1.4) for work.
For some reason, I cannot get it to open a new terminal window. When clicking the plus button here:
...nothing happens. Additionally, nothing shows up in the event log. I restarted IntelliJ, my computer, and did the "invalidate caches and restart" option.
Any ideas? Is there a log file I can look at?
It could be a known issue that is already fixed in 2017.2.
Another possible case is that the native terminal library fails to initialize on your system (check idea.log for exceptions). This can be caused by an antivirus or a corrupted IDE installation.
Thanks to #CrazyCoder for reminding me to check idea.log - the native terminal library, as well as other plugins, failed to initialize.
The root cause of the issue is that at my workplace, there is a security restriction to not run any executable that exists outside of C:\Program Files. As a result, IntelliJ cannot run certain plugins, jars, etc. that exist outside of that location, because it will attempt to execute them from your user directory.
To fix this, in IntelliJ, go to Help > Edit Custom Properties and point the config and system path to a known path where you can run executables, like so:
# custom IntelliJ IDEA properties
idea.config.path=C:\\Program Files\\JetBrains\\.IntelliJIdea2017.2\\config
idea.system.path=C:\\Program Files\\JetBrains\\.IntelliJIdea2017.2\\system
You will need to make sure to copy the contents of both directories to the new location. Hopefully this helps anyone else who runs into this issue.
Just installed version 2016.2.5 of the Community edition of IntelliJ and then installed the Go plugin from:
https://plugins.jetbrains.com/plugin/5047
I followed the wizard for creating a new project but when I come to run a simple hello.go file I get a "Main file is invalid" in the "Run Configurations" dialog.
Does anyone know of a step by step guide to setting up and running the simplest of Go projects?
I've tried GoClipse and now IntelliJ and for both the user documentation is absoluetly crap. It's always the same: they spend ages developing this stuff and proide zero useful documentation!
Thanks
Graham
I use the plugin with WebStorm, and it is quite an improvement over previous Go IDE attempts.
The issue you run into is quite simple. The auto-generated code does not have the package set to main. For that reason, the main file is invalid. You need to manually set the package to main, and add a function called main.
My steps to ensure a working Go development environment and set up a new project are:
Install Go
Set GOROOT environment variable to Go installation, e.g. /usr/local/go
Create a go directory in your home folder, and set GOPATH to it.
Install IntelliJ + plugin
Create a new Go project in a subfolder of $GOPATH/src
Set the Go SDK in IntelliJ
Create a main .go file and make sure package name is main, and a main function exists.
Now you can create a proper Run configuration.
For me, this works quite well, including debugging and running unit tests.
I'm using IntelliJ with the go plugin to write my application.
version of Go: go version go1.7beta2 darwin/amd64
Operation system: OSX El Capitan 10.11.5
Intellij Version: 2016.1.3
Go Installation Location: /usr/local/go
Go Pkg Location ($GOPATH): /Users/ufk/projects/go
when I open terminal, browse to my application's main source file, and type go it compiles it properly without any errors.
but when I try to Run the program using Intellij, which also compiles it, i get the following error:
/usr/local/go/pkg/tool/darwin_amd64/link: cannot open file /usr/local/go/pkg/darwin_amd64/github.com/codegangsta/negroni.a: open /usr/local/go/pkg/darwin_amd64/github.com/codegangsta/negroni.a: no such file or directory
lookgs like it's looking for the negroni package in the location when I have go installed, and not where I the 3rd party packages are installed according to $GOPATH. My project is configured to use $GOPATH, and the real time error of the intellj editor doesn't complain about packages that are not installed which means that Intellij does check the $GOPATH variable.
so what am i missing ?
thanks
update
Hi :)
I noticed something new... I have 2 go projects, one of them is the JSON Api Server, and the other is for the web server.
The project that is causing issues is the Api Server.
now, the web server also uses and imports negroni, but the problem occurs only on the Api Server Project.
so I decided to go wild and delete the .idea and iml file from the Api Server, reopen it with intellij, and see what happens... welp, what happens is that now it complains about a different module.
/usr/local/go/pkg/tool/darwin_amd64/link: cannot open file /usr/local/go/pkg/darwin_amd64/github.com/jingweno/negroni-gorelic.a: open /usr/local/go/pkg/darwin_amd64/github.com/jingweno/negroni-gorelic.a: no such file or directory
the thing is.. that my web server project also uses negroni-gorelic and things are fine!
I tried downgrading go from 1.7beta2 to 1.6.2, deleting the content of the modules ($GOPATH/pkg and in src directory github.com and golang.org)
then I got all the modules again.. tried to compile with intellij and the results are the same.
so... hope this helps to further investigate the issue.
I have started to learn Go and I have installed Go plugin on IntelliJ I have compiled and run sucessful some really simple code pieces. However I don't find any bin file in the bin folder, and the compiler runs this command to execute the app
C:/Go/bin/go.exe run E:/IntelliJ/untitled/src/myApp.go
How to get the binary of my compiled code?
You need to use go build, go run simply creates a temporary file somewhere and executes it then deletes it.
You simply need to specify output dir in your run/debug configuration like
E:\IntelliJ\untitled\.idea\output
I am trying to diagnose an issue I am having with IntelliJ 10.0.2 not being able to launch a run configuration due to an (potentially) excessively long command line. It is an 'OSGI Bundles' configuration using the Equinox Framework.
I would like to be able to get the command line that Idea is trying to execute so I can diagnose the issue but I'm not sure how to.
The 'run' tool window does not open but a tooltip appears above the 'run' tool window tab stating that the command line is too long and that this could potentially be solved by enabling a classpath file. However 'dynamic.classpath' has already been enabled and is working (I can run my unit tests only with this set to true).
Any thoughts? Thanks
I don't use a CLASSPATH in the command used to launch an app in IntelliJ. I add all the JARs I need as libraries when I configure the module. If those are making your run command unnecessarily long, perhaps using IntelliJ as it is intended will sort you out.