不联网情况下,使用 IDEA 或者 eclipse 通过 maven、maven本地仓库搭建springboot项目

文章目录

    • 搭建之前所需工具:
    • eclipse
      • 修改maven配置
      • 新建maven project项目如图
      • pom.xml文件导入包
      • 添加入口文件
      • 添加配置文件
      • 在web层里面创建一个 controller
      • 最后启动成功
    • IDEA
      • 修改maven配置
      • 新建maven project项目
      • pom.xml文件导入包
      • 添加入口文件
      • 添加配置文件
      • 在web层里面创建一个controller
      • 最后启动成功

搭建之前所需工具:

 IDEA、eclipse、maven、maven本地仓库(没网的情况下需要的资源)。

eclipse

修改maven配置

文件存放的地址,D:\apache-maven-3.5.4\conf\setting.xml文件,添加/修改如下:

     
 <localRepository> D:\MyApplication\java_tool\maven_repository\m2\repository localRepository>
  

新建maven project项目如图

不联网情况下,使用 IDEA 或者 eclipse 通过 maven、maven本地仓库搭建springboot项目_第1张图片

不联网情况下,使用 IDEA 或者 eclipse 通过 maven、maven本地仓库搭建springboot项目_第2张图片

pom.xml文件导入包

pom.xml文件如下:


<project xmlns="http://maven.apache.org/POM/4.0.0"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
	<modelVersion>4.0.0modelVersion>
	<groupId>cn.jsdgroupId>
	<artifactId>jsd_networkartifactId>
	<version>0.0.1-SNAPSHOTversion>
	<name>jsd_network_namename>
	<description>jsd_network_descriptiondescription>
	<parent>
		<groupId>org.springframework.bootgroupId>
		<artifactId>spring-boot-starter-parentartifactId>
		<version>2.2.2.RELEASEversion>
		<relativePath /> 
	parent>

	<dependencies>
		<dependency>
			<groupId>org.springframework.bootgroupId>
			<artifactId>spring-boot-starter-webartifactId>
		dependency>

		<dependency>
			<groupId>org.springframework.bootgroupId>
			<artifactId>spring-boot-starter-testartifactId>
			<scope>testscope>
		dependency>
	dependencies>

	<build>
		<plugins>
			<plugin>
				<groupId>org.springframework.bootgroupId>
				<artifactId>spring-boot-maven-pluginartifactId>
			plugin>
		plugins>
	build>
project>

添加入口文件

不联网情况下,使用 IDEA 或者 eclipse 通过 maven、maven本地仓库搭建springboot项目_第3张图片


package jsd_network;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class Application {
	public static void main(String[] args) {
		SpringApplication.run(Application.class, args);
	}
}

添加配置文件

不联网情况下,使用 IDEA 或者 eclipse 通过 maven、maven本地仓库搭建springboot项目_第4张图片

application.yml 文件属性如下:

#server
server:
  port: 8080
  

在web层里面创建一个 controller

不联网情况下,使用 IDEA 或者 eclipse 通过 maven、maven本地仓库搭建springboot项目_第5张图片

添加@RestController注解 这个注解是 @Controller和@ResponesBody的组合 用于直接返回 JSON数据。

package jsd_network.controlle;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class TestController {

    @RequestMapping("/hello")
    public String home() {
        return "Hello SpringBoot Application";
    }
}

最后启动成功

不联网情况下,使用 IDEA 或者 eclipse 通过 maven、maven本地仓库搭建springboot项目_第6张图片

打开浏览器访问 http://localhost:8080/hello 就可以看到返回的json数据。

不联网情况下,使用 IDEA 或者 eclipse 通过 maven、maven本地仓库搭建springboot项目_第7张图片

IDEA

修改maven配置

不联网情况下,使用 IDEA 或者 eclipse 通过 maven、maven本地仓库搭建springboot项目_第8张图片

不联网情况下,使用 IDEA 或者 eclipse 通过 maven、maven本地仓库搭建springboot项目_第9张图片

新建maven project项目

不联网情况下,使用 IDEA 或者 eclipse 通过 maven、maven本地仓库搭建springboot项目_第10张图片

不联网情况下,使用 IDEA 或者 eclipse 通过 maven、maven本地仓库搭建springboot项目_第11张图片

不联网情况下,使用 IDEA 或者 eclipse 通过 maven、maven本地仓库搭建springboot项目_第12张图片

pom.xml文件导入包

pom.xml文件如下:


