900字范文,内容丰富有趣,生活中的好帮手!
900字范文 > javaee-教程直播-16Windows 平台 JavaEE 基本开发环境搭建-JDK-eclipse-tomcat-maven

javaee-教程直播-16Windows 平台 JavaEE 基本开发环境搭建-JDK-eclipse-tomcat-maven

时间:2023-11-13 20:08:12

相关推荐

javaee-教程直播-16Windows 平台 JavaEE 基本开发环境搭建-JDK-eclipse-tomcat-maven

Windows 平台 JavaEE 基本开发环境搭建

1 安装JDK

1.1下载

地址 /technetwork/java/javase/downloads/index。

直接官网下载安装,注意版本对应,如果是老机器,要注意下载以应的x86而不是x64版本。

1.2 安装 JDK

运行安装包,一路 next, 中途可选择安装路径和内容,如果只是纯开发,可以不装 Public JRE。

1.3 设置系统变量

在用户变量处新增一个 JAVA_HOME 变量,值为 JDK 的安装路径;

在用户变量的 Path 变量的值新增 %JAVA_HOMR%/bin。

1.4 测试

运行 cmd, 输入 java -version, 如果能正确显示相关信息,表明安装成功。

2. 安装 Eclipse

2.1 下载 Eclipse

地址 /downloads/eclipse-packages/

要注意下载的版本

是进行javaee下载,因此是带了jee插件的eclipse

2.2 安装 Eclipse

把压缩包的内容解压到一个你平常放软件的路径,最好不要有中文、空格或特殊字符,然后新建一个 eclipse.exe 的快捷方式方便运行就可以了。

2.3 Eclipse 简单配置

第一次运行 Eclipse 会让你设定一个工作空间的路径,选择一个你打算存放项目的路径,然后还可以勾选默认,这样就不用每次运行都要选择一次工作空间了。

2.4 设置

点击 Window - Preferences - General - Workspace, 把 Text file encoding 改为 UTF-8, 把 New text file line delimiter 改为 unixWindow - Preferences - Java - Formatter, 点击 Edit…, Tab policy 改为 Space only, Indentation size 和 Tab size 改为 2, 自定义 Profile name, Apply

Window - Preferences - XML - XML Files - Editor, 选择 Indent using spaces, Indentation size 改为 2

检查 Window - Preferences - Java 里的 Compiler 和 Installed JREs, 确认 JDK 已被正确配置。

2.5 测试

最后写个简单的 Hello World 跑一下,没问题就可以了。

2.6 其他个人习惯设置

2.6.1 外置浏览器,建议用chrome方便前端调试

2.6.2 编码统一设置

统一都设置为UTF-8

2.6.3 Eclipse将换行符统一设置成Linux风格

然后Windows -> Preference -> General -> Editors -> Text Editors:

然后勾选Show whitespace characters复选框。

OK,这样结合之前对Git的设置,这样就可以保证你的代码不会因为换行符转换给你添麻烦啦。不断积累软件的使用技巧,让我们的工具变得更智能,更懂你的心。

3. 安装 Tomcat

3.1 下载 Tomcat

地址 /

/download-90.cgi

国内,建议用镜像站点的资源,效率要高一些。

3.2 安装 Tomcat

把压缩包的内容解压到一个你喜欢的路径,不要有中文、空格或特殊字符,路径不要深。

3.2.1系统配置-环境变量

在系统变量中添加以下变量

(1)TOMCAT_HOME,该变量指向解压文件的路径,该目录下有lib、bin等文件夹。添加方法如下:

点击环境变量下的“新建”,在“变量名”中填写“TOMCAT_HOME”,在“变量值”中填写解压文件的路径,

D:\Tomcat\apache-tomcat-9.0.0.M1-windows-x64\apache-tomcat-9.0.0.M1

(后面没有分号)然后点击“确定”,如图

(2)CATALINA_HOME,该变量的值与TOMCAT_HOME相同,设置方法同(1),如图

(3)在“系统变量”中找到Path变量,双击打开Path变量,在“变量值”的最后面添加

%CATALINA_HOME%\bin

(后面没有分号),如图

如果是win10,就直接添加相应的项即可。

平时的开发环境,搭建到这一步即可

3.2.2 如果要搭建成服务

(4)在“系统变量”中找到CLASSPath变量,双击打开CLASSPath变量,在“变量值”的最后面添加

%CATALINA_HOME%\lib\servlet-api.jar

