Hot questions for Using GlassFish in asadmin

Question:

I'm using Java EE with Glassfish.

I can't run asadmin command as well. I did the following, but output from terminal is:

No command 'asadmin' found, did you mean: Command 'amadmin' from   package 'amanda-server' (universe) Command 'acsadmin' from package'ion' (universe) asadmin: command not found

I have Ubuntu 14.04 Trusty Tahr. I should be in bin directory of glassfish, so I'm in /opt/glassfish4/bin. But always nothing happend, just error message above.


Answer:

In Ubuntu and Linux in generĂ¡l, you run commands from current directory like this: ./asadmin, ie. you must prepend ./ to make it explicit that you run a command I current directory. This is traditionally for some security reasons.

Question:

I'm trying to use a javax.sql.DataSource injected into a servlet (glassfish)

@Resource (name="jdbc/MysqlDS" )
javax.sql.DataSource mysqlDS;

The following statements fail, throwing "java.sql.SQLException: Access denied for user 'userapp'@'localhost' (using password: YES)":

con=mysqlDS.getConnection();
PreparedStatement pstmt=con.prepareStatement("select now()");

or

con=mysqlDS.getConnection("userapp","userpassword");
PreparedStatement pstmt=con.prepareStatement("select now()");

But the following were successful:

Class.forName("com.mysql.jdbc.Driver");
con = java.sql.DriverManager.getConnection("jdbc:mysql://localhost:3306/user_lindenb", "appuser", "userpassword");
w.println("OK");
con.close(); con=null;

or

con=mysqlDS.getConnection("root","root_password");

or

con=mysqlDS.getConnection("me","mypassword");

or

$ mysql -u appuser --password=userpassword -D user_lindenb -e 'select now()'
+---------------------+
| now()               |
+---------------------+
| 2015-08-05 10:19:07 |
+---------------------+

The grant was declared as follow:

 grant insert,select,update,delete on user_lindenb.* TO 'appuser'@'localhost' identified by 'userpassword';

and the resources were declared as follow

asadmin --port  8138 create-jdbc-connection-pool \
            --datasourceclassname com.mysql.jdbc.jdbc2.optional.MysqlDataSource \
            --restype javax.sql.DataSource \
            --property "password=userpassword:user=userapp:serverName=localhost:databaseName=user_lindenb" \
             MysqlDS
asadmin --port 8138 create-jdbc-resource \
            --connectionpoolid MysqlDS \
            "jdbc/MysqlDS"

what's wrong with this user 'userapp' ?

Thank you.


Answer:

after I added

grant USAGE on *.* TO 'appuser'@'localhost' identified by 'adminadmin';

everything worked fine... I don't understand why.

Question:

I'm trying to start my local domain from a command line, for some reason my domain was created in a different location so I tried the following command to start the domain:

C:\Program Files (x86)\glassfish4\glassfish\bin>asadmin start-domain C:\Users\Abraham\personal_domain

but it doesn't work, I got the following error:

There is no such domain directory:

C:\Program Files (x86)\glassfish4\glassfish\domains\C:\Users\Abraham\personal_domain Command start-domain failed.

Do I have to add another attribute in the command?, What am I missing?

From NetBeans, it runs fine and I can access to my application but I want to be able to start it from command line


Answer:

Firstly, to find more information about any asadmin subcommand, you can use help to find the man page for that command in one of two ways:

Either:

asadmin help start-domain

or

asadmin start-domain --help

Secondly, to start a domain from a different location, you need to first specify the domains directory - a folder where the actual domain folder sits, and then the domain name. This will look a lot like you've just typed out the full path to the domain directory, but do be aware that there is a space in between the end of the path and the name of the domain.

e.g. if I wanted to start a domain called "myDomain" in a folder C:\Users\me\domains, I could do this:

asadmin start-domain --domaindir C:\Users\me\domains myDomain

Note the space in between domains and myDomain.

So, in your case, you would need to use:

asadmin start-domain --domaindir C:\Users\Abraham personal_domain