<project xmlns="http://maven.apache.org/POM/4.0.0"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
	<modelVersion>4.0.0modelVersion>
	<groupId>cn.jsdgroupId>
	<artifactId>jsd_networkartifactId>
	<version>0.0.1-SNAPSHOTversion>
	<name>jsd_network_namename>
	<description>jsd_network_descriptiondescription>
	<parent>
		<groupId>org.springframework.bootgroupId>
		<artifactId>spring-boot-starter-parentartifactId>
		<version>2.2.2.RELEASEversion>
		<relativePath /> 
	parent>

	<dependencies>
		<dependency>
			<groupId>org.springframework.bootgroupId>
			<artifactId>spring-boot-starter-webartifactId>
		dependency>

		<dependency>
			<groupId>org.springframework.bootgroupId>
			<artifactId>spring-boot-starter-testartifactId>
			<scope>testscope>
		dependency>
	dependencies>

	<build>
		<plugins>
			<plugin>
				<groupId>org.springframework.bootgroupId>
				<artifactId>spring-boot-maven-pluginartifactId>
			plugin>
		plugins>
	build>
project>

添加入口文件

package jsd_network;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;


@SpringBootApplication
public class Application {
    public static void main(String[] args) {
        SpringApplication.run(Application.class, args);
    }
}

添加配置文件

不联网情况下,使用 IDEA 或者 eclipse 通过 maven、maven本地仓库搭建springboot项目_第13张图片

application.yml 文件属性如下:

#server
server:
  port: 8080
  

在web层里面创建一个controller

不联网情况下,使用 IDEA 或者 eclipse 通过 maven、maven本地仓库搭建springboot项目_第14张图片

添加@RestController注解 这个注解是 @Controller和@ResponesBody的组合 用于直接返回 JSON数据。

package jsd_network.controlle;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class TestController {

    @RequestMapping("/hello")
    public String home() {
        return "Hello SpringBoot Application";
    }
}

最后启动成功

