Eclipse - Obfuscate .java files and export them as .jar file automatically - eclipse

My dream when using the Eclipse IDE is to have my .java files obfuscated and exported to a .jar file automatically.
At the moment, I use two applications to repetitively perform my obfuscation and jar exportation, and it really is a pain!!!
If I'm correct, the only way to do this is to create my own Ant Task - if this is the case, may you guide me step by step on how to create this Ant Task?
Thank you gurus, I will soon be able to rest my hands for just that little bit longer!

Excelsior Jet has a Eclipse plugin.

Proguard has ant tasks.

Related

Have eclipse copy .class files to additional target folder?

I have an eclipse project. By default, my .class files are being put here:
/projectname/build/classes
is there a way I can have eclipse also copy those files to an additional folder destination, every time the project is built?
I could write a script to do this myself, but was hoping there was some kind of hook in eclipse to do this.
Thanks
You could write an Ant script for this and add it as a builder to your project. See the Eclipse documentation for an example.
Eclipse doesn't have the native ability to output to multiple locations, but you can probably accomplish it yourself by adding a custom builder to your project(s).

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

Extract eclipse project .classpath dependencies into ant script

I have a list of Eclipse projects that I would like to compile based on the existing project configuration.
As far as I can tell, if an ant script could read the .classpath files, it would pretty much be able to infer the project dependencies and perform a "javac" compilation in the right order. This would save time in describing the same dependencies again in the ant script or a Makefile.
The dependencies I am interested in are JAR Dependencies, JRE dependencies, and inter-project dependencies. These are -- as far as I can tell -- part of the .classpath XML file.
Any ideas on how Eclipse project dependencies could used in an ant script?
Right click on your Project -> Export
"General/Ant Buildfiles".
Choose the projects and there you go.
Otherwise...
I have some experience with ant4eclipse and it is a hassle to get it stable.
Go check Buckminster or Maven Tycho for a good solution.
I'm currently using Ivy along with Ant, Eclipse and Maven.
I just love the way Ivy works.
Currently, we have a workspace with many projects using Liferay (with Tomcat) for the front-end and Glassfish for the back-end.
We were looking for a way to manage our dependencies a lot better than how we were doing it.
So I took Ivy, replaced all of the classpaths and deployment dependencies in eclipse and was able to build my application using 1 ivy file per project using either Eclipse or Ant.
Ivy integrates like a charm in ant and builds are done either from the workspace or by command line.
I strongly suggest you look at this avenue. Additionnaly, by adding Artifactory, we have a local repository in which the ivy files look for dependencies. This helps us maintain and rule which jars are to be used by developpers. Once everything is setup, we will build our application nightly using Jenkins and these builds will be using our Artifactory repository to resolve dependencies since our build servers do not have access to the internet.
Hope this helped
If you are running the Ant script only from eclipse using the "External Tools Configurations", you can add the variable ${project_classpath} to the Classpath.
Depending on if you are in a plugin project and dependencies you might need to add the
${eclipse_home}.
In case you get an error launching Variable references empty selection: ${project_classpath}, make sure the ant xml file or at least the project is selected. This is important.
I believe the ant4eclipse project provides support for executing Ant builds based on Eclipse metadata files.
However, in my opinion that is doing things back to front. You shouldn't have your build (Ant) depending on your IDE (Eclipse) environment. But it is useful if you can derive your Eclipse environment from your Ant build.
This is an approach used successfully in a team I worked in. We had a helper Ant target which applied XLST to project build.xml files to transform these into Eclipse .classpath files. Thus the Ant build.xml files were the single configuration point for our projects.

Create single jar from many eclipse projects

I'm doing the build automation for a java app with ant. This is a client-server app which has many projects in eclipse. I would like to create a jar file for the client and one for the server, but since the class dependencies are all over the projects (in eclipse)... I had the idea to use a tool to automate the search for dependencies. I've been looking at GenJar witch is almost all I need but it's not been updated in a while. So I would like to know if there are any other tools like this one, maybe Maven?
You may also try FatJar
It kind of sounds like what you really want is a WAR file.
Personally I would go with Ant + Apache Ivy. Each project has its own build.xml file and publishes to a central Ivy repository. Other projects will simply download these dependencies as needed.
The advantage of having an Ant based build process is that you can very easily automate it and use a continuous server to build the entire product after each check-in.

Building Eclipse plugins and features on the command line

I have a bunch of Eclipse plugins and features, which I would like to build as part of a nightly (headless) build. I've managed to do this using a complicated setup involving manually specifying paths to Eclipse plugin jars, copying customTargets.xml, etc.
Is there really no simpler solution? Isn't there a way to just point out my Update Site's site.xml and say "build"; i.e. the equivalent of clicking "Build All" in the Update Site project?
Given that all the answers to this question are all 3-5 years old, I figure an update would be useful to others.
For those who want to add the building of Eclipse plugins to the CI process, I recommend they check out the Eclipse Tycho project. This is essentially a Maven plugin that allows you you to wrap eclipse projects within Maven project. With this we use Atlassian Bamboo to build our Eclipse plugin. This also allows us to use the Maven jarsigner plugin to sign our plugin files.
I've just been fighting with this problem myself. Are you using the productBuild script? Maybe putting your features into a product would help you out.
I am doing a headless build on a product configuration. The only script that I customized was to add some ant tasks to customTargets.xml to get my sources from SVN and to do a little cleanup on JNLP manifests after the build as I am using WebStart.
Then you only need to invoke antRunner on the out of the box productBuild.xml in the scripts/productBuild directory (in the pde-build plugin).
Check out Ant4Eclipse. I've used it to parse Eclipse's .classpath/.project files to determine project dependencies and classpaths. In combination with Groovy Ant Task, I have automatically built multiple projects in Ant using the Eclipse project files for build information.
A buildPlugin task exists, but I have not personally used it.
We are currently using PDE to automatically build features and our complete product. It works quite well. Make sure you use the right script for product build or feature build.
Eclipse Help on using PDE
EDIT: We've now migrated to Buckminster, which has an excellent command line interface.
You might look into buckminster and maven. There is a learning curve for sure, but they seem to do their jobs well.
We are using headlesseclipse, which can be found on Google Code:
http://code.google.com/p/headlesseclipse/
It works quite well, and can easily automate command-line building of plugins and features. However, I have not yet found a way to automate building of the update site via the command line.