Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Language IDEs » ServerTools (WTP) » Finding the context root and tomcat version of WTP projects programmatically
Finding the context root and tomcat version of WTP projects programmatically [message #181674] Mon, 16 October 2006 21:17 Go to next message
Justin Weir is currently offline Justin WeirFriend
Messages: 18
Registered: July 2009
Junior Member
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 #181676 is a reply to message #181674] Mon, 16 October 2006 21:43 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: kosta.bea.com

I will answer half of your question and let other folks answer the rest.
Here is a bit of code that you should use to check whether a project has
a certain facet...

import org.eclipse.wst.common.project.facet.core.*;

....

final IFacetedProject fproj = ProjectFacetsManager.create( <IProject> );

if( fproj != null )
{
final IProjectFacet f
= ProjectFacetsManager.getProjectFacet( "jst.web" );

return fproj.hasProjectFacet( f );
}

- Konstantin
Re: Finding the context root and tomcat version of WTP projects programmatically [message #181694 is a reply to message #181676] Tue, 17 October 2006 19:31 Go to previous messageGo to next message
Justin Weir is currently offline Justin WeirFriend
Messages: 18
Registered: July 2009
Junior Member
Thanks, Konstantin. That worked great.

Even if you don't know exactly what to do, do you think you could point me
in the right direction with the web content folder and the tomcat version?
If you could just get me started, I could probably figure out the rest
using the source code and the debugger.
Re: Finding the context root and tomcat version of WTP projects programmatically [message #181698 is a reply to message #181694] Tue, 17 October 2006 21:30 Go to previous messageGo to next message
Larry Isaacs is currently offline Larry IsaacsFriend
Messages: 1354
Registered: July 2009
Senior Member
Since I'm short on time, here's a "no error handling start" that builds
on Kostantin's earlier code:

For version of "jst.web", i.e. Servlet spec version of the project:

fproj.getInstalledVersion(f).getVersionString();

For content folder, perhaps:

IVirtualFolder rf = fproj.getRootFolder();
IPath p = rf.getProjectRelativePath();

I'm not sure there is public API to get the Tomcat version. Is that
what you really need, or would the "jst.web" version be ok?

Cheers,
Larry

Justin Weir wrote:
> Thanks, Konstantin. That worked great.
>
> Even if you don't know exactly what to do, do you think you could point
> me in the right direction with the web content folder and the tomcat
> version? If you could just get me started, I could probably figure out
> the rest using the source code and the debugger.
>
Re: Finding the context root and tomcat version of WTP projects programmatically [message #181704 is a reply to message #181694] Tue, 17 October 2006 22:09 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: kosta.bea.com

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 #181707 is a reply to message #181704] Tue, 17 October 2006 23:06 Go to previous messageGo to next message
Larry Isaacs is currently offline Larry IsaacsFriend
Messages: 1354
Registered: July 2009
Senior Member
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 #181723 is a reply to message #181707] Wed, 18 October 2006 14:52 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: kosta.bea.com

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
Re: Finding the context root and tomcat version of WTP projects programmatically [message #181727 is a reply to message #181707] Wed, 18 October 2006 15:16 Go to previous messageGo to next message
Justin Weir is currently offline Justin WeirFriend
Messages: 18
Registered: July 2009
Junior Member
Thanks a lot, guys. Everything worked, and I'm all set now.
Re: Finding the context root and tomcat version of WTP projects programmatically [message #181731 is a reply to message #181723] Wed, 18 October 2006 15:59 Go to previous message
Larry Isaacs is currently offline Larry IsaacsFriend
Messages: 1354
Registered: July 2009
Senior Member
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
Previous Topic:Error if opening a xml file from subclipse-history
Next Topic:Orion task for Xdoclet
Goto Forum:
  


Current Time: Fri Apr 19 23:37:00 GMT 2024

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

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

Back to the top