D:\MyApplication\java_tool\jdk1.8.0_162\bin\java.exe -XX:TieredStopAtLevel=1 -noverify -Dspring.output.ansi.enabled=always -javaagent:D:\MyApplication\tool\ideaIU_2021.2.1_Portable\lib\idea_rt.jar=58558:D:\MyApplication\tool\ideaIU_2021.2.1_Portable\bin -Dcom.sun.management.jmxremote -Dspring.jmx.enabled=true -Dspring.liveBeansView.mbeanDomain -Dspring.application.admin.enabled=true -Dfile.encoding=UTF-8 -classpath D:\MyApplication\java_tool\jdk1.8.0_162\jre\lib\charsets.jar;D:\MyApplication\java_tool\jdk1.8.0_162\jre\lib\deploy.jar;D:\MyApplication\java_tool\jdk1.8.0_162\jre\lib\ext\access-bridge-64.jar;D:\MyApplication\java_tool\jdk1.8.0_162\jre\lib\ext\cldrdata.jar;D:\MyApplication\java_tool\jdk1.8.0_162\jre\lib\ext\dnsns.jar;D:\MyApplication\java_tool\jdk1.8.0_162\jre\lib\ext\jaccess.jar;D:\MyApplication\java_tool\jdk1.8.0_162\jre\lib\ext\jfxrt.jar;D:\MyApplication\java_tool\jdk1.8.0_162\jre\lib\ext\localedata.jar;D:\MyApplication\java_tool\jdk1.8.0_162\jre\lib\ext\nashorn.jar;D:\MyApplication\java_tool\jdk1.8.0_162\jre\lib\ext\sunec.jar;D:\MyApplication\java_tool\jdk1.8.0_162\jre\lib\ext\sunjce_provider.jar;D:\MyApplication\java_tool\jdk1.8.0_162\jre\lib\ext\sunmscapi.jar;D:\MyApplication\java_tool\jdk1.8.0_162\jre\lib\ext\sunpkcs11.jar;D:\MyApplication\java_tool\jdk1.8.0_162\jre\lib\ext\zipfs.jar;D:\MyApplication\java_tool\jdk1.8.0_162\jre\lib\javaws.jar;D:\MyApplication\java_tool\jdk1.8.0_162\jre\lib\jce.jar;D:\MyApplication\java_tool\jdk1.8.0_162\jre\lib\jfr.jar;D:\MyApplication\java_tool\jdk1.8.0_162\jre\lib\jfxswt.jar;D:\MyApplication\java_tool\jdk1.8.0_162\jre\lib\jsse.jar;D:\MyApplication\java_tool\jdk1.8.0_162\jre\lib\management-agent.jar;D:\MyApplication\java_tool\jdk1.8.0_162\jre\lib\plugin.jar;D:\MyApplication\java_tool\jdk1.8.0_162\jre\lib\resources.jar;D:\MyApplication\java_tool\jdk1.8.0_162\jre\lib\rt.jar;D:\MyApplication\www\java_wwwroot_idea\jsd_network\target\classes;D:\MyApplication\java_tool\maven_repository\m2\repository\org\springframework\boot\spring-boot-starter-web\2.2.2.RELEASE\spring-boot-starter-web-2.2.2.RELEASE.jar;D:\MyApplication\java_tool\maven_repository\m2\repository\org\springframework\boot\spring-boot-starter\2.2.2.RELEASE\spring-boot-starter-2.2.2.RELEASE.jar;D:\MyApplication\java_tool\maven_repository\m2\repository\org\springframework\boot\spring-boot\2.2.2.RELEASE\spring-boot-2.2.2.RELEASE.jar;D:\MyApplication\java_tool\maven_repository\m2\repository\org\springframework\boot\spring-boot-autoconfigure\2.2.2.RELEASE\spring-boot-autoconfigure-2.2.2.RELEASE.jar;D:\MyApplication\java_tool\maven_repository\m2\repository\org\springframework\boot\spring-boot-starter-logging\2.2.2.RELEASE\spring-boot-starter-logging-2.2.2.RELEASE.jar;D:\MyApplication\java_tool\maven_repository\m2\repository\ch\qos\logback\logback-classic\1.2.3\logback-classic-1.2.3.jar;D:\MyApplication\java_tool\maven_repository\m2\repository\ch\qos\logback\logback-core\1.2.3\logback-core-1.2.3.jar;D:\MyApplication\java_tool\maven_repository\m2\repository\org\apache\logging\log4j\log4j-to-slf4j\2.12.1\log4j-to-slf4j-2.12.1.jar;D:\MyApplication\java_tool\maven_repository\m2\repository\org\apache\logging\log4j\log4j-api\2.12.1\log4j-api-2.12.1.jar;D:\MyApplication\java_tool\maven_repository\m2\repository\org\slf4j\jul-to-slf4j\1.7.29\jul-to-slf4j-1.7.29.jar;D:\MyApplication\java_tool\maven_repository\m2\repository\jakarta\annotation\jakarta.annotation-api\1.3.5\jakarta.annotation-api-1.3.5.jar;D:\MyApplication\java_tool\maven_repository\m2\repository\org\yaml\snakeyaml\1.25\snakeyaml-1.25.jar;D:\MyApplication\java_tool\maven_repository\m2\repository\org\springframework\boot\spring-boot-starter-json\2.2.2.RELEASE\spring-boot-starter-json-2.2.2.RELEASE.jar;D:\MyApplication\java_tool\maven_repository\m2\repository\com\fasterxml\jackson\core\jackson-databind\2.10.1\jackson-databind-2.10.1.jar;D:\MyApplication\java_tool\maven_repository\m2\repository\com\fasterxml\jackson\core\jackson-annotations\2.10.1\jackson-annotations-2.10.1.jar;D:\MyApplication\java_tool\maven_repository\m2\repository\com\fasterxml\jackson\core\jackson-core\2.10.1\jackson-core-2.10.1.jar;D:\MyApplication\java_tool\maven_repository\m2\repository\com\fasterxml\jackson\datatype\jackson-datatype-jdk8\2.10.1\jackson-datatype-jdk8-2.10.1.jar;D:\MyApplication\java_tool\maven_repository\m2\repository\com\fasterxml\jackson\datatype\jackson-datatype-jsr310\2.10.1\jackson-datatype-jsr310-2.10.1.jar;D:\MyApplication\java_tool\maven_repository\m2\repository\com\fasterxml\jackson\module\jackson-module-parameter-names\2.10.1\jackson-module-parameter-names-2.10.1.jar;D:\MyApplication\java_tool\maven_repository\m2\repository\org\springframework\boot\spring-boot-starter-tomcat\2.2.2.RELEASE\spring-boot-starter-tomcat-2.2.2.RELEASE.jar;D:\MyApplication\java_tool\maven_repository\m2\repository\org\apache\tomcat\embed\tomcat-embed-core\9.0.29\tomcat-embed-core-9.0.29.jar;D:\MyApplication\java_tool\maven_repository\m2\repository\org\apache\tomcat\embed\tomcat-embed-el\9.0.29\tomcat-embed-el-9.0.29.jar;D:\MyApplication\java_tool\maven_repository\m2\repository\org\apache\tomcat\embed\tomcat-embed-websocket\9.0.29\tomcat-embed-websocket-9.0.29.jar;D:\MyApplication\java_tool\maven_repository\m2\repository\org\springframework\boot\spring-boot-starter-validation\2.2.2.RELEASE\spring-boot-starter-validation-2.2.2.RELEASE.jar;D:\MyApplication\java_tool\maven_repository\m2\repository\jakarta\validation\jakarta.validation-api\2.0.1\jakarta.validation-api-2.0.1.jar;D:\MyApplication\java_tool\maven_repository\m2\repository\org\hibernate\validator\hibernate-validator\6.0.18.Final\hibernate-validator-6.0.18.Final.jar;D:\MyApplication\java_tool\maven_repository\m2\repository\org\jboss\logging\jboss-logging\3.4.1.Final\jboss-logging-3.4.1.Final.jar;D:\MyApplication\java_tool\maven_repository\m2\repository\com\fasterxml\classmate\1.5.1\classmate-1.5.1.jar;D:\MyApplication\java_tool\maven_repository\m2\repository\org\springframework\spring-web\5.2.2.RELEASE\spring-web-5.2.2.RELEASE.jar;D:\MyApplication\java_tool\maven_repository\m2\repository\org\springframework\spring-beans\5.2.2.RELEASE\spring-beans-5.2.2.RELEASE.jar;D:\MyApplication\java_tool\maven_repository\m2\repository\org\springframework\spring-webmvc\5.2.2.RELEASE\spring-webmvc-5.2.2.RELEASE.jar;D:\MyApplication\java_tool\maven_repository\m2\repository\org\springframework\spring-aop\5.2.2.RELEASE\spring-aop-5.2.2.RELEASE.jar;D:\MyApplication\java_tool\maven_repository\m2\repository\org\springframework\spring-context\5.2.2.RELEASE\spring-context-5.2.2.RELEASE.jar;D:\MyApplication\java_tool\maven_repository\m2\repository\org\springframework\spring-expression\5.2.2.RELEASE\spring-expression-5.2.2.RELEASE.jar;D:\MyApplication\java_tool\maven_repository\m2\repository\org\slf4j\slf4j-api\1.7.29\slf4j-api-1.7.29.jar;D:\MyApplication\java_tool\maven_repository\m2\repository\org\springframework\spring-core\5.2.2.RELEASE\spring-core-5.2.2.RELEASE.jar;D:\MyApplication\java_tool\maven_repository\m2\repository\org\springframework\spring-jcl\5.2.2.RELEASE\spring-jcl-5.2.2.RELEASE.jar jsd_network.Application

  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::        (v2.2.2.RELEASE)

