Showing posts with label tool configuration. Show all posts
Showing posts with label tool configuration. Show all posts

Cool links about load balancing

The first time I load balanced several Tomcat nodes behind an Apache using mod_jk was in the early 2000s.  Mayb 2002, I'm not sure.  Anyway, here is a spot where I will gather my various references on the topic. 


White screen of death and how to coordinate the maxConnctions and timeout settings between workers.properties and Tomcat server.xml

Hibernate, multiple databases

Hey, did you know that you can have TWO hibernate.cfg.xml files in one web application?

I was working on a project that involved merging 2 web applications into one.  There was an old web application that was being brought into the same GUI as a new system.  The old web application, let's call it oldWebApp, had its own POJOs being saved in an old database on an old server.   The new web application had new POJOs being saved in a different database on a different MySQL server.

But I needed everything packaged up in the same WAR file.  How to do it?

In applicationContext.xml, I had two "singleton" sessionFactories.  Like:



     
     
 



     
     
 


Notice how there are TWO hibernate.cfg.xml files? 

Next, you just write your Manager classes (analagous to in this tutorial) according to the appropriate database.  Connect the appropriate Manager class with the appropriate database, still in applicatonContext.xml, like this:


 
 



 
 



So from here just mark up your POJOs using plain old Hibernate annotations and the application is like "who cares what database this object is in" and it just works.  So sweet.

After all that, it turns out we decided to migrate the old POJOs onto the new database server after all, so I gutted this part of the configuration files after all.  But it was still fun to get it working. 

Subclipse crash

One moment, I was fighting with Maven, and the next moment, Eclipse crashed!  After this point, no matter what I did in SVN, from attempting to check in to even browsing the repo, it would crash.  Like, Eclipse would quit completely and I’d get a “Report this error” window, “Would you like to restart Eclipse?”

Here’s how I fixed. it.  In Eclipse, Preferences —> Team —> SVN.  On this window there is a heading “SVN interface” and under CLient, I had JaveHL selected.  Change thiis to SVNKit, click OK.

I had to re-enter my SVN userid and password, but now everything is magically fixed.

Reference:  http://www.eclipse.org/forums/index.php/t/81973/

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.

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

Time in AnyLogic

This entry is about how I solved a problem in my AnyLogic model with the Time settings. 

A few weeks ago, I went to "Simulation: Main", then clicked the "Presentation" tab, and changed Execution mode to "Virtual time (as fast as possible)".  I did this because I wanted to speed up the execution time of my model because I was in the middle of the testing and development process.  This worked.

However, some weeks later, I needed to change back to "Real time".  When I did that, I wasn't seeing my usual "System.out.println" messages that I print out for myself so I can keep tabs on what's going on in the Console.  What was going on??  Obviously, I had changed something during the time that I had it set to "Virtual time", and I couldn't remember what it was.  I had done way to much work to simply re-load an earlier version of my model.

After a bit of poking around, I figured it out.  After setting the model to "Real time with scale" = 1,  click on the main project title, and under the "General" tab, check the Time units.  I had mine set to "days".  So, naturally, in the few seconds that I was watching my console, obviously days were not passing, so, my code was not executing.   I changed this to "seconds" and that fixed it.

Another setting to watch out for is under "Simulation: Main" (or whatever yours is called), also under the "Presentation" tab, check out your "CPU ration (Presentation: Simulation)".  I had mine at 1:2 but wasn't seeing my Console outputs.  So I changed it to "1:1" and that fixed it.

I just LOVE this stuff.  I like growing in expertise and learning the subtleties of these tools.  I also love sharing what I learn with those who are interested in the same thing.  :) :) :)

*hearts*

How to make a Windows machine join a Domain

Although I think of my blog as primarily a place for my research thoughts and meanderings, lately I noticed I've mostly been posting about technical hurdles I have overcome.  Guesswhat, here's another one!  ;) With added bonus of some life reflection mixed in.

