Eclipse合并两个java项目

Eclipse合并两个java项目,java,spring,eclipse,maven,spring-mvc,Java,Spring,Eclipse,Maven,Spring Mvc,我正在使用Eclipse开发一个Java项目以在服务器上运行。我有两个项目: 1 jbosswildfly:Java代码由许多RESTful服务和一个Maven pom组成 2 Whozoo web:另一个是包含一些html文件的web项目 我想合并这些项目,只有一个项目。我已尝试将WebContent文件夹从WhoZoo web复制到jbosswildfly,启动服务器,但无法访问index.html 问题: 合并这两个项目的最佳方式是什么,以便可以在同一台服务器上访问RESTful服务和in

我正在使用Eclipse开发一个Java项目以在服务器上运行。我有两个项目:

1 jbosswildfly:Java代码由许多RESTful服务和一个Maven pom组成

2 Whozoo web:另一个是包含一些html文件的web项目

我想合并这些项目,只有一个项目。我已尝试将WebContent文件夹从WhoZoo web复制到jbosswildfly,启动服务器,但无法访问index.html

问题:

合并这两个项目的最佳方式是什么,以便可以在同一台服务器上访问RESTful服务和index.html

谢谢

更新

我尝试运行JBoss index.html,但得到了404

但是,当我调用一个RESTful服务时,它会返回一个结果

e、 g

但是,

返回:

14:23:31699警告[org.springframework.web.servlet.PageNotFound] 默认任务4未找到URI为的HTTP请求的映射 名为“rest”的DispatcherServlet中的[/jbosswildfly-1.0/index.html]

My pom.xml具有:


这不会很简单

作为一般指南,您可能希望从将源代码和测试从一个复制到另一个开始,确保它仍然构建并添加任何缺少的依赖项。我倾向于先把jbosswildfly转移到WHO

然后将资源(包括web目录)从一个添加到另一个。编辑index.html和web.xml文件以反映新结构

启动web服务器并检查日志中是否存在任何异常。尝试自己修复它们,如果无法修复,则返回stackoverflow。

您必须将WebContent文件夹下的文件从Whozoo web移动到jbosswildfly的src/main/webapp,作为web资源的maven默认文件夹,如果不是这样,则必须创建它

如果您想将WebContent保留为静态web文件目录,您可以配置pom.xml,如下所示:

在这种情况下,SpringMVC只截获*.do请求,而.html请求则绕过容器

如果spring项目中有很多链接,那么将.html扩展名改为.jsp可能更容易

如果.do还不够,那么您可以添加更多类似的内容

  <servlet-mapping>
        <servlet-name>rest</servlet-name>
        <url-pattern>/**/*.do</url-pattern>
         <url-pattern>/category/*</url-pattern>
        <url-pattern>/somethingelse/*</url-pattern>
 </servlet-mapping>

谢谢,我试过了。已经有一个index.html,请参阅上面的更新。不幸的是,我得到了404。不过我可以访问RESTful服务。您认为存在一些配置问题吗?看起来您使用的是spring mvc,然后您可以:创建一个控制器,使用index.html作为模板,或者更改web.xml中的org.springframework.web.servlet.DispatcherServlet servlet映射,这样DispatcherServlet就可以绕过.html扩展,容器就可以直接为它服务了。很抱歉我的无知,但我确实在使用Spring来构建RESTful服务的框架。为了满足index.html的需要,我在web.xml文件中添加了一个,请参见上文。但不幸的是没有变化。这就是你的意思吗?我想它实际上使用的是WebAppInitializer.java.adding/***。确实有效,谢谢。我现在可以访问index.html。但是,不,我无法访问RESTful服务,例如。http://localhost:8080/jbosswildfly-1.0/category/list返回404。
<?xml version="1.0" encoding="UTF-8"?>

<web-app version="3.1"
         xmlns="http://xmlns.jcp.org/xml/ns/javaee"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
         metadata-complete="false">
   <!--       
         <servlet>
            <servlet-name>rest</servlet-name>
            <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
            <load-on-startup>1</load-on-startup>
         </servlet>
  -->        
         <servlet-mapping>
            <servlet-name>rest</servlet-name>
            <url-pattern>/*</url-pattern>
         </servlet-mapping>

</web-app>
public class WebAppInitializer implements WebApplicationInitializer {

    @Override
    public void onStartup(ServletContext servletContext) throws ServletException {
        AnnotationConfigWebApplicationContext ctx = new AnnotationConfigWebApplicationContext();
        ctx.register(AppConfig.class);
        ctx.setServletContext(servletContext);
        Dynamic dynamic = servletContext.addServlet("rest", new DispatcherServlet(ctx));
        dynamic.addMapping("/*");
        dynamic.setLoadOnStartup(1);
}
...
<build>
<plugins>
<plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-war-plugin</artifactId>
            <version>2.4</version>
            <configuration>
                <warSourceDirectory>WebContent</warSourceDirectory>
            </configuration>
</plugin>
....
 <servlet-mapping>
        <servlet-name>rest</servlet-name>
        <url-pattern>/**/*.do</url-pattern>
 </servlet-mapping>
  <servlet-mapping>
        <servlet-name>rest</servlet-name>
        <url-pattern>/**/*.do</url-pattern>
         <url-pattern>/category/*</url-pattern>
        <url-pattern>/somethingelse/*</url-pattern>
 </servlet-mapping>