2022-09-08 14:30:43.979  INFO 75292 --- [           main] jsd_network.Application                  : Starting Application on SK-20210717IEII with PID 75292 (D:\MyApplication\www\java_wwwroot_idea\jsd_network\target\classes started by Administrator in D:\MyApplication\www\java_wwwroot_idea\jsd_network)
2022-09-08 14:30:43.983  INFO 75292 --- [           main] jsd_network.Application                  : No active profile set, falling back to default profiles: default
2022-09-08 14:30:44.868  INFO 75292 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat initialized with port(s): 8080 (http)
2022-09-08 14:30:44.875  INFO 75292 --- [           main] o.apache.catalina.core.StandardService   : Starting service [Tomcat]
2022-09-08 14:30:44.875  INFO 75292 --- [           main] org.apache.catalina.core.StandardEngine  : Starting Servlet engine: [Apache Tomcat/9.0.29]
2022-09-08 14:30:44.941  INFO 75292 --- [           main] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring embedded WebApplicationContext
2022-09-08 14:30:44.941  INFO 75292 --- [           main] o.s.web.context.ContextLoader            : Root WebApplicationContext: initialization completed in 847 ms
2022-09-08 14:30:45.059  INFO 75292 --- [           main] o.s.s.concurrent.ThreadPoolTaskExecutor  : Initializing ExecutorService 'applicationTaskExecutor'
2022-09-08 14:30:45.202  INFO 75292 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat started on port(s): 8080 (http) with context path ''
2022-09-08 14:30:45.204  INFO 75292 --- [           main] jsd_network.Application                  : Started Application in 1.854 seconds (JVM running for 3.736)
2022-09-08 14:31:05.923  INFO 75292 --- [nio-8080-exec-1] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring DispatcherServlet 'dispatcherServlet'
2022-09-08 14:31:05.923  INFO 75292 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet        : Initializing Servlet 'dispatcherServlet'
2022-09-08 14:31:05.927  INFO 75292 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet        : Completed initialization in 4 ms

打开浏览器访问 http://localhost:8080/hello 就可以看到返回的json数据。

你可能感兴趣的:(spring,boot,maven,intellij-idea)