在idea中提取springboot的jar包


前面的步聚都是一样的,修改pom.xml。


        <dependency>
            <groupId>org.apache.tomcat.embedgroupId>
            <artifactId>tomcat-embed-jasperartifactId>
        dependency>


        <resources>
            <resource>
                <directory>src/main/webappdirectory>
                <targetPath>META-INF/resourcestargetPath>
                <includes>
                    <include>*.*include>
                includes>
            resource>
            <resource>
                <directory>src/main/resourcesdirectory>
                <includes>
                    <include>**/*.*include>
                includes>
            resource>
        resources>


            <plugin>
                <groupId>org.springframework.bootgroupId>
                <artifactId>spring-boot-maven-pluginartifactId>
                <version>1.4.2.RELEASEversion>
                <configuration>
                    <mainClass>com.example.Spring027Jar03ApplicationmainClass>
                configuration>
                <executions>
                    <execution>
                        <id>repackageid>
                        <goals>
                            <goal>repackagegoal>
                        goals>
                    execution>
                executions>
            plugin>

以上只有那个1.4.2.RELEASE是与jar文件的生成有关的,是必须要改的。

再改properties文件。加这个jsp支技的前后缀,

spring.mvc.view.prefix=/
spring.mvc.view.suffix=.jsp

然后再添加一个类。这个controller类,一个指向是返回一个对象,一个是返回一个相应的同名的页面。

package com.example.control;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.Map;

@Controller
public class MyController {
    @RequestMapping("/hehe")
    public @ResponseBody Object hehe(){
        Map map=new HashMap<>();
        map.put("userid",1001);
        map.put("username","lili");
        return map;
    }

    @RequestMapping("show")
    public String show(Model model){
        model.addAttribute("userid",1002);
        model.addAttribute("username","haha");
        return "show";
    }
}

再建一个webapp目录,并指定为webapp目录,然后在里面新建一个show.jsp。

<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Titletitle>
head>
<body>
<h1>${userid}h1>
<h2>${username}h2>
body>
html>

然后,运行,成功以后,在idea的右边点击clean,再点击package就行了。

然后,把生成的jar文件拷到需要的目录,打开cmd窗口,运行这个jar文件,就行了,就能在浏览器里访问这个工程了。