Java是一种通用的,基于类的,面向对象的编程语言。它是用于应用程序开发的计算平台。因此,Java是快速,安全和可靠的。它被广泛用于在笔记本电脑,数据中心,游戏机,科学超级计算机,手机等中开发Java应用程序。Java遵循WORA(Write Once, Run Anywhere。一次写入,到处运行)的原理,并且与平台无关。它也简单易学。
查找
java 11版本使用较多,搜索java 11版本安装
[root@iZ2zee2m456rb6bde98jpkZ ~]# dnf search java-11
Last metadata expiration check: 0:33:04 ago on Wed 29 Jun 2022 10:47:19 AM CST.
====================================================================== Name Matched: java-11 ======================================================================
java-11-openjdk.x86_64 : OpenJDK 11 Runtime Environment
java-11-openjdk-demo.x86_64 : OpenJDK 11 Demos
java-11-openjdk-demo-fastdebug.x86_64 : OpenJDK 11 Demos optimised with full debugging on
java-11-openjdk-demo-slowdebug.x86_64 : OpenJDK 11 Demos unoptimised with full debugging on
java-11-openjdk-devel.x86_64 : OpenJDK 11 Development Environment
java-11-openjdk-devel-fastdebug.x86_64 : OpenJDK 11 Development Environment optimised with full debugging on
java-11-openjdk-devel-slowdebug.x86_64 : OpenJDK 11 Development Environment unoptimised with full debugging on
java-11-openjdk-fastdebug.x86_64 : OpenJDK 11 Runtime Environment optimised with full debugging on
java-11-openjdk-headless.x86_64 : OpenJDK 11 Headless Runtime Environment
java-11-openjdk-headless-fastdebug.x86_64 : OpenJDK 11 Runtime Environment optimised with full debugging on
java-11-openjdk-headless-slowdebug.x86_64 : OpenJDK 11 Runtime Environment unoptimised with full debugging on
java-11-openjdk-javadoc.x86_64 : OpenJDK 11 API documentation
java-11-openjdk-javadoc-zip.x86_64 : OpenJDK 11 API documentation compressed in a single archive
java-11-openjdk-jmods.x86_64 : JMods for OpenJDK 11
java-11-openjdk-jmods-fastdebug.x86_64 : JMods for OpenJDK 11 optimised with full debugging on
java-11-openjdk-jmods-slowdebug.x86_64 : JMods for OpenJDK 11 unoptimised with full debugging on
java-11-openjdk-slowdebug.x86_64 : OpenJDK 11 Runtime Environment unoptimised with full debugging on
java-11-openjdk-src.x86_64 : OpenJDK 11 Source Bundle
java-11-openjdk-src-fastdebug.x86_64 : OpenJDK 11 Source Bundle for packages with debugging on and optimisation
java-11-openjdk-src-slowdebug.x86_64 : OpenJDK 11 Source Bundle for packages with debugging on and no optimisation
java-11-openjdk-static-libs.x86_64 : OpenJDK 11 libraries for static linking
java-11-openjdk-static-libs-fastdebug.x86_64 : OpenJDK 11 libraries for static linking optimised with full debugging on
java-11-openjdk-static-libs-slowdebug.x86_64 : OpenJDK 11 libraries for static linking unoptimised with full debugging on
安装
使用dnf install 命令安装
[root@iZ2zee2m456rb6bde98jpkZ ~]# dnf install java-11-openjdk java-11-openjdk-devel
Last metadata expiration check: 0:34:34 ago on Wed 29 Jun 2022 10:47:19 AM CST.
Dependencies resolved.
===================================================================================================================================================================
Package Architecture Version Repository Size
===================================================================================================================================================================
Installing:
java-11-openjdk x86_64 1:11.0.15.0.9-2.al8 alinux3-updates 270 k
java-11-openjdk-devel x86_64 1:11.0.15.0.9-2.al8 alinux3-updates 3.4 M
Installing dependencies:
aajohan-comfortaa-fonts noarch 3.001-2.1.al8 alinux3-os 148 k
alsa-lib x86_64 1.2.4-5.1.al8 alinux3-updates 469 k
copy-jdk-configs noarch 4.0-2.al8 alinux3-updates 30 k
fontconfig x86_64 2.13.1-4.al8 alinux3-updates 276 k
fontpackages-filesystem noarch 1.44-22.1.al8 alinux3-os 16 k
giflib x86_64 5.1.4-3.2.al8 alinux3-os 52 k
graphite2 x86_64 1.3.10-10.2.al8 alinux3-os 120 k
harfbuzz x86_64 1.7.5-3.2.al8 alinux3-os 268 k
java-11-openjdk-headless x86_64 1:11.0.15.0.9-2.al8 alinux3-updates 40 M
javapackages-filesystem noarch 5.3.1-7.3.al8 alinux3-updates 32 k
lcms2 x86_64 2.9-2.2.al8 alinux3-os 165 k
libX11 x86_64 1.6.8-4.1.al8 alinux3-updates 612 k
libX11-common noarch 1.6.8-4.1.al8 alinux3-updates 158 k
libXau x86_64 1.0.9-3.1.al8 alinux3-os 38 k
libXcomposite x86_64 0.4.4-14.2.al8 alinux3-os 29 k
libXext x86_64 1.3.4-1.1.al8 alinux3-os 46 k
libXi x86_64 1.7.10-1.1.al8 alinux3-os 49 k
libXrender x86_64 0.9.10-7.2.al8 alinux3-os 33 k
libXtst x86_64 1.2.3-7.2.al8 alinux3-os 22 k
libfontenc x86_64 1.1.3-8.2.al8 alinux3-os 37 k
libjpeg-turbo x86_64 1.5.3-10.2.al8 alinux3-os 156 k
libxcb x86_64 1.13.1-1.3.al8 alinux3-os 230 k
lksctp-tools x86_64 1.0.18-3.2.al8 alinux3-os 101 k
lua x86_64 5.3.4-11.2.al8 alinux3-os 195 k
ttmkfdir x86_64 3.0.9-54.2.al8 alinux3-os 64 k
tzdata-java noarch 2022a-1.al8 alinux3-updates 191 k
xorg-x11-font-utils x86_64 1:7.5-40.2.al8 alinux3-os 104 k
xorg-x11-fonts-Type1 noarch 7.5-19.1.al8 alinux3-os 522 k
Transaction Summary
===================================================================================================================================================================
Install 30 Packages
Total download size: 47 M
配置java环境变量
[root@iZ2zee2m456rb6bde98jpkZ ~]# which java
/usr/bin/java
[root@iZ2zee2m456rb6bde98jpkZ ~]# ls -l /usr/bin/java
lrwxrwxrwx 1 root root 22 Jun 29 11:22 /usr/bin/java -> /etc/alternatives/java
[root@iZ2zee2m456rb6bde98jpkZ ~]# ls -l /etc/alternatives/java
lrwxrwxrwx 1 root root 62 Jun 29 11:22 /etc/alternatives/java -> /usr/lib/jvm/java-11-openjdk-11.0.15.0.9-2.al8.x86_64/bin/java
[root@iZ2zee2m456rb6bde98jpkZ ~]# echo "export JAVA_HOME=/usr/lib/jvm/java-11-openjdk-11.0.15.0.9-2.al8.x86_64/" >> .bashrc
[root@iZ2zee2m456rb6bde98jpkZ ~]# echo "export PATH=$JAVA_HOME/bin:$PATH" >> .bashrc
[root@iZ2zee2m456rb6bde98jpkZ ~]# source .bashrc
运行jar包
使用IDEA创建spring cloud项目
编译生成jar包,scp上传到ECS服务器
用java运行jar包
[root@iZ2zee2m456rb6bde98jpkZ ~]# java -jar demo1-0.0.1-SNAPSHOT.jar
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v2.7.1)
2022-06-29 11:30:32.062 INFO 15164 --- [ main] com.example.demo.Demo1Application : Starting Demo1Application v0.0.1-SNAPSHOT using Java 11.0.15 on iZ2zee2m456rb6bde98jpkZ with PID 15164 (/root/demo1-0.0.1-SNAPSHOT.jar started by root in /root)
2022-06-29 11:30:32.065 INFO 15164 --- [ main] com.example.demo.Demo1Application : No active profile set, falling back to 1 default profile: "default"
2022-06-29 11:30:32.920 INFO 15164 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 8080 (http)
2022-06-29 11:30:32.928 INFO 15164 --- [ main] o.apache.catalina.core.StandardService : Starting service [Tomcat]
2022-06-29 11:30:32.928 INFO 15164 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/9.0.64]
2022-06-29 11:30:32.978 INFO 15164 --- [ main] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2022-06-29 11:30:32.979 INFO 15164 --- [ main] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 859 ms
2022-06-29 11:30:33.282 INFO 15164 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port(s): 8080 (http) with context path ''
2022-06-29 11:30:33.297 INFO 15164 --- [ main] com.example.demo.Demo1Application : Started Demo1Application in 1.626 seconds (JVM running for 1.968)
2022-06-29 11:31:20.263 INFO 15164 --- [nio-8080-exec-1] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring DispatcherServlet 'dispatcherServlet'
2022-06-29 11:31:20.263 INFO 15164 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet : Initializing Servlet 'dispatcherServlet'
2022-06-29 11:31:20.265 INFO 15164 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet : Completed initialization in 2 ms
用浏览器打开ip:8080访问,可以看到提示错误信息,服务器是可以访问,是没有编写程序逻辑