(后面没有分号),如图

5、单击“开始”—“运行”,键入"cmd",在控制台输入service install Tomcat9,

在系统中安装Tomcat9服务项。

然后进入控制面板—系统和安全—管理工具—服务,找到Apache Tomcat Tomcat9服务项,右击该项,点“启动”,启动该服务,如图

6、打开浏览器,地址栏输入http://localhost:8080或 http://127.0.0.1:8080

如果出现tomcat示例主页,则表示服务器安装成功,如图

如果8080端口被占用了,可以修改tomcat的访问端口,方法如下:找到D:\Tomcat\apache-tomcat-9.0.0.M1-windows-x64\apache-tomcat-9.0.0.M1\conf目录下的server.xml文件,打开该文件,找到以下内容

注:每次需要启动tomcat服务器都要运行startup.bat文件。如果觉得麻烦可以把服务里启动类型设置为自动。但这样开机速度会慢些。

安装Apache Tomcat9.0的前提是必须安装JDK,如果没有安装JDK的用户可以点击下载jdk1.8.0_77(32/64位)

3.2.3 win10配置环境变量

这个步骤网上叫教程有很多不同版本,本人尝试很多种不行后,以下是亲测有效的。

Step1:右键 “此电脑”(如果Win10桌面没有,请百度),点击"属性",点击"高级系统设置"—>“高级”—>“环境变量”。

Step2:配置jdk的环境变量(略)

Step3:在"系统变量"里新建变量名:CATALINA_BASE,变量值:D:\JavaEE\apache-tomcat-9.0.8(此处为你的解压包路径)

Step4:在"系统变量"里新建变量名:CATALINA_HOME,变量值:D:\JavaEE\apache-tomcat-9.0.8

Step5:在"系统变量"里打开Path变量,添加变量值:%CATALINA_HOME%\lib;%CATALINA_HOME%\bin(这一步可有可无,有些电脑无需配置此步骤便可完成,因此可以先跳过Step5)

示例图如下:按顺序1,2,3执行。

按图标记顺序1,2,3配置

Step6:Win+R,输入cmd,按Enter,进入命令行界面。

进入tomcat下的bin目录(本人电脑的路径为D:\JavaEE\apache-tomcat-9.0.8\bin),执行“service.bat install” 。(附:service卸载命令:service.bat remove)

3.3 测试

打开安装路径,运行 bin - startup.bat, 然后打开一个你喜欢的浏览器,输入地址 localhost:8080

, 如果能显示经典的 Tomcat 小猫,就说明安装成功了,测试完成后记得运行 shutdown.bat 结束服务器。

不要关闭这个窗口

3.4 tomcat简单配置

打开安装路径 - conf - server.xml,在 标签里添加 URIEncoding=UTF-8,这样可以解决 get 请求的 URI 中文乱码问题,还有,如果不想用 8080 端口,直接修改 port 为你想设的端口就可以了。

3.5 在eclipse中配置

打开 Eclipse, 点击 Window - Preferences - Server - Runtime Environments, 点击 Add…, 选择 Apache Tomcat v8.5, next, 改一个喜欢的名字,选择 Tomcat 安装路径,最后 finish。

选择主界面的 Servers 标签页,点击 …create a new server…, 给服务器改个喜欢的名字,选择上一步配置的环境,finish。

双击刚创建的服务器,选择 Server Locations 为 Use Tomcat installation, 并把 Deploy path 配置为 webapps,这样每次运行 Tomcat 都会把项目发布到 Tomcat 的 webapps 目录。

点击 Window - Preferences - Web - JSP Files, Encoding 一项选择 UTF-8, 这样每次新建的 JSP 页就默认都是 UTF-8 编码了。

4. 配置和试用maven

4.1 maven版本更新

可以用eclipse已经安装好的插件版本,也可以自己更新成相应的版本。

内嵌的maven如下,版本是3.6.1,可以使用这个版本。

4.2 仓库配置文件

settings.xml文件

