java与资源一起部署war文件
我有一个war文件,我已经部署了它,但是在部署资源和链接之后,它就不起作用了
<build>
<finalName>KFA</finalName>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<includes>
<include>**/*Tests.java</include>
</includes>
</configuration>
</plugin>
</plugins>
</build>
When I build the application I get kfa.war which i deploy to tomcat but unfortunately I can't access any page, I get http status 404 - /kfa/trainee. sample controller
@Controller
@RequestMapping("/kfa/trainee")
public class TraineeController {
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
TraineeService traineeService;
RegService regService;
@Autowired
public void setTraineeService(TraineeService traineeService) {
this.traineeService = traineeService;
}
@Autowired
public void setRegService(RegService regService) {
this.regService = regService;
}
@RequestMapping(method = RequestMethod.GET)
public ModelAndView addMember(ModelMap model){
model.addAttribute("module", "kfa/trainee");
model.addAttribute("submodule", "add_trainee");
model.addAttribute("title", "Trainee");
model.addAttribute("subtitle", "Add");
model.addAttribute("trainee", new Trainee());
return new ModelAndView("/kfa/index", model);
}
}
当我在intellij idea中运行和部署时,我使一切工作正常。我的问题是,我应该如何配置上面粘贴的构建,以允许我在另一台机器上的tomcat上运行war文件
如果不理解,您可以询问更多信息。我将为你的帮助而高兴
# 1 楼答案
通过解压来验证你的战争是否包含了它应该包含的所有内容
如果它没有所需的内容,请确保您的项目使用了这里提到的正确的maven目录结构https://maven.apache.org/guides/introduction/introduction-to-the-standard-directory-layout.html
如果不是这样,你可能不得不相应地调整你的项目,一切都应该按预期进行
# 2 楼答案
如果部署一个名为kfa的war文件。war在tomcat容器中,如果部署时不提供任何其他信息,tomcat将采用上下文路径/kfa
尝试访问/kfa/kfa/学员
但是查看tomcat的日志文件应该会有所帮助!您可以安装tomcat的管理器war(https://tomcat.apache.org/tomcat-7.0-doc/manager-howto.html),以获取容器中已安装war的信息,并转到/manager/html