Say you have a Windows machine on a network, (such as a campus, like, I don't know, say the University of Saskatchewan), and you want your machine to be part of the USASK domain, but it isn't.  Here's what you do.

0.  Your user may need to be granted permissions to add new machines to the domain.  In addition, your machine may also have to be "pre-added" to the domain so it goes to the right spot when it joins.  So, before going any further, you should contact your Active Directory administrator to make sure they are expecting you & your machine to be added.
1.  Right-click on My Computer, choose Properties
2. Look for the heading "Computer name, domain and workgroup settings".  In here there should be a link that reads "Change settings", click that.
3.  Near the bottom, there's a button that reads "Change", with the label, "To rname the computer or change its domain or workgroup, click Change."
4.  Look at the "Computer name".  Is that what you want your machine to be known as on the network?  If not, change it and then restart your computer.  (if it's a server, have fun organizing downtime!)
5.  Beneath that, it says "Member of" Domain or Workgroup.  Change the domain to be "usask.ca" and restart again.
6.  Type in your username and password to confirm adding the machine to the domain.  Possibly restart again.  Restarting again might be a good idea anyway, because after you have joined a domain, your machine may inherit new policies it never had before.
7.  If something doesn't work anymore, then review the new policies.  In my case, some of the policies shut down some ports I needed open on the firewall, so I had to re-open them.

Why did I bother to type out these simple and obvious steps?  Well, 20 years ago I might have thought it would be unnecessary, because the computer is just so obvious there's no need for directions. right?  (I actually believe this in many cases.)  However, in my life, I have learned that "obvious" is relative.  Of course it's obvious to a young kid who doesn't have any experience with anything EXCEPT Windows, and they are totally familliar with it, there's like no other option of where it could be!   But, operating systems change.  Windows 95 turns into 98 and then XP and then you have a kid and fall of the face of the technical world for a number of years, and maybe you switch and re-learn everything on Mac or Linux, and then you come back and you get all rusty, and, and,  ....

well, sometimes it is just nice to have the friggin' directions in front of you.  It is NOT obvious to people who come from a different universe.  And believe me, life has a way of pushing you into different universes.


Cannot convert value '1111-11-11 11:11:11' from column X to TIMESTAMP.

I got this error a few months ago:

Cannot convert value '1111-11-11 11:11:11' from column X to TIMESTAMP. 

Only, all those 1's were replaced with an actual timestamp from my application, and the X was actually a real integer corresponding to a column in my database.

This answer helped me, but I seem to remember it only worked on my development machine, not my server, something like that:

https://community.jboss.org/thread/192804?start=0&tstart=0&_sscc=t

I think my database was on a Windows server, and I had to do a mysqldump, change the datatypes, then import to the mysql on my RedHat server. 

OAuth errors

When I tried to start up my web application, it would fail with the error:

A class file of the class name com.sun.jersey.oauth.server.api.Providers.DefaultOAuthProvider is identified by the class could not be found.


In my "lib" folder, I also had jars for Tomcat (i.e. catalina-ant.jar and servlet-api.jar).  When I got the error above, I was using jars from Tomcat 5.x.  I swapped out those jars for those from Tomcat 7.x. Doing this caused the error to change to the following:

 Missing OAuthProvider class name in the configuration.  Make sure 'com.sun.jersey.config.property.oauth.provider' property is set.

After fiddling with more things, such as changing the order of the Jars in Eclipse (i.e. right click on the project name --> Properties --> Java Build Path --> Order and Export), finally resolved the error.  How?  I noticed that the Jersey jars I were using were from Jersey 1.5.  I upgraded them to Jersey 1.8 and that made the error go away for me.

Maybe I should start using Maven!  But I already use ANT....


Windows Scheduled Tasks break when you change the password

Did you know that if you change your Windows password, then all of your Scheduled Tasks will break?  Neither did I!  LOL!  Thanks to my colleague GV for helping me figure out why my tasks mysteriously quit working.  I didn't put two and two together.

When I stop and think about it, I do recall a tickbox that says "Do not save the password" (use local resources only), which implies that the password does get saved if you don't check that box.  Obviously, Windows does not keep this synchronized when you use the change password tool.  (Don't you think it should?)

Oh well.

BUILD FAILED - ${tomcat.home} not found

I bumped into this error again today and would like to thank my past self from a few years ago for this reminder on how to fix it.

http://homepage.usask.ca/~slb534/oldblog/archive/2011/01/build_failed_to.php

PHP development in Eclipse

Note:  For anyone who has found my blog from web searching, please be advised that these directions are not complete, they are just my scratch notes as I am trying to figure out the process myself.  However, when I do figure it out, the final notes will be placed on the page you're looking at!

Although PHP is NOT my preferred language for web application development, sometimes you just gotta.

I already have Eclipse and I use it mostly for Java.  However, here's how I installed PHP development tools.

In Eclipse, go to Help --> Install New Software --> click "Add" to add a new site,  for the name I just put "php dev tools" and for the site I put http://download.eclipse.org/tools/pdt/updates/release.   Here's where I got that URL from: http://www.eclipse.org/pdt/downloads/    I think that PDT stands for PHP Development Tools.

Now you can go New --> Project --> Other and "PHP project" will be an option.

Then it will ask you if you would like to switch to the PHP perspective.

Now you can right-click on your new project and go New --> PHP File, say "helloworld.php".

 At this point, you might be inclined to read the PDT User Guide, like me, only to find that the sections, "Preparing the Workbench", and "Creating your first PHP project" are blank.  What the hell!

Well, PHP, perhaps you and I will always have a troubled relationship.  But I will keep trying and I hope that can hold up on your end of things.

Moving on, I'll figure this out for myself.

Right-click on helloworld.php and choose Run As --> ah, ha! there is a new "PHP Web Application" option!  But it doesn't work:  "Page load failed with error: Could not connect to the server."

That's because we haven't created the server yet.  So, let's go into Window --> Show View --> Other --> Servers.   Then right-click in this view and choose New --> Server, then under Basic, choose "HTTP Server".    For "Publishing Directory", Browse to your "htdocs" folder of the Apache installation on your machine, then go into the web folder for this specific project.  I have a Mac, which comes with Apache installed by default.  My user's folder is in /Users/myuser/Sites.  Here's a handy link for setting up Apache + PHP on OSX Mavericks: http://akrabat.com/computing/setting-up-php-mysql-on-os-x-mavericks/.

Anyway, back in Eclipse type in the location where the PHP files should go where Apache can see them.  Click through the rest to finish setting up the server.

NOW you can right-click on helloworld.php again and Run As PHP Web Application.  This time, you see a familliar Apache Not Found message.   Next we gotta set up so the PHP files are automatically copied from Eclipse into the htdocs folder......... and so far I have failed to get this working.  So I will just manually copy the php files from the Eclipse workspace into the Apache htdocs folder for now.  So annoying!  I thought I could create a symbolic link from the workspace to the htdocs folder, but PHP files give me a 403 Forbidden.  I made the "real" files in the workspace and the symbolic link in the htdocsfolder.  Maybe I should try it the other way around.

Another thing you can do is right-click the PHP project --> Properties, then go under "Targetted Runtimes".  This will take you to a screen similar to above (where you have to put in "HTTP Server" and "Publishing Directory".  When I tried this the option I had set up above was greyed out.  I don't know why.

When doing this, you will likely set up a whole bunch of Servers, most of which you won't need.  How do you delete the extra ones?  Find the Server tab in Eclipse, right click and pretend you're going to make a "New" server.  In that window you'll get a link "Configure runtime environments" where you can remove the extras.

Eclipse / PHP links:

  • Installation on Eclipse: http://robsnotebook.com/php_debugger_pdt_xdebug
  • http://www.eclipse.org/pdt/help/html/running_php_web_pages.htm
  • http://stackoverflow.com/questions/432162/does-anybody-have-a-development-staging-deploying-workflow-with-php-mysql (team workflow)
  • http://ubuntuforums.org/showthread.php?t=1787976 (note to self, read this one again - bottom!)
  • http://coolestguidesontheplanet.com/install-configure-apache-mysql-php-phpmyadmin-osx-10-8-mountain-lion/
  • http://brianflove.com/2013/10/23/os-x-mavericks-and-apache/
  • Symbolic links discussion http://stackoverflow.com/questions/4097946/whats-the-best-way-to-deploy-a-php-pdt-eclipse-project-to-apache-on-ubuntu
  • OS X adding a user to a group (to give Apache user permission over the folder containing PHP files)  http://superuser.com/questions/214004/how-to-add-user-to-a-group-from-mac-os-x-command-line
  • NETBEANS PHP https://netbeans.org/kb/docs/php/project-setup.html#localServer


JUnit testing

After many years of "I've been meaning to try this!" but never actually having time to do so, I finally incorporated my first JUnit test into a codebase.

In Eclipse, I right-clicked on the package containing the class I wished to write tests, for, then I chose New --> Other --> JUnit Test Case, click Next, then create a class name (ex. MyClassTest) then finish.

Next, write your test methods.

Next, right click on the new class in the Project Explorer, then choose Debug As -> JUnit Test.  (I originally goofed up here because I picked Run As --> JUnit Test.  But when I did that, the variable inspection features didn't work!)

Next, the perspective will change to Debug, then you can click the items in the Variable column to view the contents, set break points, etc..

This is my favourite part about my job!  Too bad it's so rare I get to do this, hahah!

Eclipse / JUnit links
  • http://courses.cs.washington.edu/courses/cse143/11wi/eclipse-tutorial/junit.shtml 

sweet Hibernate links

Earlier, I started a list of "sweet Hibernate links".  Because I can no longer edit my old blog, I'm creating a new spot for it here.

Previous links


MySQL does not install on Windows

MySQL does not install on Windows.  Can you believe it?  I would have thought this is a common and reasonable combination of tools.  But NOPE!

I have tried Windows Server 2008, Windows 2012, MySQL 5.1 and MySQL 5.5 and all combinations fail.

Finally, a co-worker informed me that this has been a problem for many years.  Apparently it's related to the fact that the Windows directory name "Program Files" had recently added an "(x86)" at the end, so, "C:\Program Files (x86)\".  Apparently the brace symbol in the directory name is responsible for mucking everything up.  When the installer finishes and it goes to start the service for you, it says:

"Windows could not start the MySQL service on Local Computer.  Error: 1053: The service did not respond to the start or control request in a timely fashion."

Unfortunately, the installer did not give me the option of choosing a different directory.  Further, I checked and one time I managed to get the installer to go into "C:\Program Files" (without the (x86)) and it STILL failed.  My colleague suggested it might be possible to change the path by directly editing the registry.

However, at this point, I was running out of time.  I gave up on Windows and got myself a RedHat Linux server instead. It is working. 

My sincerest sympathy to anyone who does not have this freedom and is forced to get MySQL installed on Windows.  If I ever find a set of steps that explains how to fix this, I'll post the link here.

I just wish I had known about this "Known Issue"  BEFORE I spent a day of my life trying to get it to work.  :(
 


How to make Internet Explorer allow you to download Firefox

Once up on a time, I sat down in front of a new Windows computer and the only web browser option was Internet Explorer.  Upon opening IE, I received a prompt, "Do you wish to use the recommended settings (green)" or "Don't use recommended settings (red)".  I was feeling trusting, so I picked the green one.  Big mistake!  Next, I went to download Firefox, but I kept getting the message "The file could not be downloaded".  I added mozilla.org, downloads.mozilla.org and all sorts of sites to my Trusted Sites, but nothing worked.  Internet Explorer was utterly UNUSABLE.

Then I found the secret.  Tools --> Internet Options --> Advanced.  At the bottom there's a section for "Reset Internet Explorer settings".  Click the button that says "Reset".  Then, the next time you open IE, it will ask you again if you want the recommended settings.  Then you can choose "Don't use recommended settings" and then you can go and download Firefox.  Whew!

Well... not quite "whew" yet.  Even with this, none of the CSS stylesheets were loading.  So I could not see the "Download" button.  But after going into View Source, I found it.  (Here it is: https://download.mozilla.org/?product=firefox-stub&os=win&lang=en-US)

UPDATE:  Another thing you have to do to to make IE allow you to download files is in Internet Options -> Advanced, then under the heading "Security", look for the checkbox that reads "Do not save encrypted pages to desk".  Then, for goodness sakes, UNCHECK THAT.  Now, you can download Firefox, and wash your hands so you never have to touch IE again.

Even though I'm quite a skilled developer, if I do say so myself, IE makes me incompetent! 

Translate