GlassFish 3 + Maven + remote deploy

后端 未结 2 1549
眼角桃花
眼角桃花 2021-02-06 05:39

I couldn\'t find any clear answer about how to deploy simple Maven based project to remote GlassFish server via maven like

mvn package xxx:deploy
2条回答
  •  心在旅途
    2021-02-06 06:12

    In case you want to only use maven-glassfish-plugin (let say version 2.1), you can do a remote deploy by specifying the "host" parameter. Below is an example where configurations are setup in maven settings.xml and an plugin loads them using a profile:

    In settings.xml define a profile:

    
         production-config    
         
           /var/local/glassfish/
           admin
           adminadmin
           prd-domain
           NAMEOFYOURREMOTEHOST
           10161
           .
           .
          
    
    

    Next put this profile in your active profiles:

    
        production-config
    
    

    In your maven project pom.xml, create a profile and add the maven-glassfish-plugin in your list of profiles:

    
        production
        
         false
         
        x86
        linux
         
         
        profile
        production
         
         
          
           ${glassfish.glassfishDirectory}/domains/${glassfish.domain.name}/config/domain.passwords
          
         
       
       
          
              
                   org.glassfish.maven.plugin
                   maven-glassfish-plugin
                   
                      true
                      true
                      true
                      ${glassfish.glassfishDirectory}
                      ${glassfish.user}
                      ${glassfish.adminPassword}
                      
                         ${glassfish.domain.name}
                         ${glassfish.domain.host}
                         ${glassfish.domain.adminPort}
                      
                      
                        
                          ${project.artifactId}  
                     ${project.build.directory}/${project.build.finalName}.war
                        
                      
                   
                   
                        
                    
                deploy
                
                
            
             
          
        
    
    

    This should do the trick. You can run this profile using maven : mvn glassfish:deploy -P production or just mvn deploy -P production (since we have added the goal deploy inside the executions part of plugin)

    Using the model above you can create different profile per environment (dev, acc, tst, prd), and use different settings. For instance you can create a developer profile where a local glassfish is being used to deploy and run unit/integration tests on it.

    Common mistake people make is to mix up the settings for the machine from where you are doing the remote deployment with the host where deployment is to be installed. glassfishDirectory is place from where you are running the deployment plugin from. As a result of mistake plugin just hangs, doing nothing and just waiting giving the impression that something is happening. Another mistake is to specify a password file instead of a password for a remote deploy which will also result in nothing.

提交回复
热议问题