<?xml version="1.0" encoding="UTF-8"?><!--Licensed to the Apache Software Foundation (ASF) under oneor more contributor license agreements. See the NOTICE filedistributed with this work for additional informationregarding copyright ownership. The ASF licenses this fileto you under the Apache License, Version 2.0 (the"License"); you may not use this file except in compliancewith the License. You may obtain a copy of the License at/licenses/LICENSE-2.0Unless required by applicable law or agreed to in writing,software distributed under the License is distributed on an"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANYKIND, either express or implied. See the License for thespecific language governing permissions and limitationsunder the License.--><!--| This is the configuration file for Maven. It can be specified at two levels:|| 1. User Level. This settings.xml file provides configuration for a single user,| and is normally provided in ${user.home}/.m2/settings.xml.|| NOTE: This location can be overridden with the CLI option:|| -s /path/to/user/settings.xml|| 2. Global Level. This settings.xml file provides configuration for all Maven| users on a machine (assuming they're all using the same Maven| installation). It's normally provided in| ${maven.conf}/settings.xml.|| NOTE: This location can be overridden with the CLI option:|| -gs /path/to/global/settings.xml|| The sections in this sample file are intended to give you a running start at| getting the most out of your Maven installation. Where appropriate, the default| values (values used when the setting is not specified) are provided.||--><settings xmlns="/SETTINGS/1.0.0"xmlns:xsi="/2001/XMLSchema-instance"xsi:schemaLocation="/SETTINGS/1.0.0 /xsd/settings-1.0.0.xsd"><!-- localRepository| The path to the local repository maven will use to store artifacts.|| Default: ${user.home}/.m2/repository<localRepository>/path/to/local/repo</localRepository>--><!-- interactiveMode| This will determine whether maven prompts you when it needs input. If set to false,| maven will use a sensible default value, perhaps based on some other setting, for| the parameter in question.|| Default: true<interactiveMode>true</interactiveMode>--><!-- offline| Determines whether maven should attempt to connect to the network when executing a build.| This will have an effect on artifact downloads, artifact deployment, and others.|| Default: false<offline>false</offline>--><!-- pluginGroups| This is a list of additional group identifiers that will be searched when resolving plugins by their prefix, i.e.| when invoking a command line like "mvn prefix:goal". Maven will automatically add the group identifiers| "org.apache.maven.plugins" and "org.codehaus.mojo" if these are not already contained in the list.|--><pluginGroups><!-- pluginGroup| Specifies a further group identifier to use for plugin lookup.<pluginGroup>com.your.plugins</pluginGroup>--></pluginGroups><!-- proxies| This is a list of proxies which can be used on this machine to connect to the network.| Unless otherwise specified (by system property or command-line switch), the first proxy| specification in this list marked as active will be used.|--><proxies><!-- proxy| Specification for one proxy, to be used in connecting to the network.|<proxy><id>optional</id><active>true</active><protocol>http</protocol><username>proxyuser</username><password>proxypass</password><host></host><port>80</port><nonProxyHosts>|</nonProxyHosts></proxy>--></proxies><!-- servers| This is a list of authentication profiles, keyed by the server-id used within the system.| Authentication profiles can be used whenever maven must make a connection to a remote server.|--><servers><!-- server| Specifies the authentication information to use when connecting to a particular server, identified by| a unique name within the system (referred to by the 'id' attribute below).|| NOTE: You should either specify username/password OR privateKey/passphrase, since these pairings are| used together.|<server><id>deploymentRepo</id><username>repouser</username><password>repopwd</password></server>--><!-- Another sample, using keys to authenticate.<server><id>siteServer</id><privateKey>/path/to/private/key</privateKey><passphrase>optional; leave empty if not used.</passphrase></server>--></servers><!-- mirrors| This is a list of mirrors to be used in downloading artifacts from remote repositories.|| It works like this: a POM may declare a repository to use in resolving certain artifacts.| However, this repository may have problems with heavy traffic at times, so people have mirrored| it to several places.|| That repository definition will have a unique id, so we can create a mirror reference for that| repository, to be used as an alternate download site. The mirror site will be the preferred| server for that repository.|--><mirrors><!-- mirror| Specifies a repository mirror site to use instead of a given repository. The repository that| this mirror serves has an ID that matches the mirrorOf element of this mirror. IDs are used| for inheritance and direct lookup purposes, and must be unique across the set of mirrors.|<mirror><id>mirrorId</id><mirrorOf>repositoryId</mirrorOf><name>Human Readable Name for this Mirror.</name><url>/repo/path</url></mirror>--><mirror><id>alimaven</id><mirrorOf>central</mirrorOf><name>aliyun maven</name><url>/nexus/content/groups/public</url></mirror><mirror> <id>CN</id> <name>OSChina Central</name> <url>/content/groups/public/</url> <mirrorOf>central</mirrorOf> </mirror><mirror><id>repo2</id><name>Mirror from Maven Repo2</name><url>/maven2/</url><mirrorOf>central</mirrorOf></mirror></mirrors><!-- profiles| This is a list of profiles which can be activated in a variety of ways, and which can modify| the build process. Profiles provided in the settings.xml are intended to provide local machine-| specific paths and repository locations which allow the build to work in the local environment.|| For example, if you have an integration testing plugin - like cactus - that needs to know where| your Tomcat instance is installed, you can provide a variable here such that the variable is| dereferenced during the build process to configure the cactus plugin.|| As noted above, profiles can be activated in a variety of ways. One way - the activeProfiles| section of this document (settings.xml) - will be discussed later. Another way essentially| relies on the detection of a system property, either matching a particular value for the property,| or merely testing its existence. Profiles can also be activated by JDK version prefix, where a| value of '1.4' might activate a profile when the build is executed on a JDK version of '1.4.2_07'.| Finally, the list of active profiles can be specified directly from the command line.|| NOTE: For profiles defined in the settings.xml, you are restricted to specifying only artifact| repositories, plugin repositories, and free-form properties to be used as configuration| variables for plugins in the POM.||--><profiles><!-- profile| Specifies a set of introductions to the build process, to be activated using one or more of the| mechanisms described above. For inheritance purposes, and to activate profiles via <activatedProfiles/>| or the command line, profiles have to have an ID that is unique.|| An encouraged best practice for profile identification is to use a consistent naming convention| for profiles, such as 'env-dev', 'env-test', 'env-production', 'user-jdcasey', 'user-brett', etc.| This will make it more intuitive to understand what the set of introduced profiles is attempting| to accomplish, particularly when you only have a list of profile id's for debug.|| This profile example uses the JDK version to trigger activation, and provides a JDK-specific repo.<profile><id>jdk-1.4</id><activation><jdk>1.4</jdk></activation><repositories><repository><id>jdk14</id><name>Repository for JDK 1.4 builds</name><url>/maven/jdk14</url><layout>default</layout><snapshotPolicy>always</snapshotPolicy></repository></repositories></profile>--><!--| Here is another profile, activated by the system property 'target-env' with a value of 'dev',| which provides a specific path to the Tomcat instance. To use this, your plugin configuration| might hypothetically look like:|| ...| <plugin>| <groupId>org.myco.myplugins</groupId>| <artifactId>myplugin</artifactId>|| <configuration>|<tomcatLocation>${tomcatPath}</tomcatLocation>| </configuration>| </plugin>| ...|| NOTE: If you just wanted to inject this configuration whenever someone set 'target-env' to| anything, you could just leave off the <value/> inside the activation-property.|<profile><id>env-dev</id><activation><property><name>target-env</name><value>dev</value></property></activation><properties><tomcatPath>/path/to/tomcat/instance</tomcatPath></properties></profile>--></profiles><!-- activeProfiles| List of profiles that are active for all builds.|<activeProfiles><activeProfile>alwaysActiveProfile</activeProfile><activeProfile>anotherAlwaysActiveProfile</activeProfile></activeProfiles>--></settings>

