Maven build on save - eclipse

I just jumped into a webapplication that uses Maven. It's a project that's been around for some months now and a lot have people worked on it and left. So it's a mess and there hasn't been a lot of documenting around it.
So I've been trying to find my way around the project and something I've been running into is that I have to build 2 folders, move a file into the server folder to see the changes I've made. This is a slow and tedious process, so I'm trying to speed it up.
We are all using the Eclipse IDE and after I've done changes in the code I have to right click a the rootfolder > run as > maven build > goals: clean install. This I have to do for two folders.
Then I have to close Wildfly (the server app for the project) and move a .ear file from folder a to b and restard Wildfly to see my changes. As you can see this takes quite some actions so I'm looking for a method to automate this.
Is it possible to configure this in Eclipse or should I look into creating a .bat file that a user can run that performs the actions stated above?

Eclipse by default should build each class file as you edit it.
I would suggest running Wildfly within Eclipse. Take a look at JBoss tools for some better integration in this area. Once you have it configured to run within Eclipse then it should auto reload the files as you edit them - no need to even restart Wildfly.

I've created a batch file:
rem run a maven clean install
cd C:\Users\A647450\workspace\****\*****
call mvn clean install
rem run a maven clean install
cd C:\Users\A647450\workspace\*****\****
call mvn clean install
rem copy created EAR file to Wildfly folder
copy C:\Users\A647450\workspace\****\****\target\****-1.2.1-SNAPSHOT.ear C:\wildfly-10.1.0.Final\standalone\deployments\****-1.2.1-SNAPSHOT.ear /y
This does get the job done, but takes a while.

Related

Force the use of an alternate POM file in eclipse

In my maven project I usually use the POM file named pom.xml. I have a second POM file though (call it pom_alt.xml), which I occasionally use to perform a very different build of the same project. To do so I specify the -f option in the command line
mvn clean package -fpom_alt.xml
as suggested by man mvn:
-f,--file
Force the use of an alternate POM file.
Now, when I am coding in eclipse I usually need maven to use pom.xml, but sometimes I should code or debug while the other file pom_alt.xml is used instead. Is there a way to tell the eclipse maven integration to use that file? Currently I am temporarily copy-pasting from pom_alt.xml to pom.xml since I seldom happen to need that, but you can see that's not optimal.
I am with Eclipse IDE for Java EE Developers, Mars Release 4.5.0.
UPDATE
I could build from the command line or use Run As Maven build as in
Carlos Andres' solution, but ideally I would like to define a persistent setting, like a property or preference. This because I find nice if the POM file can be fixed while I am doing things like running as Java Application and test cases, or executing on a server. Processes that require a project clean or server restart are often triggering a maven build with the default POM.
Check that M2E - Maven Integration for Eclipse is installed on Eclipse. Once that is installed go to the project and press right click
Next, put the command that you want to execute
This option allow you to save the commands, and the next time all your commands will be saved.
To execute the command recorded go to

Best method to export the Eclipse project as exe file

I have a selenium project in eclipse that i want to distribute to manual testers with no Eclipse or Java knowledge. Hence i am looking to distribute it to them as executable files so that they dont need to use eclipse to run them. Can any one suggest the best way to do this without having to install any 3rd party extensions?
P.S : My organisation doesnt allow me to install 3rd party extensions on Eclipse. It will require a lot of approvals. Hence i am wondering if there is any method available inside Eclipse itself?
I've done it some years ago, in my eclipse version:
file -> export -> java -> Runnable jar file
If you want an exe file you can use: Launch4J
Export your project as jar file and create a .bat file which will include all the necessary libraries in your classpath with your project and then make a call to the underlying script (in case if you are using testng then testng has option to make command line calls)
else use Maven
EDIT:
Something on below lines:
1. Create run.bat file
2. Content of the bat file:
JAVA_HOME={Path to your JDK}
CLASSPATH=%PATH%;{All the dependent jar files of your project as well as you project}
{Call to your Junit Script from command line} Something like this Run JUnit from command line
3. Run your batch file (run.bat)
I may not have provided the exact code but thats where you should be heading if you wish to run your JUnit tests from command line.
NOTE / FYI : Maven does not require any installation or approval..You just download the zip and unzip it and set environment variable and thats it.

Deploying a new version of WAR onto tomcat on eclipse

So I'm having this issue with eclipse and tomcat 6.
I am able to upload the first version of my war on eclipse using server(tomcat 6)->add resource, add all.
But then I tried editing some lines, and then run as maven clean->run as maven install, then clean, clean tomcat work directory, and restart the server, and it would not show me the reflected changes.
Any suggestions?
You clean your application, and executing an install, but seems you're not executing the build correctly. Ensure you're generating a new war file (take a look at the date of when it is generated to make sure you're deploying the last version). If your project has many modules, e.g: war and jars. Make sure you build the jars as well, and the jars are being replaced in the tomcat/libs folder or in your WEB-INF/libs, check the date of when are the depending jars generated too, then you can see the differences.
Best regards.

Force Eclipse to clean a project automatically before every run

I'm looking for a solution that will force Eclipse to automatically clean a project before I run it (I'm talking about running a project using just Eclipse- no Maven, no Ant). For building I already have a Maven configuration, but sometimes I run the build directly from Eclipse as well and this is when I need that cleaning.
Shouldn't it be possible to have Maven and Eclipse use different class folders, e.g. /target for the Maven build and /bin for the Eclipse internal Java compiler? If so, you should be able to have 2 different launch configurations running the code from 2 different locations.
Second alternative: You can create a small Ant script to clear the target directory. That Ant script can be run from inside Eclipse, so a workaround is running the Ant launch configuration first and your Java launch configuration afterwards. To make this a one-step process, please install the launch groups feature from Eclipse CDT (you only need that small feature, not the whole CDT!), then you can create a "batch" like launch configuration from the other two launch configurations. Now everything is inside Eclipse with a single launch configuration!

finding what commands are executed by eclipse

I have a project in eclipse right now that is compiled using ant. I am wondering what eclipse is doing behind the curtains whenever I double click on the jar target of one of this build files.
Is it possible to get the commands that eclipse is executing with ant, as I'd like to setup a shell script that compiles the project. How can I find what commands it is actually executing and what parameters it is passing.
I imagine there are also some variables like classpath, and buildpath that are set, where do I find them as to be easily copied over.
Eclipse comes with its own installation of ant. Is it possible to use that bundled installation of ant to build via command line.
Any help appreciated,
Ted.
One possible way is to look at the process executed by Eclipse when building.
For that, use Process Explorer (if you are on Windows) in order to display the full command line and all its parameter when running that build.