How to add JUnit to my Eclipse and how to run it? - eclipse

I want to try some tests,and have accidentally removed JUnit
My prefrences in Eclipse
I have found
http://scala-ide.org/docs/current-user-doc/testingframeworks/index.html
What is my next step?

Try "Restore Defaults", or re-install Eclipse.
Once you have re-enabled JUnit, to run a test just right-click on the class and choose "Run As" -> "JUnit Test"

Related

Run as Ant build' Missing in my eclipse

I am unable to right click and run my build.xml file by choosing 'Run as Ant' . Whenever I click it says run configuration and that goes into running Java file options .
This works for me.
Go to..
1. Help -> Install New SoftWare
Work With -> "http://download.eclipse.org/releases/juno"
Drop down list "General Purpose Tools"
select "Eclipse Plug-in Development Environment"
After doing this...eclipse started showing option of Ant Build in Run as
In Eclipse Neon, the Ant Build moved to Run > External Tools > External Tools Configurations ... it is not located in the default Run anymore.
An example of a build xml file and how to run it
I hope this helps!
I encountered a configuration where depending on the filename of build.xml file the "Run As" menu did not contain the "Ant Build" and "Ant Build..." commands. The commands "Ant Build" and "Ant Build..." (see the image in ricardoramos's answer) are present if the build file is named build.xml, but absent if the file is named build-something.xml.
I tracked down that the cause of this issue in my configuration was plugin LiClipseText. Uninstalling the plugin resolved the issue. I observed this with LiClipseText version 2.1.2 and with Eclipse versions "2018-09" (4.9), "Photon" (4.8) for Java EE Developers.
The plugin provides its own editor for XML files, and I guess that interferes with the way how Eclipse detects that an XML file is an Ant build file.
It may be that this will be fixed in a future version of LiClipseText.
For a recipe on how to uninstall the plugin - see question 6174725. For a cleanup afterwards - see question 221476.
Another possibility is your build.xml file is not parseable by ant
For example, if you open the Ant Perspective (Open Perspective | Other | ant) and then choose the Add Buildfiles toolbar button, then choose your build.xml file, if it is not a valid build file, you may see an error message "Unable to parse as an ant build file".
Once you fix your build.xml file, the Run As ant RMB command on the build.xml file will appear.
(above was my experience on Eclipse Mars.2)
Follow the below steps.
Go to Windows -> Preferences -> General -> Content Types -> Text -> XML -> Ant BuildFile.
Just click on Add button and add your AntBuild file. click ok.
Restart your Eclipse.
Follow the below steps.
Go to Windows -> Preferences -> General -> Content Types -> Text -> XML -> Ant BuildFile.
Just click on Add button and add your AntBuild file. click ok.
Workaround:
Open the ANT-View, add the build file and start it from there.
(Had the problem in JBDS8 after installing IBM Diagnostics Tools)

Run "mvn clean install" in Eclipse

Title says it all.
I want to run the console command mvn clean install on my project in question directly in Eclipse, not from the command line.
It would just be more convenient for me to do this, as I already have the project open in Eclipse. It would save me time if I would not have to navigate to the folder in Windows Explorer.
Not a big deal if I can't do this... but can I? And if so, how?
It would be great if I could just right click my project, then click "mvn clean install" from the context menu.
I use eclipse STS, so the maven plugin comes pre-installed. However, if you aren't using STS (Springsource Tool Suite), you can still install the m2Eclipse plugin. Here is the link:
http://www.eclipse.org/m2e/
Once you have this installed, you should be able to run all the maven commands. To do so, from the package explorer, you would right click on either the maven project or the pom.xml in the maven project, highlight Run As, then click Maven Install.
Hope this helped.
Run a custom maven command in Eclipse as follows:
Right-click the maven project or pom.xml
Expand Run As
Select Maven Build...
Set Goals to the command, such as: clean install -X
Note: Eclipse prefixes the command with mvn automatically.
You can create external command Run -> External Tools -> External Tools Configuration...
It will be available under Run -> External Tools and can be run using shortcuts.
Right click on pom.xml, Run As, you should see the list of m2 options if you have Maven installed, you can select Maven Clean from there
If you want to open command prompt inside your eclipse, this can be a useful approach to link cmd with eclipse.
You can follow this link to get the steps in detail with screenshots.
How to use cmd prompt inside Eclipse ?
I'm quoting the steps here:
Step 1: Setup a new External Configuration Tool
In the Eclipse tool go to Run -> External Tools -> External Tools Configurations option.
Step 2: Click New Launch Configuration option in Create, manage and run configuration screen
Step 3: New Configuration screen for configuring the command prompt
Step 4: Provide configuration details of the Command Prompt in the Main tab
Name: Give any name to your configuration (Here it is Command_Prompt)
Location: Location of the CMD.exe in your Windows
Working Directory: Any directory where you want to point the Command prompt
Step 5: Tick the check box Allocate console
This will ensure the eclipse console is being used as the command prompt for any input or output.
Step 6: Click Run and you are there!! You will land up in the C: directory as a working directory
Just found a convenient workaround:
Package Explorer > Context Menu (for specific project) > StartExplorer > Start Shell Here
This opens the cmd line for my project.
Unless someone can provide me a better answer, I will accept my own for now.

Build EAR in Eclipse Indigo

i created an EAR-Application in Eclipse Indigo and compile it via "run on server". All works well but i dont see the compile errors in the console. How can i make it visible?
Is where any way to compile an ear without having an AS running?
thx
BJ
Your code is compiled in the background, not when you invoke "run on server". To see compilation problems, you need to look in the Problems View rather than the console. If the Problems View is not visible in your current perspective, use "Window -> Show View" menu to find it.
To create a .ear file, you can use the "File -> Export -> Java EE -> EAR file" wizard.

Eclipse 3.7 runs auto build before executing ant task

My Project -> Builders list looks like this:
Ant
Android resource manager
Android pre compiler
Java builder
Android Package manager
"Build Automatically" option is turned off
If I run ant target from Ant view or as external tool then Eclipse makes this:
It builds my project (it runs all builders from the builders list)
Executes selected target
If I remove Ant from builders list it executes only selected ant target (that's what I want).
How can I make Eclipse launch only selected ant target without running other builders and without removing ant builder from the builders list?
Go to Run > External Tools > External Tool Configurations...
Choose the Ant build configuration for your project.
Click on the Build tab
Uncheck the "Build before launch" box.
Press "Apply" and "Close" buttons.
You can turn off "build before launch"
You have turned rebuild off for resource modification but I believe you have
not turned off "Build before launch"
Window>Preferences>Run/Debug>Build (if required) before launching

eclipse: auto build after save

I have an ant script that creates runnable jar and I want it to run each time I make changes in my code and save them. I guess I need some "auto build after save" option in Eclipse. Is there such a thing?
You could declare your script as a builder, and make it run "during auto build".
See the properties of your project: you can add an external program (above) or an an script (below).
If you can export your script as an ant script, like the OP David B did in his answer, it becomes quite easy:
Export as an ant script: right-click the project -> export -> runaable jar file, tick "save as ANT script" and finish.
Add the ant script as a builder: right-click the project -> properties -> Builders -> new (Ant).
Paste the path for the ant file, go to "targets" tab and click the "set targets" button next to "auto build".
Finally, click OK, OK, OK.
Actually, the best solution I found was: right-click the project -> export -> runaable jar file, tick "save as ANT script" and finish. Now right-click the project -> properties -> Builders -> new -> paste the path for the ANT file, go to "targets" tab and click the "set targets" button next to "auto build", OK, OK, OK.
Use an ANT file which will be triggered everytime you save a file: Using Ant to Auto-Build in Eclipse