Payara(GlassFish)服务器外置Domain可行性及配置路径咨询
Absolutely yes! You can move your Payara/GlassFish domains completely outside the Payara installation directory — this is actually a recommended best practice for exactly the scenario you described: avoiding domain configuration loss or conflicts during server upgrades. Below is a step-by-step guide to make this work:
一、First, manually migrate your existing Domain folders
- Stop all running domains first to avoid file locks:
asadmin stop-domain domain1 asadmin stop-domain payaraDomain - Copy the entire domain folders (like
payara/glassfish/domains/domain1andpayara/glassfish/domains/payaraDomain) to your external target directory, e.g.,/opt/payara-domains/. Make sure to preserve the original file permissions to avoid startup permission issues later. - You can delete the original domain folders under the Payara installation directory (or back them up first to prevent accidental misloading).
二、Configure Payara to point to the external Domain location
There are two common methods to specify the external domain path — pick the one that fits your workflow:
Method 1: Specify the domain path via asadmin command on startup
Each time you start a domain, use the --domaindir parameter to point to the external directory:
asadmin start-domain --domaindir /opt/payara-domains/ domain1 asadmin start-domain --domaindir /opt/payara-domains/ payaraDomain
This method is great for temporary testing or if you don't want to modify global configurations.
Method 2: Modify global config to permanently set the default domain directory
If you want all asadmin commands to automatically read domains from the external directory by default:
- Locate the configuration file:
glassfish/config/asenv.conf(Linux/macOS) orglassfish/config/asenv.bat(Windows) in your Payara installation folder. - Add or modify the following line:
- For Linux/macOS:
AS_DOMAINS_DIR=/opt/payara-domains/ - For Windows:
set AS_DOMAINS_DIR=C:\payara-domains\
- For Linux/macOS:
- After saving the config, all subsequent
asadmincommands (likestart-domain,list-domains) will default to the external directory, no need to specify the parameter every time.
三、Verify the configuration works
- Run
asadmin list-domains— you should seedomain1andpayaraDomainfrom the external directory, marked asnot running. - Start one domain (e.g.,
asadmin start-domain domain1) and check if the server launches successfully. Test your application to confirm everything works as expected. - Now you can safely upgrade Payara: just replace the original installation directory files. The external domains won't be touched at all, and you can start them with the same configuration after the upgrade.
Extra Notes
- Ensure correct permissions for the external domain directory: the user running Payara needs full read/write access to this folder, otherwise you'll get permission errors on startup.
- If your domain uses custom resource paths (like JDBC pool file paths, custom library locations), check if they're relative paths. If so, adjust them to absolute paths pointing to the correct external locations.
内容的提问来源于stack exchange,提问作者Nallamachu

