Bobzone
Bobzone

Reputation: 286

Controlling GlassFish from CLI

I have problems with setting up IntelliJ to work with my GlassFish server. Trying to fix it, but I came with an walk-around fix.

Is it possible to start / stop / build project / deploy / redeploy / check logs etc. From the command line instead of inside IntelliJ? This way I can use IDE to code but won't have to bother with GlassFish related issues with IntelliJ.

Any experiences with that matter? Thanks

Upvotes: 0

Views: 282

Answers (2)

Bobzone
Bobzone

Reputation: 286

Im not sure if i should add this answer here but here's detailed information of how I handled the initial problem:

The problem was that after adding Glassfish to IntelliJ and running my app I had the Server is not connected. Deploy is not available error.

This is much likely because I worked with that glassfish instance before using other IDE - Netbeans.

From what I gathered Netbeans actually alters the domain.xml file and "makes it corrupted" for IntelliJ.

The solution was to use the asadmin commands provided by Mike and either delete the domain1 folder in glassfish folders and recreate it with asadmin create-domain domain1 command or just create a domain2 with create-domain domain2 and then add the new domain into IntelliJ.

Upvotes: 0

Mike
Mike

Reputation: 4963

OK, here goes. You need to be familiar with the asadmin tool. you will find it in ${GLASSFISH_HOME}/bin/asadmin. You can either call asadmin from a terminal and follow it with a subcommand and its options, or just run asadmin with no parameters to start an interactive session.

For additional options for any subcommand, you can use the help subcommand, with the name of the one you want instructions for as a parameter, e.g. ./asadmin help list-domains

Here are the ones you asked for:

Start the server

asadmin start-domain

Stop the server

asadmin stop-domain

Deploy myApp.war

asadmin deploy /path/to/myApp.war

Undeploy myApp.war

asadmin undeploy myApp

Redeploy myApp.war

asadmin redeploy /path/to/myApp.war

Build project

cd /path/to/my/project
mvn clean install

Check logs

The server.log file is located in: ${GLASSFISH_HOME}/glassfish/domains/domain1/logs/server.log

When you are deploying your WAR, it will take the name of the artefact, excluding the extension. This means that any version in the filename will become part of the deployment name, e.g:

asadmin deploy /path/to/myApp-1.0-SNAPSHOT.war

To undeploy this, you would need to run asadmin undeploy myApp-1.0-SNAPSHOT.

You can override the name with the Deploy and Redeploy commands as follows:

asadmin deploy --name myApp /path/to/myApp-1.0-SNAPSHOT.war
asadmin redeploy --name myApp /path/to/myApp-1.0-SNAPSHOT.war

You may also find it helpful, or easier, to administer the server from the web based admin console at http://localhost:4848

Upvotes: 1

Related Questions