入坑JAVA,学习记录一下
java环境搭建可参考链接
https://www.cnblogs.com/daxiong2014/p/4334530.html
重新安装JAVA jdk后无法打开eclipse IDE编辑器解决方案
编辑D:\install\java\eclipse\eclipse.ini文件,
-vm D:\install\jdk12.0.1\bin
修改为
-vm C:\Program Files\Java\jdk-11\bin
jdk11配置环境变量
JAVA_HOME C:\Program Files\Java\jdk-11(JDK安装目录) PATH 添加 %JAVA_HOME%\bin; |
jdk8添加环境变量
JAVA_HOME C:\Program Files\Java\jdk1.8.0 PATH 添加 %JAVA_HOME%\bin;%JAVA_HOME%\jre8\bin; |
javac常用命令
用法: javac
①MyProgram.java文件
②使用javac命令,编译器compiler将源文件编译为字节码class文件
③使用java命令,通过解释器将字节码文件转为可执行程序
java中,单引号和双引号注意事项:
单引号只能对单个字符使用,比如 ‘a’ ‘b’ ‘c’
多个字符必须双引号”abc”
System.out.println(‘Hello World!’)报错如下:
d:\Myprogram.java:3: 错误: 未结束的字符文字
System.out.println(‘Hello World!’);
MyProgram.class字节码文件
java myprogram
错误: 找不到或无法加载主类 myprogram
原因: java.lang.NoClassDefFoundError: MyProgram (wrong name: myprogram)
java MyProgram才能正常运行~~~
综上,java命令,必须不带文件后缀,大小写必须一致。
坑:The project was not built due to “release 11 is not found in the system”. Fix the problem, then try refreshing this project and building it since it may be inconsistent
解决方案:create a java project=》选择合适的JRE
坑:Errors occurred during the build.Errors running builder ‘Java Builder’ on project ‘study’.
java.lang.NullPointerException
解决方案:删除src下的module-info.java文件
JDK12安装
使用jdk12 https://www.oracle.com/technetwork/java/javase/downloads/jdk12-downloads-5295953.html
环境变量PATH添加C:\Program Files\Java\jdk-12.0.1\bin,即可执行java -version命令。
启动tomcat服务器方式①
①下载apache-tomcat
②切换到E:\apache-tomcat-9.0.20-windows-x64\apache-tomcat-9.0.20\bin下,然后执行startup命令
打开tomcat中文乱码,解决方案如下:
打开E:\apache-tomcat-9.0.20-windows-x64\apache-tomcat-9.0.20\conf\logging.properties,在50行左右,将java.util.logging.ConsoleHandler.encoding = UTF-8修改为java.util.logging.ConsoleHandler.encoding = GBK。
③浏览器中输入http://localhost:8080/,则tomcat启动成功。
关闭tomcat服务器
E:\apache-tomcat-9.0.20-windows-x64\apache-tomcat-9.0.20\bin>shutdown Using CATALINA_BASE: "E:\apache-tomcat-9.0.20-windows-x64\apache-tomcat-9.0.20" Using CATALINA_HOME: "E:\apache-tomcat-9.0.20-windows-x64\apache-tomcat-9.0.20" Using CATALINA_TMPDIR: "E:\apache-tomcat-9.0.20-windows-x64\apache-tomcat-9.0.20\temp" Using JRE_HOME: "C:\Program Files\Java\jdk-12.0.1" Using CLASSPATH: "E:\apache-tomcat-9.0.20-windows-x64\apache-tomcat-9.0.20\bin\bootstrap.jar;E:\apache-tomcat-9.0.20-windows-x64\apache-tomcat-9.0.20\bin\tomcat-juli.jar" NOTE: Picked up JDK_JAVA_OPTIONS: --add-opens=java.base/java.lang=ALL-UNNAMED --add-opens=java.base/java.io=ALL-UNNAMED --add-opens=java.rmi/sun.rmi.transport=ALL-UNNAMED |
修改tomcat端口号
打开E:\apache-tomcat-9.0.20-windows-x64\apache-tomcat-9.0.20\conf\server.xml文件,修改Connector的port属性,如下将端口改为8090:
<Connector port="8090" protocol="HTTP/1.1" connectionTimeout="20000" redirectPort="8443" URIEncoding="UTF-8"/> |
启动tomcat服务器方式②
①打开E:\apache-tomcat-9.0.20-windows-x64\apache-tomcat-9.0.20\bin\startup.bat文件,然后可以看到下边一句话:
if exist "%CATALINA_HOME%\bin\catalina.bat" goto okHome |
设置环境变量变量名为CATALINA_HOME,变量值为E:\apache-tomcat-9.0.20-windows-x64\apache-tomcat-9.0.20。CMD中输入CATALINA,
E:\apache-tomcat-9.0.20-windows-x64\apache-tomcat-9.0.20\bin>CATALINA Using CATALINA_BASE: "E:\apache-tomcat-9.0.20-windows-x64\apache-tomcat-9.0.20" Using CATALINA_HOME: "E:\apache-tomcat-9.0.20-windows-x64\apache-tomcat-9.0.20" Using CATALINA_TMPDIR: "E:\apache-tomcat-9.0.20-windows-x64\apache-tomcat-9.0.20\temp" Using JRE_HOME: "C:\Program Files\Java\jdk-12.0.1" Using CLASSPATH: "E:\apache-tomcat-9.0.20-windows-x64\apache-tomcat-9.0.20\bin\bootstrap.jar;E:\apache-tomcat-9.0.20-windows-x64\apache-tomcat-9.0.20\bin\tomcat-juli.jar" Usage: catalina ( commands ... ) commands: debug Start Catalina in a debugger debug -security Debug Catalina with a security manager jpda start Start Catalina under JPDA debugger run Start Catalina in the current window run -security Start in the current window with security manager start Start Catalina in a separate window start -security Start in a separate window with security manager stop Stop Catalina configtest Run a basic syntax check on server.xml version What version of tomcat are you running? |
②任意目录执行catalina start(或者startup)命令,即可开启tomcat服务器,catalina stop(shutdown)即可停止tomcat服务器。
eclipse httpservlet不存在
解决方法路径
https://www.cnblogs.com/xlflove/p/9252237.html
查看开启了哪些端口
C:\Users\Dell>netstat -a
Active Connections
Proto Local Address Foreign Address State
TCP 0.0.0.0:135 account:0 LISTENING
TCP 0.0.0.0:445 account:0 LISTENING
TCP 0.0.0.0:5040 account:0 LISTENING
TCP 0.0.0.0:7680 account:0 LISTENING
TCP 0.0.0.0:9312 account:0 LISTENING
TCP 0.0.0.0:49664 account:0 LISTENING
TCP 0.0.0.0:49665 account:0 LISTENING
TCP 0.0.0.0:49666 account:0 LISTENING
TCP 0.0.0.0:49667 account:0 LISTENING
TCP 0.0.0.0:49668 account:0 LISTENING
TCP 0.0.0.0:49669 account:0 LISTENING
TCP 127.0.0.1:6379 account:0 LISTENING
TCP 127.0.0.1:28317 account:0 LISTENING
TCP 192.168.1.125:139 account:0 LISTENING
TCP 192.168.1.125:52207 163.177.81.141:http ESTABLISHED
查看占用端口的进程
1:协议 2:本地地址 3: 外部地址 4: 状态 5: PID
C:\Users\Dell>netstat -ano | findstr 8080
TCP 0.0.0.0:8080 0.0.0.0:0 LISTENING 5520
TCP [::]:8080 [::]:0 LISTENING 5520