I have an exported Eclipse Java Project in my server and I want to be able to compile the project and use ASTParser
with JDT.
I'm able to compile the project using BatchCompiler
, however it runs on console and gives me PrintWriter
s instead of an array of problems and errors. Also I want to be able to use proposals in Eclipse and BatchCompiler
didn't built for this purpose.
Therefore I tried to use ASTParser
, it can be used with either char[]
or ICompilationUnit
. CompletionProposalCollector
and org.eclipse.jdt.internal.compiler.Compiler.Compiler
needs ICompilationUnit
so I have to create an ICompilationUnit
which only can be created by an IJavaProject (https://dl.dropboxusercontent.com/u/10773282/2012/eclipse_workspace.pdf) in order to be able to use these features.
It seems the only way to create IJavaProject
is to use ResourcesPlugin.getWorkspace()
, however it returns java.lang.IllegalStateException: Workspace is closed.
on my computer and it seems the reason is that the program that I coded is not an Eclipse plug-in.
Is there any way to create IJavaProject without Eclipse environment?
From the comments, it looks like you are trying to do more than just parsing, you actually want to get some form of content assist.
I'm afraid that you're asking for too much. There is no simple way to get the power and flexibility of JDT outside of a running Eclipse instance (believe me, I've tried). There's no simple way, but if you are brave and strong willed, you can one of try following:
org.eclipse.jdt.internal.compiler.env.INameEnvironment
. This implementation would be able to find types, files, and compilation units in your actual project structure. You'd need to reimplement support for content assist, but this would most likely work reasonably well.I am actually fairly interested in doing something like this (but I lack the time to do it). If you are seriously considering creating a headless JDT that can run on a server, feel free to ask for more information. I am quite familiar with JDT internals.