Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[jdt-dev] JDT Core as a library / Eclipse CLI

Hi,

it's been a while[1] since I posted here about using Eclipse's JDT Core
as a library in a standalone Java project. I recently discovered that
there has been the fortunate development that five releases of this
library have been published to Maven Central during 2017[2]. One of the
initial problems I tried to tackle with this can now be solved: running
the Eclipse Formatter standalone or from within 3rd party tooling!

I've set up a little example, a CLI, that is designed to be a handy
tool for running tasks that you usually perform through the Eclipse user
interface, but from the command line or from scripts instead:

https://github.com/sebkur/eclipse-cli

As mentionend above, running the formatter already works[3], which I
consider highly useful on its own. You can specify a formatter
configuration and a number of files or directories to format
recursively.

Another thing I would be very interested in is creating and
manipulating workspaces outside the Eclipse UI (The use case here is
to automatically set up a number of workspaces on fresh working
environments and adding the projects to them initially).

That task seems to be a bit more involved, since it requires the
ResourcesPlugin to be running. I could not get this working yet[2].
Maybe someone more experienced with the Eclipse plugin has an idea how
this could work. I appreciate any directions on this.

Thanks,
Sebastian

[1]http://dev.eclipse.org/mhonarc/lists/jdt-dev/msg00879.html
[2]http://mvnrepository.com/artifact/org.eclipse.jdt/org.eclipse.jdt.core
[3]https://github.com/sebkur/eclipse-cli/blob/master/cli/src/main/java/de/topobyte/eclipse/cli/RunFormat.java
[4]https://github.com/sebkur/eclipse-cli/blob/master/cli/src/main/java/de/topobyte/eclipse/cli/RunCreateWorkspace.java

PS: I tried something along these lines so far to, but that does not
work because the ResourcePlugin instance obtained is null:

public static void main(String[] args) throws Exception
{
	EclipseStarter.main(args);
	BundleContext bc =
	EclipseStarter.getSystemBundleContext();

	InternalPlatform platform =
	InternalPlatform.getDefault(); platform.start(bc);

	try {
		ResourcesPlugin plugin = ResourcesPlugin.getPlugin();
		Workspace workspace = new Workspace();
 	} catch (Throwable e) {
		System.out.println("error: " +
			e.getClass().getSimpleName());
			e.printStackTrace(); }

	EclipseStarter.shutdown();
}


Back to the top