I'm new to both Eclipse and Groovy.
In Eclipse, I set up a new project. I added a new Groovy script that looks like this
println "Hello jerkface!
I can hit the "play" button, it asks me if I want to run as a Groovy Console, Groovy Script, or Java Application. I choose "Groovy Script" and it works. Hooray!
Now I want to create a new test case, so I create a new Groovy test, and I edit it so that it looks like this:
import groovy.util.GroovyTestCase
class DegenerateTestCase extends GroovyTestCase {
void testAlwaysTrue() {
assert true
}
}
If I try to run that file, Eclipse says "Did not find runnable type for Groovy Shell in selection". I'm not quite sure what that means. Is it because there is no main() method?
The funny thing is, if I try to run that test file from the command line using groovy or groovysh, it works just fine.
Any ideas what I have to do to run Groovy test scripts within Eclipse?
P.S. I have installed the Groovy Development Tools 4.5.0 into Eclipse.
So it seems that Eclipse is trying (and failing!) to be helpful, and complaining that this file won't actually do anything. So either of these solutions will get rid of the problem
Add a static void main(args) {} to the test class. Then you can run the class (it won't do anything...but at least it will not give you that error.
Add a command outside the class definition (e.g. println "hello world"). That's avoiding the pop-up error for me, but leading to another complaint about JUnit not being found...but that's a separate issue.
UPDATE: I think I'm getting closer.
As noted in the comments, adding either the static void main() definition or adding something outside the class definition will get rid of the "Did not find runnable type" message, but will not cause the tests to run.
I think I see two things going on. (But I'm still new at this and might be mistaken.)
When using the "new file" wizard in Eclipse, Eclipse remembers the type of file that you picked (Groovy Type or Groovy Test). That influences how Eclipse will run the file.
It seems like using the run buttons in the toolbar is a better choice than right-clicking the file name in the package explorer and choosing "run as". Those buttons seem to use the information from the file creation step to run things correctly. (That seems to be called a Launch Configuration, and I'll have to figure out what that does.)
Related
I have several scala object in my project, sometimes I would like to run one single object whch has no dependency on any other object in the file (just want to see how it would behave before merging it into the whole project), but every time I click on "Run 'XXX'" (where xxx is the name of the object I would like to run, "hello world" for example), intellij tried to build the whole project, actually I just wanted to build and run the single scala object, like "helloword.scala".
I searched a lot and mostly the questions are about Java, if someone wants to run single Java class, then he can right click in the editor zone, then choose the "Run xxx.main()", but in my case ,I just can find the "Run xxx",
someone said that cancel 'make' in run/debug configuration, but how and I didn't find 'make' button in the configuration.
so, anybody have an idea how to compile/build/run just one single scala object/file at one time in intellij?
BTW I am using the intellij idea 2019.1 and the project is based on maven.
Try removing Build action from Before launch section of the corresponding Run/Debug Configuration like so
Edit the Run/Debug Configuration for the Application configuration type
Go to Before launch section
Remove Build action by clicking on the minus - button
You can test this out by creating two apps
// Run.scala file
object Run extends App {
println("woohoo")
}
and
// RunBroken.scala file
obct RunBroken extends App {
ptln("boom")
}
Create run configuration for Run.scala by following above instructions, and it should run despite there being a syntax error in RunBroken.scala.
You can create a Scratch File.
Simply search for Scratch file in the actions search
And search for Scala in the languages dialog: (I'm using Java as an example, since I don't use Scala.)
This will create a new scratch which is accessible under Scratches and Consoles -> Scratches in the Project view.
As you can see here, there are Syntax Errors in a Project file
and yet, the Scratch file will compile and run:
In IntelliJ/Scala plugin, how can I run the Scala test code?
class TestFile extends FunSuite with BeforeAndAfter {
test ("simple") {
I'm not sure exactly what happened, but I remember IntelliJ/Scala plugin automatically showed me a "run" menu with the right click, but I see nothing about the run menu. Is there any setup change to teach this file is Scala test file that can be executed?
Find the directory where all your tests are (if you are using Maven directory structure that would be src/test/scala) right click on it and choose "Mark directory as"-> "Test Sources Root". This would tell IntelliJ that the directory contains test and would make it offer to run tests in the right click menu of files
Right click on the source (especially on test class name or test name) opens up a menu that shows the run menu.
I configured everthing within eclipse for scala. I create a snippet to show you the issue, i can't see in run options run as scala application, i also tried to find my main class under build configuration option but i can't find it.
How i can solve it?
to run as scala application, you need to create Scala App and not class
In eclipse, package explorer
select project/src/package
right click
new>scala app
inform Name e.g. Test and click "finish"
select Test.scala
right click
"run as Scala Application"
see results in console window.
Replace class with object.
You can even have it extend Application so it can look like:
object afaf extends Application {
println("Done.")
}
I'm developing a Scala application using IntelliJ Idea 12, sbt and sbt-idea plugin. I generated all necessary files by saying "gen-idea" and everything goes well -- I was able to compile the sources in command line in sbt as well in IntelliJ Idea 12 itself using menu Build->Make Project.
Here is my main class (Application.scala)
object Application extends App {
val a = 12345
println("application entry point 1235")
}
I have a breakpoint at val a = 12345.
1) There were other errors before, but now says "Module is not specified". How do I solve this?
I'll be posting updates since there would be other errors as my gut tells me.
To debug just like to run, you need to create a run configuration (menu Run -> Edit Configurations). If you haven't done yet, you need to add an Application entry with the + button.
Not only do you need to specify the main class, but also which "module" that class belongs to. By default, "Use classpath of module" will be empty. Here in the popup menu, you need to select the main module (not the one ending in "-build"). After you choose that and close with "Ok", it should work.
Although not necessary, I also recommend to use sbt for building instead of "Make". In the configuration in the "Before launch" part, select "Make" and click on "-", then click on "+" and choose sbt -> test:products.
Edit: Here is the reference for the SBT plugin for IntelliJ.
While I have plenty of experience with Eclipse, I am very new to Vaadin. I'm having a simple issue when running my project. By default the project runs as...
http://localhost:8080/Sample_App/WEB-INF/classes/com/example/sample/Sample_Application.java
...which throws a 404 error, forcing me to manually adjust it every time I run. Instead I obviously want it to run as...
http://localhost:8080/Sample_App
How do I go about adjusting this? (I tried the proposed solution here which isn't working for me)
Almost stupid how simple the answer was.
When running the project, instead of highlighting the class file in the Project Explorer, highlight the very base of the project before running. This is what we want to run anyway, not the class file itself.