Want an eclipse java project to run ant build files automatically - java

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:

Related

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 launch ant clean target when executing eclipse Project clean

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).

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

How to achieve that Eclipse clean and build (aka rebuild)?

I deleted my ./bin folder in an Eclipse Indigo (super similar to Helios), and now I am wondering how to rebuild my Java project. I just cannot find a button like we can see in Netbeans.
For Eclipse you can find the rebuild option under Project > Clean and then select the project you want to clean up... that's all.
This will build your project and create a new bin folder.
In Eclipse there is an "Auto Build" option, which is checked by default. When it is checked, you don't need to build your project, this happens automatically. If this behaviour is unwanted, uncheck this option and click build project whenever you want.
To clean a project, select Clean Project. This will delete the bin folder, however if Auto build is checked, it will be immediatelly regenerated.
In case you are unable to find a file in Eclipse code after pulling code from git or creating a file in intelliJ seperately (my case) you ca do the following
Right click on 'src' folder and in the menu that appear click on the 'refresh' button

How do I configure eclipse to automatically refresh a project as part of it's build?

I have a maven plugin generating some code for eclipse to build, but I have to manually refresh the project before eclipse sees the code.
How can I make eclipse automatically refresh the project as part of the build?
I'm trying to use a custom builder, but it wants to run a command (which I don't need to do).
You can make eclipse automatically refresh your whole workspace:
Window->Preferences->General->Workspace and check "Refresh automatically"
you can make it project/build specific for external builders under Project Properties->Build->Refresh Policy. Here is an example for C/C++ builds.
Depending on how you run your Maven plugin, it may just refresh the project automatically. That is how it normally works in m2eclipse.
Also, you can configure a custom builder Project Properties / Builders / New... / Program and select some dummy command to run (e.g. C:\cygwin\bin\date.exe) and then configure project refresh settings.

Categories