How to launch ant clean target when executing eclipse Project clean - java

In order to simplify Eclipse use for our newbie users, we want to add this features to Eclipse :
1) If the user click on Project ---->Clean... , eclipse launches also the ant clean target which is implemented in the build.xml file of the concerned project.
2) When the user saves the code, the ant build is launched automatically.
Any link or a starting point.
Thank you in advance

You can add an Ant build file to the builders for a project in project Properties > Builders. Click New... and select Ant Builder. You can then specify the build.xml and select the targets used for clean, manual build and auto build (run during save).

Related

How do I make an executable file from an intellij idea project?

I created a gradle project in Intellij idea. After building and running everything worked as expected. But I don't want to run an IDE everytime I need to use my program. Can anyone recommend a step-by- step guide?
You can quickly do it in IntelliJ following theses steps :
Go to File > Project Structure
Select Artifacts tab and click on the "+" icon
Choose to generate a JAR from modules with dependencies
Choose your module and its main class and save changes
Now go to Build > build artifacts > build*
It's done, your executable .jar file should be located in out/artifacts/module_name/module.jar
*Choose rebuild if it has already been built.

How to clean or clean build my Maven project in IntelliJ IDEA?

I'm using Apache Maven in my Java project. in NetBeans there are build and clean build icons but there aren't in IntellIJ IDEA. How can I clean or clean build my project in it?
Maven > Lifecycle > clean
Open the Maven Projects panel. Click lower-left corner for pop-up menu if that panel is not already visible.
In that panel, open the Lifecycle item. There you will find clean and install items for you to run.
As commented, you can also invoke this by command-line/console. But if already using IntelliJ, I do not see the point. Just show/hide this pane as you work. I use it countless times a day to hit install to build complete app, and hit clean whenever I suspect not all of the project is up-to-date in the build-results.
Build > Rebuild Project
If you are having weird problems in running the app in development also try the menu item Build > Rebuild Project.
I have asked what is the difference between a Build > Rebuild Project versus doing a Maven clean. But I still do not understand the precise details. So when things seem wonky, I do both to right the ship.
Tips:
Restarting IntelliJ may help when behavior seems odd.
Keep Intellij updated.
The answer here with the most votes suggests running the clean and install Lifecycle items separately in IntelliJ, which is easy enough and works. But it’s worth mentioning that you can combine these steps (and/or others) by instead creating a new Run/Debug Configuration of type maven and adding the command clean install (or whichever combination of maven lifecycle methods you run on a recurring basis).
Thereafter, running a mvn clean install is as simple as clicking the green button to run that Run/Debug Configuration.
Here is a faster way to do that:
in IntelliJ IDEA window hit Ctrl key twice, then a pop-up window appears like this:
there you can enter your command and use recommendation tools, too.
including template commands and the list of your previous ones:
In IntelliJ, go to your Toobar, View>Tools Windows>Maven Projects
From there, you can click Clean to clean the project
click on maven panel --> select project--> lifecycle --> double click clean.
source: vaadin.com
I have the same problem. I found some suggestions but nothing get me to an acceptable solution. Here are some things I found maybe it will help you:
File -> Invalidate caches / restart
or just rebuild the project: Build -> Rebuild project (Shift+F11)
But it's nothing like Clean or Clean and Build from netbeans.
By the way I use intellij-15.
Edit: Finally, Build->Build Artifacts->Build or Rebuild works for me.
So far, the best I can come up with (for a non-Maven project) would be to manually delete the target folder and then do your build. But I'm still looking for a better answer, myself.
I'm building a Maven project, and I discovered if I run the Maven Clean phase from the IntelliJ "Maven Projects" pane, it deletes the target folder. The target folder itself (without subfolders) corresponds to NetBeans' dist folder, and the subfolders in target have corresponding subfolders of the build folder in NetBeans. When you clean and build in NetBeans, the first thing that happens is the build folder and dist folder are deleted, and this corresponds to deleting the target folder in IntelliJ, so that's why I suggest it.
Note that just as you get an error if you try to clean and build in NetBeans while holding open a file that happens to be in the build or dist directory, you will similarly get an error in IntelliJ if you try to execute the Maven Clean phase while a file is open in the target folder - the difference is, if you are doing this in Windows, IntelliJ will half-way delete the folder and there isn't a simple straightforward way to clean up the mess even after you close the program that is holding the file open. Probably if you reboot it will clean up, but who wants to do that? I ended up identifying the culprit process (processes, actually - two copies of explorer.exe) with Sysinternals Process Explorer, killing all instances of explorer (killing only the two culprits didn't seem to work), then starting explorer back up via Task Manager, and everything was fine.
You can use the terminal to switch to the current project directory and use mvn clean install
If it's a Maven project:
Go to your project's root folder (where your pom.xml is located)
In address bar of windows explorer type cmd
You should be prompted with cmd window where you should type mvn clean
That will clean your target folder which is getting created after build
Make sure you have your system variables set so mvn commands can work (otherwise you will get "mvn is not recognized as an internal or external command")
This is how it should look:
Hope this helps.
As explained in Jetbrains help there are three ways to execute maven goals in IntelliJ.
One simple way to execute clean and install and also save the configuration is to select with CRTL button the goals "clean" and "install" from the maven tab -> Right click in one of the selected -> Modify Run Configuration -> check all the fields -> click OK. Then you can execute this configuration in order to clean and install.
This way works for the InteliJ IDEA 14 upwards not exceeding InteliJ IDEA 20:
Click Run -> Edit Configurations -> Press + -> Search for "Maven" -> Locate "Command Line" field and enter in following maven commands "clean install" -> Press OK.
Now click the green button to run that Run/Debug Configuration, this will maven clean install the module/project.
The output of the module if you are to deploy somewhere can be seen in the target directory in the project.
Maven Clean Install refers to clear any compiled files you have, making sure that you're really compiling each module from scratch