4.3 更新eclipse里的maven设置

4.4 试建helloworld的maven项目

耐心等待一下,就可以得到对应的项目结构了,如下

设置项目,排除错误

右键项目,选择properties

更新jre版本

添加Server Runtime

4.5 更新后的maven项目结构

4.6 查看pom.xml文件

<project xmlns="/POM/4.0.0" xmlns:xsi="/2001/XMLSchema-instance"xsi:schemaLocation="/POM/4.0.0 /maven-v4_0_0.xsd"><modelVersion>4.0.0</modelVersion><groupId>cn.edu.cuit</groupId><artifactId>j001001-maven01project</artifactId><packaging>war</packaging><version>0.0.1-SNAPSHOT</version><name>j001001-maven01project Maven Webapp</name><url></url><dependencies><dependency><groupId>junit</groupId><artifactId>junit</artifactId><version>3.8.1</version><scope>test</scope></dependency></dependencies><build><finalName>j001001-maven01project</finalName></build></project>

4.7 查看web.xml文件

<!DOCTYPE web-app PUBLIC"-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN""/dtd/web-app_2_3.dtd" ><web-app><display-name>Archetype Created Web Application</display-name></web-app>

4.8 查看index.jsp文件

<html><body><h2>Hello World!</h2></body></html>

右键,启动on Server项目

在浏览器中查看到结果

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。