如何为Spring Boot内嵌Tomcat配置指定环境参数(Eclipse运行场景)
Hey there! Since you're running your Spring Boot app directly via its main class in Eclipse (not deploying to a standalone Tomcat instance), we'll need to translate those shell script parameters into Eclipse's run configuration settings. Here's how to do it step by step:
1. Set Up the Correct JDK (JAVA_HOME)
First, ensure Eclipse uses your specified JDK:
- Open
Window > Preferences > Java > Installed JREs - Click
Add, chooseStandard VM, then browse to/usr/local/java/jdkto add this JDK to Eclipse's list - Either set it as the default JRE (check the box next to it) or assign it specifically to your app's run config (we can adjust this in the next step if needed)
2. Combine & Add VM Arguments
In your shell script, JAVA_OPTS and CATALINA_OPTS both contain JVM flags. Since we're running via the main class, we can merge all these into Eclipse's VM arguments section:
- Right-click your
StructuredInterviewingApplicationclass →Run As > Run Configurations - Select your existing Java Application run config (or create a new one if you don't have it set up)
- Switch to the
Argumentstab - In the VM arguments box, paste this (I fixed the extra space in
- Dsun.security.jgss.liband removed the quotes since Eclipse doesn't require them):-d64 -XX:MaxPermSize=256M -jcifs.http.domainController=dc.nc.example.com -Dspring.profiles.active=hcServiceDev,authDev -Dsun.security.jgss.native=true -Dsun.security.jgss.lib=/usr/local/libexec/libjgssfix.so -Duser.timezone=GMT - Optional: If you didn't set the JDK as default earlier, go to the
JREtab in the run config and select your/usr/local/java/jdkfrom the dropdown menu - Click
ApplythenRunto launch the app with these settings
3. Verify the Settings Are Applied
To double-check that all parameters are working as expected, you can add a quick debug line to your main class:
import java.lang.management.ManagementFactory; import java.util.Arrays; @SpringBootApplication public class StructuredInterviewingApplication { public static void main(String[] args) { // Print all VM arguments to the console for verification System.out.println("Applied VM Arguments: " + Arrays.toString(ManagementFactory.getRuntimeMXBean().getInputArguments())); SpringApplication.run(StructuredInterviewingApplication.class, args); } }
When you run the app, check the console output—you should see all your configured flags listed there.
A quick side note: -XX:MaxPermSize is only relevant for Java 8 and older versions. If you're using Java 9+, this flag will be ignored (since PermGen was replaced with Metaspace), but it won't cause any issues to leave it in your configuration.
内容的提问来源于stack exchange,提问作者ThinkGeek