How to Invoke two or more ant targets from eclipse?

I use ant plugin for eclipse.
from comman line I can write
ant clean all
What analog can I use with plugin?
UPDATE
what I can click after?
You can create one of the target and specify depends property of the targets you want to execute.
Refer to below sample code
<project name="some name" default="executeMultipleTargets">
<target name="executeMultipleTargets" depends="myTarget1,target2,target3,clean" >
<echo>Build Successfull....</echo>
</target>
</project>
Ant is considered an external tool. So you do not have a run configuration but an external tool configuration for ant runs. There even exists a sub-point "Ant Builds" in that window.
It is very strange that you do not have the option run as ant build when right-clicking an ant build file. I can only assume, you do not have the appropriate plugin (although that is installed by default).
But maybe you are satisfid by just creating an external tool configuration for running ant.
You can specify multiple targets in Ant GUI: open your build.xml file and in outline view right click desired target. Then select "Run as -> Ant build..." and check all desired targets.
You can go on eclipse-> external tools configurations, select in Targets tab your preferable ant targets and be executed in order.

eclipse builds all projects even on issuing build for single project

There seems to be some issue with Eclipse VERSION 3.7
When I compile some single project ( though ant or though buildProject) , Eclipse starts building all projects in workspace and that takes a long amount of time.
I have tried building project in two ways -
right click ant file, select Run as And Build
Right Click project in Eclipse , select Build Project.
Both ways Eclipse starts building other open projects first.
is there any ways we can avoid it.
Three options I can think of:
Disable automatic building (Preferences->General->Workspace).
Change the build order to compile the project you need first (Preferences->General->Workspace->Build Order).
Close any projects you don't want built.
None of these is ideal, but they may be an improvement.
I have checked the options you have in the current Eclipse release, Indigo.
Use automatic building: See the Menu Project > Build Automatically. If that is on, Eclipse builds on its own only when there are changes to files, and it will build incrementally. I suspect that this option is off for you.
If the option is not used, you can start a build by doing Project > Build All or Project > Build Project. As the menu entries say, only the first one will build all your projects. Perhaps you are using the keybinding that starts that menu entry? CTRL-B? This will only do anything if something has changed.
When doing a clean build, there comes a popup (see below) with some options in it. If you set the right options, only the project you have selected will be cleaned and then built.
So only the options Clean projects selected below combined with Build only the selected projects will do what you want.
I do not understand why an Ant build (started in Eclipse) of one project will lead to a rebuild of all projects in the same workspace. There is no connection at all from the Ant build to the eclipse projects. The only reason I could imagine is, that the Ant build touches something, which is then dirty, and that leads to a new build. Perhaps you should add information about your build file, the directory structure you work on, ...
Shortcut Key Method
Another way is to change the shortcut key for building a project eg. Ctrl-B to only Build Project, instead of Build All.
Go to Window -> Preferences
In General -> Keys, find "Build" in the filter
There are two cases, Build All and Build Project.
Personally, I set Ctrl-B to Build Project by pressing Ctrl-B in the Binding Box
Next I set Ctrl-A Ctrl-B sequence to build all Projects
Try it out

Want an eclipse java project to run ant build files automatically

I have an Eclipse Java project, not a plugin project. And the project has some external dependencies that I handle in two separate ant files. Everything works fine, but I want to force Eclipse to run the ant files everytime it builds my project.
How can I do that?
If this had been a plugin project I would have handled it in a customBuildCallbacks.xml and included it in my build.properties, but doesnt seem to work when its just a java project
Step 1: Add the build file to your ant view
Click the add button and select the build.xml file from the project. You can also drag the build.xml file onto the ant view (To add the ant view to your perpective, go to Window > Show View > Other…)
Step 2: Run as Ant Build
In your ant view, right click the newly added build file and select Run As > Ant Build… In the dialog window, select the ‘Hide internal targets not selected for execution’ option in the Targets tab. You can rename the builder in the box at the top of the window if you wish (I usually remove the trailing ‘build.xml’. Click Apply and Close.
Step 3: Setup automatic build
Right click on the project, select Properties, then Builders. Click Import. Before closing the screen, highlight the imported build and select edit. Go to the Targets tab select clean for ‘After a clean’ and deploy.local for ‘Auto build’. Apply the changes and close.
Step 4: Enable Auto Build
Go to Project > Build Automatically
source: http://www.simonwhatley.co.uk/using-ant-with-eclipse
Go to your project properties, select "Builders", and add a new Ant Builder. You may specify which targets to run at what time (during a clean, after a clean, etc.), and which resources (if any) to refresh in Eclipse after your ant target is executed.
Project/Builders/New/Ant Builder
There you can add your custom ant build.
At least with Eclipse 4.2 (Juno), the ability to auto-build with Ant has been removed. Under the builder configuration -> "Auto Build", there is a message: "". That said you, can still work around this by:
Follow the steps above for creating your Ant builder. This will create a file in projectDirectory/.externalToolBuilders.
Modify projectDirectory/.externalToolBuilders/YourLaunchName.launch:
You'll need to add auto, to this line: <stringAttribute key="org.eclipse.ui.externaltools.ATTR_RUN_BUILD_KINDS" value="full,incremental,auto,"/>
Specify the target you want run for auto by adding: <stringAttribute key="org.eclipse.ant.ui.ATTR_ANT_AUTO_TARGETS" value="compile-jar,"/>
You can look at your Ant builder configuration and see that everything looks good:

Categories