Load, compile and run Eclipse project with a bash file - eclipse

Given an hypothetical Eclipse project located in :
C:\user\john.doe\workspace\myProject
Is it possible with a simple bash script (or else) to:
Open Eclipse
Compile the project
Run the project
Possibly do this for multiple projects at the same time
with a simple click?
I'm working on an application and I currently have several modules all with their own suit of unit tests in a separate project. I would like to make it as effortless as possible to run every single test benches when changes are made by me and others so the code doesn't rot because it takes too much time to run the 10+ test projects.
I'm using Eclipse Kepler on Windows 7 for C projects.

Related

Do I need 10 step process to make jar file in Eclipse? [duplicate]

This question already has answers here:
Build project into a JAR automatically in Eclipse
(7 answers)
Closed 7 years ago.
I sincerely hope the answer to my question will be no.
I just wanted to quickly test a hypothesis on a simple java program (4 lines). I already tested that with C++ in Visual Studio where the experiment took 5 minutes.
Eclipse is different. First, I was unable to find where did it save my project - unlike NetBeans or Visual Studio, it doesn't provide Open in file browser option.
Afterwards I had to google up "create jar file eclipse" since Project -> build does not seem to produce a jar file, or anything else for that matter. The article I found is correct and works. But it has 10 steps and actually doing the thing takes long time because you have to specify the main class every time.
Is that normal? I make simple test programs quite often, this is definitely gonna slow me down a lot.
To clarify the question: How to quickly create a project and produce a jar file in Eclipse? (time limit 180 seconds)
You can always right click a project in Eclipse and pick the option "Export", which will lead you to create a jar/Runnable jar file. Another option would be to transform your projects into Maven Projects and then run maven install with the target packaging set to jar. Another way would be to directly compile your code using the javac : http://www.skylit.com/javamethods/faqs/createjar.html
Since you are testing small stuff, you have a lot of options which may fit you, and the answer is not bound to an IDE (Eclipse) for example
You don't have to produce a JAR to test a program in Eclipse. You can right-click on any class, package, or project that includes an appropriate main(String[]) method, and select Run or Debug.
Use Show in > System explorer from the context menu on the project (or any file) to open Windows Explorer (or whatever your OS uses).
If you just want to test some lines of code, there is no need to create a jar file at all, just use the Run As > Java application menu.
Once you get used to it the eclipse tooling for java is no worse than that of netbeans. And I've never found building java applications with either tool to be much different than building c# projects in Visual Studio.
As for having a main class, not every type of application requires you to create one. It's no that much different than c++ is in that respect, is it?
Take a look at this thread:
Build project into a JAR automatically in Eclipse
It seems any number of those methods would take less than 3 minutes. And once you do it once (for example using an ant file), future builds will take seconds.
Also, look at this maven article:
https://maven.apache.org/guides/getting-started/maven-in-five-minutes.html
Five minutes from the command line. The eclipse tooling will cut that down considerably.

Working on an Eclipse project (using Builders) in IntelliJ

I've recently been tasked with working on an existing eclipse project that makes use of Builders to run Ant tasks under given conditions. I've never heard of Builders before yesterday, and I'm having difficulties getting the project to work in IntelliJ.
First of all, I would like to know if there is a way I can effectively trick Ant into running from a different base directory than what it already does. Consider the following screenshot from Eclipse:
Here, project A is running an Ant task in a local build file that extends a build file from project B. As you can see from the Base Directory setting, it is different from that of A. When I try to run the task from this build file in IntelliJ, I get build errors because certain directories do not exist in the folder for project A -- they are located in project B.
Secondly, this Builder is set to trigger on Manual Build and Auto Build, but my understanding is that this only triggers if the project the builder is attached to gets built. As far as I can tell, in IntelliJ, I can set an Ant task to trigger before or after a build, but it seems like this will be for the whole project, instead of just the relevant module that represents this Eclipse project. Is there a way I can make it only apply to a given module, or will I have to trigger it for changes to all modules?

Compare to the IDE for Java,do we still need Ant?

