Tuesday, December 9, 2008

Java classpath - adding libraries and jars

Setting/Using the Java classpath always brings up some trouble, especially when a lot of external libraries or JARs are needed.

Well, here is something to make life easier. It is apparently new with JDK 1.6: the wildcard character. It adds to the classpath ALL JARs, classfiles, zipped libraries etc. inside a particular directory.

To compile a Java file that needs a long list of JARs or external classes, try:
> javac -cp "path-to-library-folder/*" MyJavaClass.java
  • NOTE: Don't forget the quotes

To run a Java class that needs a long list of JARs or external classes, try something like:
> java -cp ".;path-to-library-folder/*" MyJavaClass
  • NOTE: Don't forget to include the current directory by putting "." in the class-path
  • NOTE: Don't forget the quotes again

Thursday, December 4, 2008

J2EE 1.4 JMS problems using java.sun.com JMS tutorial

Apparently Sun's JMS tutorial has not been updated to work with J2EE 1.4 and thus most of the commands they tell you to do simply do not work. This is because there's been a lot of changes to the names of J2EE commands that you type at the command prompt.


Here are some guidelines:
  • When you download J2EE 1.4, just use their default installation directory. Do not install in a directory that has spaces in its path (ie. "Program Files\..." if you use Windows) as Java has trouble finding directories with spaces in them when you set "classpath" etc.
  • Starting the J2EE server was a problem because my system simply could not find the progam called: "j2ee". In J2EE 1.4, this program has been renamed to "asadmin" 
    • Start J2EE server in version 1.3, type: j2ee
    • Start J2EE server in version 1.4, type: asadmin start-domain
  • Adding a JMS destination queue is also different in J2EE 1.4
    • Add JMS destination queue in version 1.3, type: j2eeadmin -addJmsDestination MyQueue queue
    • Start J2EE server in version 1.4, type: asadmin create-jmsdest -T queue MyQueue
  • To view a list of JMS destinations is different in J2EE 1.4
    • View JMS destination list in version 1.3, type: j2eeadmin -listJmsDestination
    • Start J2EE server in version 1.4, type: asadmin list-jmsdest

Wednesday, December 3, 2008

Perl: Converting between day of year (DOY) dates and normal YYMMDD dates

Perl has limited support for converting between dates, and to convert between dates that include "day of year" values, you will need an external Perl module. 
 
Use the module: Date::Calc
 
 To convert a date like YY/DOY to YY/MM/DD format, try: 
  • Use  Add_Delta_Days function in Date::Calc
  • Extract by: 
 my ($new_year, $new_month, $new_day) = Add_Delta_Days($old_year, 1, 1, $old_doy - 1);
 
          Where: 
$new_year is the year value in YY/MM/DD
$new_month is the month value in YY/MM/DD
$new_day is the day value in YY/MM/DD
$old_year is the year value in YY/DOY
$old_doy is the day of year value in YY/DOY
We set the second and third arguments of Add_Delta_Days to "1" because we want to add the number of days starting from January 1st of the given year 



To convert a date like YY/MM/DD to YY/DOY, try:
  • Use  Day_of_Year function in Date::Calc
  • Calculate the day of the year by:
  my $doy = Day_of_Year($year, $month, $day);
 
 

NOTE: Don't forget to include the Date::Calc package by stating at the top of your file:
use Date::Calc qw(Add_Delta_Days Day_of_Year);
 


For more information, see: