I just wanted to run quick groovy scratch file and now my Intellij is building my multi-module project because there are codegen tools and it feels like generating missing classes on each run is obligatory. But I just want to run the script, fast, that's why I used scripting language in first place!
I dont have a groovy compiler and cannot get it, so I have to use javac
And default configuration on Run is "java -Dmaven.allTheOptions etc" and I just want it to execute script when I press the hotkey
The answer is:
Run -> Edit Configurations... -> Defaults -> Groovy -> Before launch -> Press "Remove" on Build configuration
Groovy can be built to a jar file, and run that way if you just have Groovy as a dependent library. If you want to run groovy as a script, I would use sdkman to download Groovy,so you can run it without compiling:
https://sdkman.io/install
Alternatively you can download Groovy manually, and add it to your path like Java:
http://groovy-lang.org/download.html
Once you have Groovy installed, you can run groovy scripts from the command line, or ues the groovyConsole.
I don't understand why you can't download Groovy, and have to use Javac.As macg33zr mentioned Intellij does have a Groovy console built-in, although I don't remember if it requires a Groovy install, but it probably does.
Related
I use IntelliJ IDEA CE in two environments (CentOS and Ubuntu).
The two share a project via GitHub.
In CentOS, the project is regarded as Java project? with a file build.gradle.
In the other, the project is fully managed as Gradle-Java project.
When I run a main method in CentOS, IDE just runs Java (after some compiles if are required)
On the other hand, when I run the same main method in Ubuntu, IDE activates Gradle and run that.
I think this difference happens from the module structures.. which I have not tried though....
(Am I wrong?)
One question I really want to know here is,
in CentOS, when I run a code, it shows how IDE ran the code in the Run window, like...
java [too many options] foo.target.Hoge
If I copy and paste this line, I can activate foo.target.Hoge anywhere, even where I do not set CLASSPATH because [too many options] contain that.
I always do it (I am afraid if I should not though)
However, in Ubuntu (Gradle-based environment)
the windows show only
time PM: Executing task 'Hoge.main()'...
I can not copy, paste and run it...
I want to know where I can found the actual command activated.
or.... using Gradle.. are there any simpler ways?? like
gradle run Java Hoge ...
When I run a main method in CentOS, IDE just runs Java (after some compiles if are required) On the other hand, when I run the same main method in Ubuntu, IDE activates Gradle and run that.
For Gradle-based projects this behaviour is controlled in Settings (Preferences on macOS) | Build, Execution, Deployment | Build Tools | Gradle | Build and run using option. When Gradle is set IDE uses Gradle to run and build the project. When IntelliJ is set IDE uses it's own builder and Run/Debug Configurations to run.
So I have a java program, for which, I have an ant script to run. I know how to enable the debugging option in the ant script, by adding two parameters (-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=5432) to the ant's java task.
After adding those parameters to the java task in ant, I open the ant view in eclipse, right-click on the target I want to debug, and choose "debug as" -> "ant build".
Now, I need to attach this debugger to that same eclipse (which runs on the same machine), so that it will take me to the java code, and I can debug it line by line.
The two questions are: 1) how to attach that ant debugger to eclipse? and how to run it?
I found this question (How to debug Java code when using ANT script in Eclipse), but it does not explain how to attach an ant debugger to eclipse, and how to run.
I know, you may ask, why don't I just debug the java program directly on eclipse? The thing is, the program is quite large, have a lot of junit suite tests, and we use ant to run those tests. The ant was written by some other developer.
Thanks
You don't debug the ant script. You just run the ant script, even from the command line.
You then create a "Debug Configuration" in Eclipse to a "Remote Java Application", specifying the port number (5432).
I'd like to execute my Clojure tests directly from eclipse (alternative would be to run lein test from the commandline).
I already installed the CounterClockwise-Plugin for Eclipse, but there is no "Run as / Clojure test" in the context-menu. So far I added a (run-tests) to the end of my Clojure-tests files and execute the test via "Run as / Clojure Application".
Is there a better way to run tests from eclipse? In general it shouldn’t be necessary to add code to start the tests.
You can open a project REPL in Eclipse, move the REPL to the test namespace and (run-tests) from there.
I wanted to try out the new feature of JMH by running it as Java Application in eclipse. I imported and built jmh-samples project. Compiled classes ended in /jmh-samples/target/generated-sources/annotations, there are several JARs in /target/ and running microbenchmarks.jar from command line works as usual.
However when I execute main I always get
No matching benchmarks. Miss-spelled regexp?
Any ideas? I am using version 0.3
jmh-dev# is a better way to communicate this with the developers.
Few things to try:
Hijacking Main is probably not a good idea. Use Java API instead, like this sample.
Use -v extra to debug the pattern matching: either the filter regexp is incorrect, or there are no benchmarks to run.
If the regexp is incorrect, fix it.
If there are no benchmarks to match against, then there is a chance resources are not generated and/or picked up properly. Make sure target/classes/ is also available on classpath.
Okay, so looks like by default jmh looks for generated classes under META-INF/Microbenchmarks, which maven build puts under root of the project. However root of the eclipse project is not on the classpath, so executing it in IDE results in "no benchmarks found".
I got it running following way:
mvn clean package (using external maven installation, not embded
in eclipse)
Right-click on jmh-samples project, select "Build
Path -> Use as a source folder"
You can now run any of the benchmarks from jmh-samples as Java Application in eclipse
On the downside you get like 1000+ "errors" in Problems view, since eclipse gets confused with auto-generated files, but oh well, at least it works.
I was also facing the same problem, and I followed the tutorial here. That solved the issue.
Below are the steps I took:
I used the code from the tutorial AS-IS to understand how it works.
Then I just did mvn clean and install
I saw all set of classes being created in target -> annotations -> <package path> -> generated
Then I ran the BenchmarkRunner main() class and this worked.
This might be something very simple but I cannot seem to get it right. I have a Spring MVC 3.0 application and I would like to use some groovy code.
Problem
When I add Groovy code (Groovy Classes) and I start defining my variables the IDE (SpringSource Tool Suite in my case) tells me "def cannot be resolved to a type"
What I have done
Created a source folder named src/main/groovy
Created a .groovy Class added a method with def msg = 'Hello'
Added Groovy libraries to Classpath
Did a Project/Clean through the IDE
The IDE (STS) still tells me "def cannot be resolved to a type"
If I create a simple Groovy Project I can interchange groovy/java with no problem but now that I am adding Groovy to something that I already had it does not seem to be picking up that I am trying to do groovy in those groovy files. I have Groovy on the classpath, Groovy nature and everything. Not sure what else to do so that STS stops flagging my groovy code as errors.
Thanks.
You have to install a Groovy Eclipse plugin.
Open you Dashboard, click on "Extensions" tab (of the Dashboard), check the "Groovy Eclipse" option:
and click install.
Once it is installed, it'll ask you to restart Spring Tool Suite => do it.
Then right click on your project => "Configure" => "Convert to Groovy Project"
Ensure you have Groovy installed (yum, aptitude, etc).
Right click your project.
Select "Groovy" -> "Add Groovy libraries to classpath"
The project should automatically rebuild and the problem is resolved.