Not long before I had digged into Ant and use it doing simple practice(compile,unit test,package).Now my usual work is under Eclipse for java development,the usual work can all be simply done through Eclipse' function:in-time compiling、click button to deploy、various wizard..
So I am wondering under Eclipse do we have a need for Ant.
And if it is, at which aspect should we use Ant along with Eclipse.
Building applications is not about just building them in your IDE. You need to setup an automated build and deploy method that can be run for, say, continuous integration and deployment. The built package has to be deloyed to various environments and finally production. You cannot build them out of your own box. You cannot build it out of your IDE. You need separate build system. That is where build tools like ANT come in.
Also note that the capabilities of IDEs for doing build, deploy is limited and that is not their strength. It is, however, possible to make use of ANT and its build scripts and run them out of eclipse. This way, you have a single set of scripts for both your local ( developer ) build and the main build process. With ANT being JAVA based, you can also suit your build tool to your needs by writing custom tasks etc.
Also, when you make use of something as standard as ANT for your build system, you can move to a different IDE like Intellij IDEA and still make use of the build system that you know.
Do you need Ant if you can build through the IDE? Of course not! You can see that yourself.
Should you still have a IDE independent build with standard tools? Of course!
Note I didn't say Ant. There are a number of build tools such as Maven or Gradle that are made to build Java programs. However, there are reasons why you want an IDE independent build system:
You have a Continuous Integration Server: You do have one. Right? If you don't get one. A Continuous Integration Server automatically builds your project (and runs every test) each time a change is committed to the version control system. It catches mistakes. It also provides an OFFICIAL BUILD. No more It worked on my machine! excuses. If the Continuous Integration Server can't build it and successfully run the tests, the software isn't good.
You have others who need to work with your project on a different computer in a different environment: The problem with IDEs is that its specific to your system. Someone else checks out your project, and they may be using a different IDE. They maybe have a slightly different setup. An independent build scripting language like Ant guarantees that they can rebuild your project as intended.
If you share a project with someone else, you need an independent standard method way of being able to build that project and to know exactly what is required for that build to work. IDEs can hide that information.
I am a benchmark tester using Ant everyday. Our environment has 7 test machines and 1 console machine. For each test run, the ant script updates the working copy, restarts the database, build the product and the Grinder with proper properties and deploy them to the machines, and starts them and the monitoring softwares. With the 1000-line-buildfile, I can just type in an "ant A B C D E"-like line in the terminal on the console machine. I don't think it's a good idea to do this in a IDE like eclipse or NetBeans or anything else.
Also, in my company's product, ant is widely used. We use ant to build sample data for the benchmark test; we use ant to update Tomcat which is going to be bundled with our product; we also use ant to build and run selenium tests.
What's more, when you want to release the source code, including the IDE project files is not a good idea because there are a lot of IDEs. And what if the user just want to get a fresh build from your latest code (if you don't provide nightly build)? Providing a set of ant (or other build tool) buildfiles is a good idea. With this, you can manage your classpath for the build.
The shortest answer here wold be flexibility. The IDEs may came with pre-defined functionalities and may even allow you to choose some options using wizards. It is like generating html with Dreamweaver or such tools. It will never be as flexible as the pure thing. For example NetBeans uses Ant underneath.
Quoted from: Netbeans: Build Tools
The default NetBeans IDE project system is built directly on top of
the Ant build system. All of the project commands, such as "Build
Project" and "Run File in Debugger", call targets in the project's Ant
script. You can therefore build and run your project outside the IDE
exactly as it is built and run inside the IDE.
Even after you use tools for that purpose you are most likely still to brush up. So, what I am saying is, what the IDEs do for you is only a subset of what you can do with the pure ant or maven( if you use it). For simple tasks such as compile and run, IDEs do pretty much a good job! But if you have a use case as complex as deploying on CI IDEs won't help you. You need the whole flexibility of your build tools.

Can Ant detect if a project is closed in Eclipse?

We're using Eclipse on a flat multi-project set-up. Ant builders are set up on each project to create jars as needed; the ant files are used to manually kick off junit tests, create junit reports, etc.
One project is set up as a "master build" project, from which one has a convenient single ant target "test-all", which invokes the test target in all the other projects. This works, no problem.
The challenge is, that to some developers, certain projects represent optional components that aren't relevant to their immediate work task. So they close these projects to create some time-savings when doing things like clean and rebuild the whole workspace. This is fine, Eclipse ignores the closed projects as intended.
Problems occur when one goes to the "master build" project, and runs the ant test-all target. As you'd expect, it goes and tries to run the tests for all the projects, not just the "open" ones.
Any easy way to make the ant script smarter when running in an eclipse environment to know about "closed" projects, so I could make it ignore those?
Sort of adding an "unless=${CLOSED.UNDER.ECLIPSE}" type of ability to my ant files.
many thanks.

How to run Eclipse launch configurations programmatically?

I'm finding it difficult to phrase this question well, as there are quite a few generic terms (run, configuration, launch, etc.). Here goes:
You can save run configurations in a .launch file. (in the Run Configuration Dialog, under the Common tab, Save as a shared file.
We check these in to SVN. The developers can pass them around, and it helps getting new devs running a working application quicker.
I'd like to check these out as part of our build and use them to programatically run the application, the tests, etc, without spinning up the whole IDE.
What would be the best way to run a .launch file outside of the UI?
Edit: I am trying to unify the tests run on the build server and the IDE. I do not
particularly want to give up integrated debugging, which would be the case with an ant script to run the tests .
This is probably more a problem for integration testing with multiple bundles, or unit testing a whole bundle, where you'd like to mock up extensions.
there is an eclipse plugin built over JUnit, called TPTP. It provides an automation client which can be used to launch the test from eclipse with no gui. maybe it helps
Ant4Eclipse may provide a good starting point on how to do this.
Unfortunately, this is limited to Java Applications and JUnit configurations; I am more interested in PDE applications and Plugin JUnit tests.
I have recently had alot of success building an Eclipse RCP app inside a Hudson CI server using Eclipse Buckminster. It took a bit of doing, but once I setup both features, made my RCP product be based on features, and added the Buckminster query files and the like, it worked. There is a Hudson/Jenkins Buckminster plugin that allowed me to have hudson build the application.
After saving the launch configurations for each test fragment, I created hudson commands to invoke them (yes one line per test fragment unfortunately), but after that I got the automated CI build that I wanted.
You could also use the shell command Eclipse uses. To get it:
Run your program in Eclipse
Go to the "Debug" view
Right-click on the process (probably the second item in the tree) and select "Properties"
Copy shell command and delete the agentlib flag to run in bash
I think you don't need to use the .launch configurations to run the tests. If you build an application using the Eclipse Build System, then you can use the AntRunner application from Eclipse to run your units tests. This doesn't start the whole IDE.
This article describes how to run the tests during your build process. With this process, you use a special "Test" Eclipse and load the plugins you want to test.
Perhaps running the configurations the way you would run your own custom run configurations would help here. It is described in this article.