finding what commands are executed by eclipse - 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.

Related

Running Maven commands on the command line in Eclipse

I am trying to use Maven to export my project into a JAR file, however I am also trying to export the dependencies as well and I am using the shade plugin, however I am wondering how exactly would I then run it?
I read I need to run "mvn shade:shade", however I don't exactly know where I run this? in the terminal I get 'mvn' is not recognized as an internal or external command, operable program or batch file.
So I don't really know where I am supposed to run this
Note: This solution assumes that your project is configured/imported as a Maven project.
Right-click the project in Eclipse. Select Run as > Maven build... > Goals, type package and then click Run.
Following best practices, you should not run shade:shade from the CLI (which you are actually doing with this approach), but rather bind the shade plugin to the package phase.
This link will explain how to do that, if you haven't already done it.

Apache Ant - Installing Maven Ant Tasks

This is for running files as Ant builds in Eclipse. I have my Ant set up, now I need to install the Maven Ant Tasks. I followed the instructions on the Maven website: downloaded the JAR and put it in my .ant/lib, and double checked that my environment variables were correct. When I try to run as an Ant build in Eclipse, however, it gives me this error:
No types or tasks have been defined in this namespace yet
This appears to be an antlib declaration.
Action: Check that the implementing library exists in one of:
-C:\Users\arempel\Documents\eclipse\eclipse\plugins\org.apache.ant_1.8.3.v201301120609\lib
-C:\Users\arempel\.ant\lib
-a directory added on the command line with the -lib argument
Now I know there are a ton of resolved questions like this that have been answered, but I've tried all of the solutions I could find to no avail. I've tried using -lib in prompt, tried setting the classpath variable, tried playing around with my environment variables, but I'm still screwing up somehow.
Does anyone know what I'm doing wrong, what I'm missing?
When running Ant within Eclipse, it is Eclipse itself which is managing the classpath of Ant.
Look into the global preferences of Eclipse, and then into the Ant/Runtime panel. The first tab, 'Classpath' is the one you want to modify. Click on the 'Global Entries' and then hit the button 'Add JARs...'. Select the jar of the Maven Ant Tasks and you're done.

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!

Eclipse: script compiler as part of a project

This question is not limited to lex and yacc, but how can I add a custom script compiler as part of a project? For example, I have the following files in the project:
grammar.y
grammar.l
test.script
The binary 'script_compiler' will be generated using grammar.y and grammar.l compiled by lex, yacc and g++. And then I want to use that generated script_compiler to compile test.script to generate CompiledScript.java. This file should be compiled along with the rest of the java files in the project. This setting is possible with XCode or make, but is it also possible with Eclipse alone? If not, how about together with Maven plugin?
(I might setup the script compiler as a separate project, but it would be nice if they can be put in the same project so that changes to the grammar files can be applied immediately)
Thanks in advance for your help!
You can add a custom "Builder" from the project properties dialog. This can be an ant script (with an optional target) or any other script or executable.
There are also maven plugins for ant and other scripting languages
If you just want to run an external program in Maven this is what you want: http://mojo.codehaus.org/exec-maven-plugin/ -- you can then run Maven targets from your IDE or command line and it should do the right thing either way.
To integrate with the normal compilation bind the plugin to the "generate-sources" phase and add the location where the Java files are generated to the "sourceRoot" option of the exec plugin. That way the compiler will pick them up.
Ideally you generate the code into a folder "target/generated-sources/MY_SCRIPT_NAME". That is the standard location for generated sources in the Maven world and e.g. IntelliJ IDEA will pick up source files inside of that location. Note that this doesn't work if the files are directly in "target/generated-sources".
The other option is to write your own Maven plugin, which is actually quite easy as well. See e.g. https://github.com/peterbecker/maven-code-generator

Netbeans project to scripted build

I'm trying to convert a Netbeans 6.9.1 project into a scripted build (without netbeans). Of course, it fails (or I wouldn't be asking for help).
In the failure it says that the org.apache.commons.httpclient package does not exist. (Of course, it worked when we ran the build in Netbeans).
Now I know exactly where the commons-httpclient.jar file is located in my project structure, but I can't seem to tell it to the compiler via the ant build files and the netbeans property files.
Perhaps related to this is when I ran "ant -v" to build my software, it said,
Property lib.mystuff.classpath has not been set. This variable is important, I guess, because
the file nbproject/project.properties uses lib.mystuff.classpath in its definition of javac.classpath, which of course tells the Java compiler where to find the JARs.
So...when moving a Netbeans project to a netbeans-independent scripted build, how can the build script set these properties? Also, how can I ensure that the jar file gets included in the ant build?
I appreciate any help I can get, as I am a Java newbie.
UPDATE AFTER ACCEPTING ANSWER FROM vkraemer:
There are a few best practices for build scripts for production software:
Put everything needed for a build under a single directory tree. (Netbeans = fail)
Put everything in source code control. (I did that)
The first line of the build script should clear all environment variables.
The next section of the build script should explicitly set all environment variables to values which are known to work.
The next part of the build should be able to execute using command-line programs such as javac, ant, cc, etc, and must not depend on firing up an IDE such as Eclipse or Netbeans.
It is a shame that Netbeans makes this hard.
I did a quick look in a Java Application project and found the following...
javac.classpath = ${libs.MyStuff.classpath}
libs.MyStuff.classpath is defined in %HOME%/.netbeans/6.9.1/build.properties.
You may be able to get by doing the following...
ant -Dlibs.MyStuff.classpath=c:\a\b\c.jar
You would need to do more if you have multiple jar files in the MyStuff library that you created in NetBeans.