IDEA快速创建java demo项目
Posted gsls200808
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了IDEA快速创建java demo项目相关的知识,希望对你有一定的参考价值。
有时候我们需要快速验证某些功能,写TestUnit跑起来麻烦,在类里直接写main方法有时候忘记删除影响团队维护。
一、IDEA创建普通java项目
File-->New-->Project

Java-->Next

勾选 Create project from template

填写项目名 路径 包名,点击Finish
有时我们会引用第三方jar
新建目录lib -->lib目录右键 -->Mark Dictory as-->Resources Root
二、IDEA创建普通maven项目
File-->New-->Project

选择 Maven,勾选右侧Create from archetype,选择maven-archetype-quickstart

填写名称和位置,点击Next

配置maven选项,点击finish

界面会生成一个几乎不含任何依赖的maven项目,自己调整dependency和jdk版本即可使用。
如果maven项目需要引用不在中央仓库或者私有仓库的jar,比如oracle高版本jdbc驱动,也可以新建lib目录引用,这里以RXTXcomm.jar为例
依赖写
<dependency>
<groupId>gnu.io</groupId>
<artifactId>RXTXcomm</artifactId>
<scope>system</scope>
<systemPath>$project.basedir/lib/RXTXcomm.jar</systemPath>
<version>2.0</version>
</dependency>
web项目maven打包war插件写
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<configuration>
<webResources>
<resource>
<directory>$project.basedir/lib</directory>
<targetPath>WEB-INF/lib/</targetPath>
<includes>
<include>**/*.jar</include>
</includes>
</resource>
</webResources>
</configuration>
</plugin>
三、IDEA创建普通springboot项目
File-->New-->Project

选择Spring Initializr,点击Next
如果这里spring.io无法访问,选择Customer后可以填写下面几个网址。
阿里云:https://start.aliyun.com(springboot版本2.1.17-2.4.1)
kenvie.com:https://start.kenvie.com(springboot版本2.5.14-3.0.0)
springboot.io:https://start.springboot.io(springboot版本2.5.14-3.0.0)

type 选maven
package 选jar,如果要在tomcat里运行选war,war是传统模式
java版本选8,如果要用新版spring boot3 选17

依赖选Lombok和Spring Web,点击Next

填写项目名和路径

默认生成的项目结构如图

选war生成的结构如图,比jar多一个ServletInitializer类,并且maven里的默认打包方式也不一样。
以上是关于IDEA快速创建java demo项目的主要内容,如果未能解决你的问题,请参考以下文章
使用 IDEA + Maven + Git 快速开发 JAVA或者Web 应用(转)
Java Web项目的创建——IDEA+Maven+Tomcat