Reason:
JAVA_OPTS is only valid for web server middleware such as tomcat/weblogic, and it will not read JAVA_OPTS if it runs in the "java -cp [*.jar] test.Main" mode, so an error will be reported when the relevant file is executed through java -cp.
JAVA_OPTS is configured in the tomcat/bin/catalina.sh or tomcat/bin/catalina.bat file, which can configure the startup parameters of the java process virtual machine.
Solution:
1. If you need to set Heap Size while running java class, you need the following method:
java -Xmx2048m -jar test.jar
or
java -Xmx1024m -cp douglas.jar com.douglas.Main
2. If it is on Unix or Linux server, you can write the following statement directly
#系统环境变量,单独执行一次即可
export JAVA_OPTS=-Xmx1024m -Djava.awt.headless=true
#执行文件
java $JAVA_OPTS -cp douglas.jar com.douglas.Main
3. Start the script file test.sh and write:
#!/bin/sh
classpath=./douglas.jar
/usr/java5/bin/java -Xmx1024M -cp $classpath com.douglas.Main
4. It can also be executed in the background through nohup and output log commands
#后台进程执行命令
nohup java $JAVA_OPTS -cp "xxx.jar" com.douglas.Main >> catalina.out 2>&1 &
Reference:
https://www.cnblogs.com/pachongshangdexuebi/p/5583365.html