Eclipse - How can I change a 'Project Facet

2019-03-08 22:44发布

(Eclipse 3.4, Ganymede)

I have an existing Dynamic Web Application project in Eclipse. When I created the project, I specified 'Default configuration for Apache Tomcat v6' under the 'Configuration' drop down.

It's a month or 2 down the line, and I would now like to change the configuration to Tomcat 'v5.5'. (This will be the version of Tomcat on the production server.)

I have tried the following steps (without success):

  • I selected Targeted Runtimes under the Project Properties
    The Tomcat v5.5 option was disabled and The UI displayed this message:
    If the runtime you want to select is not displayed or is disabled you may need to uninstall one or more of the currently installed project facets.
  • I then clicked on the Uninstall Facets... link.
    Under the Runtimes tab, only Tomcat 6 displayed.
    For Dynamic Web Module, I selected version 2.4 in place of 2.5.
    Under the Runtimes tab, Tomcat 5.5 now displayed.
    However, the UI now displayed this message:
    Cannot change version of project facet Dynamic Web Module to 2.4.
    The Finish button was disabled - so I reached a dead-end.

I CAN successfully create a NEW Project with a Tomcat v5.5 configuration. For some reason, though, it will not let me downgrade' an existing Project.

As a work-around, I created a new Project and copied the source files from the old Project. Nonetheless, the work-around was fairly painful and somewhat clumsy.

Can anyone explain how I can 'downgrade' the Project configuration from 'Tomcat 6' to 'Tomcat 5'? Or perhaps shed some light on why this happened?

Thanks
Pete

7条回答
在下西门庆
2楼-- · 2019-03-08 23:16

If you are using maven you can generated the eclipse settings using the maven eclipse plugin.

For the jst.web version the Maven eclipse pluging takes into account the dependencies of the project. If you have a servlet api dependency defined :

<dependency>
    <groupId>org.apache.tomcat</groupId>
    <artifactId>servlet-api</artifactId>
    <version>6.0.32</version>
</dependency> 

You jst.web parameter will be 6.0

<faceted-project>
  ...
  <installed facet="jst.web" version="6.0"/>
  ...
</faceted-project>
查看更多
Emotional °昔
3楼-- · 2019-03-08 23:19

You can try to uncheck the facet, apply, change the value of the facet and check. It works for me in Eclipse Helios SR1.

So the main difference is that I do it with 'Dynamic Web Module'.

I hope it works for you too.

查看更多
萌系小妹纸
4楼-- · 2019-03-08 23:22

This is kind of hacking eclipse and you can get into trouble doing this but this should work:

Open the navigator view and find that there is a .settings folder under your project expand it and then open the file: org.eclipse.wst.common.project.facet.core.xml you should see a line that says: <installed facet="jst.web" version="2.5"/> Change that to 2.4 and save.

Just make sure that your project isn't using anything specific for 2.5 and you should be good.

Also check your web.xml has the correct configuration:

<web-app version="2.4" 
        xmlns="http://java.sun.com/xml/ns/j2ee" 
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
        xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
查看更多
神经病院院长
5楼-- · 2019-03-08 23:22

if you are using Maven, then shutdown eclipse, then type >mvn eclipse:eclipse -Dwtpversion=2.0, and restart the eclipse.

查看更多
Bombasti
6楼-- · 2019-03-08 23:26

I saw the same thing, then I changed the web-app version value in the web.xml. Doing so could fix this for you.

查看更多
手持菜刀,她持情操
7楼-- · 2019-03-08 23:29

Sorry it seems I can't post a comment without enough Rep so...

I think it's too difficult for eclipse to degrade safely to a lower standard because it can't really know if you've used something from the newer web standard. So if it just allows you do to that it could cause your program to fail on an older version.

You can always be backward compatible but not forwards compatible.

查看更多
登录 后发表回答