我正在使用Eclipse开发一个Java项目以在服务器上运行。我有两个项目:Eclipse合并两个java项目
1)jbosswildfly
:其中一个Java代码由多个RESTful Services和一个Maven pom组成。
2)theWhoZoo-web
:另一个是一个包含几个html文件的web项目。
我想合并这些项目,只是有一个项目。我试图将WebContent
文件夹从theWhoZoo-web
复制到jbosswildfly
,启动服务器,但我无法访问index.html
。
问题
什么是这两个项目合并的最佳途径,使RESTful服务还有index.html
在同一台服务器上访问?
感谢
UPDATE
我尝试运行JBoss的index.html
却得到了一个404
但是,当我调用REST风格的服务之一,它返回结果。
例如http://localhost:8080/jbosswildfly-1.0/category/list
但是,
http://localhost:8080/jbosswildfly-1.0/index.html
回报:
14:23:31699 WARN [org.springframework.web.servlet.PageNotFound] (默认任务-4)没有映射在DispatcherServlet中使用URI [/jbosswildfly-1.0/index.html]以名称“rest”发现HTTP请求
我pom.xml
有:
<plugin>
<groupId>org.wildfly.plugins</groupId>
<artifactId>wildfly-maven-plugin</artifactId>
<version>1.0.2.Final</version>
<configuration>
<failOnMissingWebXml>false</failOnMissingWebXml>
<outputDirectory>webapps</outputDirectory>
<warName>ROOT</warName>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.3</version>
<configuration>
<failOnMissingWebXml>false</failOnMissingWebXml>
<outputDirectory>deployments</outputDirectory>
<warName>ROOT</warName>
</configuration>
</plugin>
的web.xml
<?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>
WebAppInitializer.java
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);
}
谢谢,我已经试过了。已经有一个'index.html',参见上面的UPDATE。不幸的是我得到了404。尽管我可以访问RESTful服务。你认为有一些配置问题? – Richard
看起来你使用'spring-mvc',那么你可以:创建一个控制器,使用'index.html'作为模板,或者在'web.xml'中改变'org.springframework.web.servlet.DispatcherServlet'的servlet映射。 ,因此DispatcherServlet可以绕过'.html'扩展,并且容器可以直接提供。 –
我的无知抱歉,但是我正在使用Spring构建RESTful服务。为了迎合'index.html',我在'web.xml'文件中添加了一个''(见上文)。但不幸的是没有变化。你是这个意思吗? –
Richard