MySQL shortcuts

Quoting myself from my old blog:
Over the last decade, I have installed MySQL dozens of times on dozens of computers using several different operating systems. However, when the time comes that I need to do it again, I can never freaking remember how to do it quickly and easily.  ... I am aware that I have done this successfully many times, and I wish it could just "stay" done so that I do not have to expend this effort over and over. However, as I change jobs and change computers over time, it seems any optimization is unlikely.
Therefore below I repost commands I should have memorized years ago but I haven't.  So there!

MySQL privileges
GRANT ALL PRIVILEGES ON dbnam.tables TO 'username'@'whatev.edu or %' IDENTIFIED BY 'password';
FLUSH PRIVILEGES;

MySQL import
mysql -u username -p dbname < dbname.sql

MySQL export
mysqldump -u username -p databasename > /path/to/save/mydumpfile.sql

Start MySQL on OS X
sudo /usr/local/mysql/support-files/mysql.server start

Install MySQL on OS X
http://www.bos89.nl/install-mysql-on-mac-osx/

Update MySQL Root Password
version 5.7.6 and later:
ALTER USER 'root'@'localhost' IDENTIFIED BY 'newPass';
version 5.7.5 and earlier:
SET PASSWORD FOR 'root'@'localhost' = PASSWORD('newPass');

Maven built classes refreshed in Eclipse's built-in tomcat

As much as I like my Maven setup, I still have the occasional problem of my updated java classes not getting deployed.  Like, I'll make a change to a Java class, re-compile it, then restart my Tomcat, but for whatever reason Tomcat is acting like it can't see the change I made in the new java class -- the .class file is not being refreshed.

Here are the steps I follow to force everything to refresh.   Tedious, but it works.

1.  Right click on project, go to Properties, Deployment Assembly, and delete the line for target/classes.

2.  Right click on project, Run As --> Maven Clean.   Then Run As --> Maven Build and type "package" (if you want a jar file, or just type "compile" if you don't need the jar.)

3.  Right click on project, Properties, Java Build Path.  Ensure Maven Dependencies are clicked ON.

4.  Right click on project, click Refresh.

5.  Put target/classes back into the Deployment Assembly.

6.  Go into the Servers tab, right click on server and "Clean...".

By the time Tomcat starts up, I have found that this finally refreshes my .class files.  I am sure there is a better way to do it, but this is the brute force method I have discovered with rial and error and it works in a pinch.

How did I ever survive without Maven?

I have only been using Maven in my active projects for about 2 months, but already I have no idea how I survived without it.  I have solved so many errors that were caused by jar conflicts that I have lost count!

First, there's the conflict between some versions of Jersey and Hibernate that I resolved with Maven.

Next, when I started using C3P0 connection pooling with Hibernate and Spring, I solved another error with Maven.  (I had to swap out my "c3p0" dependency for "hibernate-c3p0", then I had to fiddle with the versions of hibernate-c3p0 until it worked.)

There were several others I bumped into while switching my project to use Spring & Struts -- several dependencies to add there and get coordinated with the others.

I still use ANT for generating the WAR for production.  I need ANT because I have 2 sets of configuration files -- one for dev and one for prod -- and I simply tell ANT which set of config files to build from.  I don't know if Maven can do that or not.

For many years, I thought I had to choose between Maven and ANT, but what do you know, here I am using both on a daily basis.

Kinds of Learning: Immersive, Structured

My supervisor, Gord McCalla, told me about an invited talk that was given at AIED one time by John Sellers (?).  In this talk, there was a discussion of two kinds of learning:
  1. like language learning, where you just put yourself in a rich environment and you pick it up as you go
  2. where it takes hard work, reflection, organized/structured approach to material
I've Googled around but I can't find any references to this talk.  If I ever find it, I'll put the link here.

I think this discussion is interesting because it could inform the kinds of instructional planning approaches that should be used for certain domains, or even certain learners in certain situations. 

Building a WAR file in Eclipse with Maven

The other day, I installed Maven on my OSX machine (previous entry) and I started using it in my Eclipse projects (mostly Dynamic Web Projects).  Maven really helped me clean up my Jar file conflicts.  Now that I have my jar files all cleaned up, I want to export them into a WAR file.  So, how do you generate a WAR file from Eclipse that is based upon your definitions in pom.xml?

Well you can right-click on your project and go Run As --> Maven Build...

In the next window, you'll see a box labelled "Goals:".  There are keywords you can type in here.  If you type "package", it will look in your pom.xml for any directions you've typed for creating JAR or WAR files.  Here is a StackOverflow thread where one of the replies shows how to pull in the Maven WAR plugin. 

So, edit your pom.xml to include the Maven War Plugin stuff (which gives teh path to web.xml).  Then, Run As --> Maven Build, and type "package" into the Goals: box.   Then you'll see some Build information in your console, and, hopefully, you can look inside your "target" folder in your project (remember to hit Refresh in Eclipse!) and you should see the war file that has been assembled for you.

This link at Aykut Akın's Blog shows some screenshots to give a broad overview of how I did it.

I am accustomed to doing this with ANT, so I have a few kinks to work out to make sure the .class files and .jsp files and so on all end up in the correct place!  

Jersey + Hibernate conflict

Here is the error:
http://stackoverflow.com/questions/7721836/jersey-hibernate-nosuchmethoderror-org-objectweb-asm-classreader-acceptlor 


Using Maven, this is the best solution to the Jersey / Hibernate conflict I have found:
http://blog.idm.fr/2009/04/jersey-hibernate-conflict.html


Maven on OSX

Once upon a time, Mac OS X came with Maven pre-installed.  Nowadays we have to install it ourselves, alas.

Luckily, it's fairly simple.  First, you have to install Homebrew; just scroll to the bottom of that website and execute the command provided.   When I pasted the command directly into the Terminal, it didn't work (error: "Illegal variable name.").  But when I went into "sh" first, then it worked.  It asked me to verify that I was OK to some permissions updates, and I also had to install developer tools that I hadn't yet on this machine.  Then it installed.

After that, I followed advice from this popular StackOverflow question and typed:
brew install maven
(while still in "sh").

Now, whenever you are in "sh", you can use the "mvn" command.  At this point, I went on to install Maven Integration for Eclipse.

After installing the plugin, I found that you can right-click on your Eclipse project and go Configure --> Convert to Maven Project.  This asks you to type in the GroupID, ArtifactId, Version, etc..  When I did that, it created a pom.xml descriptor for me in the root of my project folder.

When I double-clicked pom.xml, it automatically opened in the Maven POM Editor.  In here, I found a "Dependency" tab.  When I clicked Add, it asked for GroupID, ArtifactId, Version, etc.  I observed that this looks a LOT like the XML shown in sample pom.xml files around the web.

So, I typed in:

Group ID: org.glassfish.jersey.containers
Artifact ID: jersey-container-servlet
Version: 2.5.1

Where did I get this info?  Just Google around and find a sample pom.xml... it is obvious looking at the XML what the GroupID, ArtifactID and Versions are.

Then I clicked OK, then I Saved pom.xml.   Then it automatically built my workspace.  When I went under Java Resources --> Libraries --> Maven Dependencies, I noticed some familliar Jersey Jar files there.   Did it download those automatically for me??? It must have.  I can't believe I didn't have to manually download the jars and add them to Properties -> Java Build Path

But first I have to go feed my kid some lunch.

Bye.

UPDATE:  OK, Hibernate is working now too.  That is, I have a Java class with Hibernate imports, and they are not red and underlined.  I used:

Group ID: org.hibernate
Artifact Id: hibernate-core
Version: 4.3.5.Final

Translate