Eclipse在wtpwebapps中生成我的类三次

时间:2011-10-17 10:31:16

标签: eclipse java-ee tomcat maven m2eclipse

我有一个PrettyFaces框架的问题,当使用eclipse在服务器上运行应用程序(tomcat 6)时,不止一次找到一个类

我发现eclipse在wtpwebapps中多次生成类:

\WEB-INF\classes\com\myapp\sample\beans\myclass.class
WEB-INF\classes\target\classes\com\myapp\sample\beans\myclass.class
\WEB-INF\classes\target\app-name\WEB-INF\classes\com\myapp\sample\beans\myclass.class

更新

我正在使用 m2eclipse 插件,并使用 maven 作为我的构建工具,可能是配置错误,或者需要配置的东西。

UPDATE2:

这是pom文件构建,也许我有点错误:

<build>

        <finalName>appName</finalName> 

        <resources>

            <resource>
                <directory>src/main/resources</directory>
                <filtering>true</filtering>
            </resource>

        </resources>

        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                    <source>1.6</source>
                    <target>1.6</target>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-dependency-plugin</artifactId>
                <executions>
                    <execution>
                        <id>install</id>
                        <phase>install</phase>
                        <goals>
                            <goal>sources</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>

            <plugin>
               <groupId>org.apache.maven.plugins</groupId>
               <artifactId>maven-resources-plugin</artifactId>
               <version>2.5</version>
               <configuration>
               <encoding>UTF-8</encoding>
               </configuration>
            </plugin>
        </plugins>
    </build>

如何解决此问题的任何想法?

1 个答案:

答案 0 :(得分:0)

我安装了“m2e wtp”连接器吗? Maven - &gt;发现 - &gt;打开目录(在Indigo中)搜索“wtp”。

考虑使用:

<properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

然后可能不需要像你那样设置UTF-8。但也许你现在有另一种编码,但是在另一种编码和资源中使用* .java会很奇怪。最好使整个项目相同。

您能否确认是否正在构建WAR,这是您在WAR中看到的内容?或者如果使用Eclipse中的启动Tomcat功能,这就是您在项目中看到的内容。

同时确认您已使用Stop Tomcat,Clean,手动检查目录是否已清除(可能是工作区刷新,另一个服务器 - &gt;清理,手动删除Tomcat区域中的文件)。然后执行完全发布(到tomcat),然后启动/调试tomcat以启动。

我猜你现在的配置是否如上所述(假设没有父pom.xml影响构建做得很糟糕),你看到的文件是因为在搞乱了maven后没有清理wtpwebapps区域的结果配置。

有多个地方需要检查清理:

Temporarly Turn off: Project -> Build Automatically
Stop All Servers instances running like: Tomcat
Run As -> Maven -> clean
Servers -> Clean

Open file browser and validate for yourself outside of Eclipse that the following dirs are empty or non-existant:

  workspaceDirectory/projectDirectory/target   (the maven output folder)

  workspaceDirectory/metadata/.plugins/org.eclipse.wst.server.core/tmpX/wtpwebapps/**
  # This one is ok to have the top level contextPath's, provind they are currently active projects you have added to the server.

  $CATALINA_HOME/

Perform workspace refresh (to ensure Eclipse resync file system state to workspace state).  I do this with clicking on any project in Project Explorer, then Ctrl-Clicking it again to deselect it (so nothing is selected but Project Explorer is in focus) then press F5.   Other people use Ctrl-A to select all projects.

  Now do a Project -> Build All
  Now do a Servers -> Publish  (now check the tree you get)

  Now re-enable Project -> Build Automatically (if you run that way)  
相关问题