Question:

So I am trying to restart glassfish server but it fails to start. What could be the error?

asadmin> start-domain java.io.FileNotFoundException: /home/ubuntu/glassfish-3.1.1/glassfish/domains/domain1/logs/server.log (Permission denied) at java.io.FileOutputStream.open(Native Method) at java.io.FileOutputStream.<init>(FileOutputStream.java:221) at java.io.FileOutputStream.<init>(FileOutputStream.java:142) at java.util.logging.FileHandler.open(FileHandler.java:173) at java.util.logging.FileHandler.openFiles(FileHandler.java:441) at java.util.logging.FileHandler.<init>(FileHandler.java:287) at com.sun.enterprise.admin.launcher.GFLauncherLogger.addLogFileHandler(GFLauncherLogger.java:100) at com.sun.enterprise.admin.launcher.GFLauncher.setup(GFLauncher.java:178) at com.sun.enterprise.admin.cli.StartDomainCommand.createLauncher(StartDomainCommand.java:205) at com.sun.enterprise.admin.cli.StartDomainCommand.executeCommand(StartDomainCommand.java:105) at com.sun.enterprise.admin.cli.CLICommand.execute(CLICommand.java:264) at com.sun.enterprise.admin.cli.MultimodeCommand.executeCommands(MultimodeCommand.java:226) at com.sun.enterprise.admin.cli.MultimodeCommand.executeCommand(MultimodeCommand.java:144) at com.sun.enterprise.admin.cli.CLICommand.execute(CLICommand.java:264) at com.sun.enterprise.admin.cli.AsadminMain.executeCommand(AsadminMain.java:306) at com.sun.enterprise.admin.cli.AsadminMain.main(AsadminMain.java:238) Waiting for domain1 to start ..............................................................................................................................................................................................................................

Anyone kindly advice?


Answer:

It obviously fails to create or open the log file:

/home/ubuntu/glassfish-3.1.1/glassfish/domains/domain1/logs/server.log

You should ensure that the folder structure exists and is accessible by the process (and it's user).

Question:

I would like to create a jdbc connection pool from the command line --- doing it through the browser all the time is driving me crazy as it is such a tedious process. I've used the command

    asadmin create-jdbc-connection-pool
      --datasourceclassname com.mysql.jdbc.jdbc2.optional.MysqlDataSource
      --restype javax.sql.DataSource
      --property user=root:password=test:DatabaseName=test:ServerName=localhost:port=3306
    the-pool

with success. However, it creates a connection pool with only the properties that are specified in the command. When I use the administration console at localhost:4848 to create a connection pool, the default number of "additional parameters" seem to be in the region of 171 properties. I'm assuming that the console is enacting a default property flag. Does anyone know how I might modify the command to get a more comprehensive list of properties? I've consulted the Oracle docs for pool administration but have had no joy and my shoddy installation of glassfish rendered asadmin's help pages defunct.


Answer:

I've been using the command posted in the question successfully for the past few months. There appears to be no need to set any of the additional properties. However, I use com.mysql.jdbc.jdbc2.optional.MysqlConnectionPoolDataSource instead of MysqlDataSource for the sake of performance (see this answer).

Upon creation of the pool, the jdbc resource is created by

asadmin create-jdbc-resource --connectionpoolid the-pool jdbc/the-pool

Question:

Pretty much says it all, but when I try to log in to the Glassfish console I am get a "Error Authentication Failed Re-enter your username and password"

However when i use asadmin I am able to login, deploy, etc. it all works.

If there is a particular place I can alter the log level or a place I can look.

FYI part of the reason I think this happened is that I have changed the master password.

Any tips?


Answer:

Not Exactly sure why it works, but I think it may be due to some cached values. I already had secure admin enabled when I stared the process of adding SSL certificates, and based on information in this post: Right way to configure Glassfish SSL certificate nickname? I was able to find a solution. With the server running Disable Secure Admin. Restart Server Enable Secure Admin Restart Server.