Total Pageviews

Saturday, June 14, 2014

Create and import a MySQL dump

Dumping a MySQL database is that simple:

 /path/to/mysqldump -u$DBUSER -p$DBPASSWD -h$DBHOST $DBNAME > $FILENAME  

Importing the dump back into a MySQL DB looks like this:

 /path/to/mysql -u $DBUSER -p$DBPASSWD --database=$DBNAME < $FILENAME  

If the database to import is encoded with UTF8 it might be necessary to use the option
--default_character_set

 /path/to/mysql -u $DBUSER -p$DBPASSWD --default_character_set utf8 --database=$DBNAME < $FILENAME  

Tuesday, June 10, 2014

How to get module name and application name in Java EE applications

It's been a long time since my last blog post, but here is an update :-)

For those of you who always wanted to get the name of the application or the module at runtime in a Java EE application, here is a solution:

 @Resource(lookup="java:module/ModuleName")  
 private String moduleName;

 @Resource(lookup="java:app/AppName")  
 private String applicationName;  

It's been there since Java EE 6 and it's easy and portable!

There is also the opportunity to get those names via JNDI lookup

 String myModuleName = (String) initialContext.lookup("java:module/ModuleName");  
 String myApplicationName = (String) initialContext.lookup("java:app/AppName");  

If you don't need the names in a field but just in a single method this is the way to go.

The default module name is the base name of an ejb-jar or WAR archive.
The default application name is the base name of an EAR archive.