How do I run the code from a scratch file in IntelliJ 14? - intellij-idea

I've created a simple Java scratch file containing a class named "TestGenerics" containing some code and a main method.
The code seems to be fine, however when I try to run it (by right clicking > Run 'TestGenerics.main()', I get this error: "Module not specified"
Similar situation occurs with a scratch file containing Lua code, error message: 'Error running scratch.1 (2): Executable is not specified'
Any ideas?

This was previously not possible, but is now supported for some languages. such as Java and Ruby. For these languages, you should be able to run the scratch file in the same way as you run any other file.

Related

After building a Kotlin program in IntelliJ, how do I execute it directly from the terminal? [duplicate]

I have installed IntelliJ IDEA on my mac and wrote the simplest Kotlin program
fun main(args : Array<String>){
println("Hello")
}
I can run it from the IDE environment. (It prints Hello of course)
My question: How can you run this from the console?
What I have done:
I tried to call
java simplekt.class
but I got
Error: could not find or load main class simplekt.class
I tried java simplekt but then I got an exception in thread main java.lang.NoClassDefFoundError
I tried to use kotlin or kotlinc but the command was not found. (where is the compiler installed?)
In this resource they use kotlinc and they produce a jar file but IDEA only output a class file.
Not really sure how to proceed from here.
When you run your application from the IDE, in the Run window the very first line is the command that the IDE executes to start your program. In my case it's something like:
/Library/Java/JavaVirtualMachines/jdk1.8.0_181.jdk/Contents/Home/bin/java -Dfile.encoding=UTF-8 <a lot more omitted>
You can execute the same command in your terminal and that will execute the application. Reading that line will also (indirectly) tell you where the kotlinc command is installed, and in my case – using MacOS – it's at /Applications/IntelliJ\ IDEA.app/Contents/plugins/Kotlin/kotlinc/bin/kotlinc
However, you can always decide to entirely stop using the IDE and compile/run your program from the command line by following instructions here: https://kotlinlang.org/docs/tutorials/command-line.html
The above answer by #user2340612 is mostly right, but maybe due to software changing or some differences in what i did, it did not work for me. Following did:
to avoid repetition, i'll be using the short name: $(ideac) = "IntelliJ IDEA Community Edition 2022.2" in place of the full name
the path to the kotlinc is this one: $(ideac)\plugins\Kotlin\kotlinc\bin
much similar to the one told above, but slightly different
i have verified it to work in the command given in the command-line doc linked above or compiler-reference too: kotlinc hello.kt -include-runtime -d hello.jar
running the resultant .jar file via java -jar ./hello.jar shows the expected output
there's no kotlin-native in that folder, so, couldn't verify this native-command-line-compiler kotlin doc
Backstory/What did not work
the command under the run tab in $(ideac) no longer shows the kotlinc path
I had created the Kotlin "project" by using "new project" (intelliJ) or by "Kotlin multiplatform > JVM" (gradle)
The run command for either of these did not contain any kotlinc in them
I tried creating a new > "scratch" file; and it showed this: $(ideac)\plugins\Kotlin\bin\windows\LLDBFrontend.exe but i tried using that on CLI and it did not work either

Running a simple hello world from the console after installing IntelliJ IDEA

I have installed IntelliJ IDEA on my mac and wrote the simplest Kotlin program
fun main(args : Array<String>){
println("Hello")
}
I can run it from the IDE environment. (It prints Hello of course)
My question: How can you run this from the console?
What I have done:
I tried to call
java simplekt.class
but I got
Error: could not find or load main class simplekt.class
I tried java simplekt but then I got an exception in thread main java.lang.NoClassDefFoundError
I tried to use kotlin or kotlinc but the command was not found. (where is the compiler installed?)
In this resource they use kotlinc and they produce a jar file but IDEA only output a class file.
Not really sure how to proceed from here.
When you run your application from the IDE, in the Run window the very first line is the command that the IDE executes to start your program. In my case it's something like:
/Library/Java/JavaVirtualMachines/jdk1.8.0_181.jdk/Contents/Home/bin/java -Dfile.encoding=UTF-8 <a lot more omitted>
You can execute the same command in your terminal and that will execute the application. Reading that line will also (indirectly) tell you where the kotlinc command is installed, and in my case – using MacOS – it's at /Applications/IntelliJ\ IDEA.app/Contents/plugins/Kotlin/kotlinc/bin/kotlinc
However, you can always decide to entirely stop using the IDE and compile/run your program from the command line by following instructions here: https://kotlinlang.org/docs/tutorials/command-line.html
The above answer by #user2340612 is mostly right, but maybe due to software changing or some differences in what i did, it did not work for me. Following did:
to avoid repetition, i'll be using the short name: $(ideac) = "IntelliJ IDEA Community Edition 2022.2" in place of the full name
the path to the kotlinc is this one: $(ideac)\plugins\Kotlin\kotlinc\bin
much similar to the one told above, but slightly different
i have verified it to work in the command given in the command-line doc linked above or compiler-reference too: kotlinc hello.kt -include-runtime -d hello.jar
running the resultant .jar file via java -jar ./hello.jar shows the expected output
there's no kotlin-native in that folder, so, couldn't verify this native-command-line-compiler kotlin doc
Backstory/What did not work
the command under the run tab in $(ideac) no longer shows the kotlinc path
I had created the Kotlin "project" by using "new project" (intelliJ) or by "Kotlin multiplatform > JVM" (gradle)
The run command for either of these did not contain any kotlinc in them
I tried creating a new > "scratch" file; and it showed this: $(ideac)\plugins\Kotlin\bin\windows\LLDBFrontend.exe but i tried using that on CLI and it did not work either

"Compilation failed but no error lines" on working java program (jGRASP)

I'm an amateur programmer. I use jGRASP.
I made a lot of functional, running, zero-error programs and copied them to a new computer. Now, when I try to run them, I get that message: "compilation failed but no error lines."
What's going on here? I'd like any help as soon as possible, I have an assignment due.
Do you have the JDK installed (not just JRE)?
What is the compiler output? Any general messages there (not related to your code, but something like a missing javac or javac crashing)?
Is the source code in the correct package structure?
Are the source files in a directory where your login account does not have write access?

Cannot auto configure pydev in eclipse

I have installed PyDev successfully, I have python 3.4.0 installed successfully and the folder containing python.exe is in my path and I can run it from the command line.
However, when I go to window\preferences\pydev\interpreters\python interpreter and select 'quick auto-config' to configure it using normal python I get an error saying 'auto configurator could not find a valid interpreter... Note the system environment variables used for Jython are PATH and PYTHONHOME.'
Unless this is a bug in the text I am not selecting Jython (I get a different error if I select IronPython, btw, so this is not a generic error message).
The trace is as follows:
Errors getting info on discovered interpreter(s).
See error log for details.
java.lang.RuntimeException: java.io.IOException: Cannot run program "python": CreateProcess error=2, The system cannot find the file specified
As I say, python.exe is in my path.
You have to install the actual python package separately from here https://www.python.org/download
Close LiClipse/Eclipse => Download Python Here: https://www.python.org/download
=> reopen LiClipse => Auto Config for the interpreter Will WORK!
I found the answer, but I'll leave this up in case anyone else gets it. It's a pretty stupid auto config option if you ask me ;)
In the higher level window\preferences\pydev\interpreters\ preference you need to untick jython and ironpython.
No idea why given I selected the Python sub-preference specifically.

