有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

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文件

如果不理解,您可以询问更多信息。我将为你的帮助而高兴


共 (2) 个答案

  1. # 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