Finding the context root and tomcat version of WTP projects programmatically [message #181674] |
Mon, 16 October 2006 17:17  |
Eclipse User |
|
|
|
What's the best way to get the tomcat version and the path to the content
directory of JSP projects programmatically? Also, what's the right way to
detect whether a project is a JSP project (do I try to detect the jst.web
facet? how would I do that?). I could read the data directly out of the
XML files, but I'd rather do it with the proper API's to ensure forward
compatability.
|
|
|
|
|
|
|
Re: Finding the context root and tomcat version of WTP projects programmatically [message #181707 is a reply to message #181704] |
Tue, 17 October 2006 19:06   |
Eclipse User |
|
|
|
For each IRuntime r, you can use:
String typeid = r.getRuntimeType().getId();
to get a string that will end with two digits indicating the version as
32, 40, 41, 50, or 55. I'm not sure if it is technically public API,
but this approach is probably reliable as I don't think the id strings
will be changing. See the plugin.xml file in the
org.eclipse.jst.server.tomcat.core plug-in to see the full id strings.
They are declared at the beginning of this file.
Cheers,
Larry
Konstantin Komissarchik wrote:
> To get at the web content directory, you can use the virtual component
> api...
>
> import org.eclipse.wst.common.componentcore.resources.*;
>
> final IVirtualComponent vc = ComponentCore.createComponent( <IProject> );
>
> if( vc != null )
> {
> return vc.getRootFolder().getUnderlyingFolder();
> }
>
> Getting tomcat version is a bit tricker since I don't know the context
> that you are trying to do this in. If the project is targetting a tomcat
> runtime, then you can do the following:
>
> import org.eclipse.wst.common.project.facet.core.*;
> import org.eclipse.wst.common.project.facet.core.runtime.*;
>
> final IFacetedProject fproj = ProjectFacetsManager.create( <IProject> );
>
> if( fproj != null )
> {
> for( Iterator itr = fproj.getTargetedRuntimes().iterator();
> itr.hasNext(); )
> {
> final IRuntime r = (IRuntime) itr.next();
>
> // I am getting lazy here, but use r.getRuntimeComponents()
> // method to examine the composition of the runtime. Each
> // component has type and version. You can look for the
> // tomcat type and then check the version.
> }
> }
>
> - Konstantin
|
|
|
|
|
Re: Finding the context root and tomcat version of WTP projects programmatically [message #181731 is a reply to message #181723] |
Wed, 18 October 2006 11:59  |
Eclipse User |
|
|
|
Thanks Konstantin. I had forgotten about the other IRuntime.
Justin, the strings to expect runtime type id and version for Tomcat are
found in the tomcat.core plugin.xml file under the
"org.eclipse.wst.common.project.facet.core.runtimes" extension point,
i.e. the id will be "org.eclipse.jst.server.tomcat" and the versions
will be strings like "3.2", "4.0", etc.
Larry
Konstantin Komissarchik wrote:
> Larry,
>
> You are referring to a different IRuntime. The one I was referring to
> has explicit version support in the form of the IRuntimeComponentVersion
> interface.
>
> - Konstantin
|
|
|
Powered by
FUDForum. Page generated in 0.54142 seconds