File.execute() is not executing my script. How to debug this issue?

I'm writing a script for Illustrator CS6 in ExtendScript. At the end of my script, I want to spawn a task (a second script, in Ruby) using File.execute(). However, it's not working. And I'm at a loss as how to debug the problem -- how can I figure out why this isn't working?
Here's the end of my ExtendScript file:
// Do a bunch of other work, then:
var rubyFile = new File(scriptFolder + 'BuildHtmlWalkthrough.rb');
alert(rubyFile.exists);
var result = rubyFile.execute();
alert(result);
Both rubyFile.exists and result are always true, indicating that the script launched OK. But the script does not appear to run, at all. I've tried the following diagnostics:
The Ruby script does successfully run from the command line. The script's permissions are -rwxr-xr-x
I added a call to system("touch /blah/blah/blah") as the very first line of the Ruby script. The file does not get touched.
I thought maybe the ExtendScript process was terminating before the Ruby script could run, so I added a long for loop after rubyFile.execute(). Spinning for > 30 seconds did not help.
What can I do to debug, or solve, this problem?
I'm on MacOS X v10.9.1. And for reference, this is the documentation for File.execute():
File.execute (): Boolean
Core JavaScript Classes
Executes or opens
this file using the appropriate application, as if it had been
double-clicked in a file browser. You can use this method to run
scripts, launch applications, and so on. Returns true immediately if
the application launch was successful.
It's probably doing the "opens this file using the appropriate application" instead of executing, and returns true because the file successfully opens (or is already open in its associated app). If I have a python script and do
f= new File("~/Documents/misc_scripts/getpixelrgb.py");
f.execute();
, it opens it in my script editor, even if the file's execute flags are set.
I'm on OSX, btw
In After Effects, there is system.callSystem() to execute command line commands, but I'm afraid that is absent in Illustrator (I'm assuming you're doing this for Illustrator because of the tag). Are you on OSX or Windows? There are ways around this, by making an executable .app (OSX) or .exe (Win) and calling that with execute(). If I were doing this, I'm on OSX and I'd make an AppleScript app that does 'do shell script' to make the ruby system call. On Windows, it's different. One solution you might like if you're on windows: ocra, which is ruby-specific (http://ocra.rubyforge.org/). It may be possible to run a .bat file on Windows that calls the ruby script, but I'm not sure.
[edit!]
Terribly sorry for the extraneous Windows info (for someone else, I guess). Just saw your note about being on OSX. So you might want to use the AppleScript solution.
[edit again]
So, if my ruby script ("test.rb") is:
#!/usr/bin/env ruby
print "Hello"
and my AppleScript is:
do shell script "cd /testing_folder/; ruby test.rb"
Then I get "Hello" returned in AppleScript, but ExtendScript will just return true.