Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Language IDEs » Java Development Tools (JDT) » Re: Automating JarDesc jar generation from ant
Re: Automating JarDesc jar generation from ant [message #258972] Thu, 05 March 2009 12:27 Go to next message
J.-P. Pellet is currently offline J.-P. PelletFriend
Messages: 71
Registered: July 2009
Member
> I've got a complicated .jardesc that combines multiple projects, with
> exclusions. After jar creation I need to sign it - which doesn't seem
> to be supported by the .jardesc wizard.
>
> I'd like to invoke the "Create Jar" task on the .jardesc from Ant so
> that I can use another ant task to do the jar signing without manual
> intervention.
>
> I don't want to maintain the filesets in both .jardesc and build.xml.
>
> Is this ability currently exposed, or are there any documents that
> describe how to invoke an Eclipse action from within Ant so I can
> develop my own Ant task?
>
> Thanks for any pointers.
>
> Regards, Jon

Jon, I'm having the same problem 5 years later. As I still couldn't find
an easy solution, I created my own task. It fires the Create Jar Eclipse
action just as if you had right-clicked the jardesc file and selected
Create Jar, and so avoids duplicating the jar information in the jardesc
and in build.xml.

First, create a new plugin project, and add dependencies on
org.apache.ant, org.eclipse.core.runtime, org.eclipse.jst.ui,
org.eclipse.core.resources, adn org.eclipse.ui. Next, create a new class
similar to this one:

import java.util.Collections;
import java.util.Iterator;
import java.util.List;

import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.Task;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.Path;
import org.eclipse.jdt.internal.ui.jarpackager.CreateJarActionDeleg ate;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.ui.PlatformUI;

@SuppressWarnings( "restriction" ) // for CreateJarActionDelegate
public class EclipseJar extends Task {

private String jardesc;

public void setJardesc( String jardesc ) {
this.jardesc = jardesc;
}

@Override
public void execute() throws BuildException {

Runnable doIt = new Runnable() {
public void run() {
PlatformUI.getWorkbench().getDisplay().syncExec(
new Runnable() {

public void run() {

try {
CreateJarActionDelegate action =
new CreateJarActionDelegate();
action.selectionChanged( null,
new DummyJardescSelection( jardesc ) );
action.run( null );
} catch( Exception exc ) {
exc.printStackTrace( System.out );
}

}
} );
}
};

doIt.run();
}

private static class DummyJardescSelection
implements IStructuredSelection {

private final IFile jardesc;

public DummyJardescSelection( String jardesc ) {
this.jardesc = (IFile) ResourcesPlugin.getWorkspace().getRoot().
findMember( new Path( jardesc ) );
}

public Object getFirstElement() {
return jardesc;
}

@SuppressWarnings( "unchecked" )
public Iterator iterator() {
return toList().iterator();
}

public int size() {
return 1;
}

public Object[] toArray() {
return toList().toArray();
}

@SuppressWarnings( "unchecked" )
public List toList() {
return Collections.singletonList( jardesc );
}

public boolean isEmpty() {
return false;
}

}

}

Next, package this compiled class as a jar, say MyAntTasks.jar, and in
your build.xml file, put something like this:

<project name="projectname" basedir="." default="jar">

<taskdef name="eclipseJar" classname="EclipseJar"
classpath="../anttaskproject/MyAntTasks.jar"/>

<property name="jarfile" value="jardestproject/FinalJar.jar" />
<property name="jardescfile" value="jardestproject/FinalJar.jardesc"/>

<target name="clean">
<!-- Delete the jar file -->
<delete file="${jarfile}" />
</target>

<target name="jar">
<!-- Build the jar file the Eclipse way, using the jardesc -->
<eclipseJar jardesc="${jardescfile}" />
</target>

</project>

Be sure to run this ant task in the same JRE as the IDE. This works for
me. Any suggestion for improvement?

Cheers,
J.-P.
Re: Automating JarDesc jar generation from ant [message #889763 is a reply to message #258972] Tue, 19 June 2012 14:47 Go to previous message
Hardy Haardt is currently offline Hardy HaardtFriend
Messages: 1
Registered: June 2012
Junior Member
Hi J.P.,

this sounds as the right solution for my problem, too

I've tried as you described but when running the build.xml I get a

java.lang.NoClassDefFoundError: org/eclipse/ui/PlatformUI

my manifest-file is:

Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: Jardesc
Bundle-SymbolicName: com.myproj.jardesc
Bundle-Version: 1.0.0.qualifier
Bundle-Activator: com.myproj.jardesc.Activator
Bundle-Vendor: MYSELF
Require-Bundle:
org.eclipse.ui,
org.eclipse.core.runtime,
org.apache.ant;bundle-version="1.7.1",
org.eclipse.core.resources;bundle-version="3.6.1",
org.eclipse.jdt.ui;bundle-version="3.6.2"
Bundle-RequiredExecutionEnvironment: JavaSE-1.6
Bundle-ActivationPolicy: lazy

I have added the org.eclipse.ui.workbench dependency also but it doesn't help

Are you using this solution today or did you find a better one?

Best regards
Hardy
Previous Topic:Please I need Help Perspective Flex
Next Topic:problem to connetc to marketplace on indivo realese 2
Goto Forum:
  


Current Time: Sun Dec 21 14:38:02 GMT 2014

Powered by FUDForum. Page generated in 0.01556 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software