Wednesday, August 13, 2008

Learning LaTeX and Eclipse*

Wednesday, August 13, 2008 2:07:19 PM (GMT Standard Time, UTC+00:00)

It's that glorious time once again, i.e. time to learn new software. The software choices are mainly 'required' for my research so it's nothing too fancy. They are:

LaTeX is a high-quality typesetting system; it includes features designed for the production of technical and scientific documentation. LaTeX is the de facto standard for the communication and publication of scientific documents. (Source) [To use LaTeX on Vista, I first installed Basic MiKTeX 2.7, then TeXnicCenter. proTeXt seems like a good option as well but I'm yet to try it.]

Eclipse is an open source community whose projects are focused on building an extensible development platform, runtimes and application frameworks for building, deploying and managing software across the entire software lifecycle. Many people know us, and hopefully love us, as a Java IDE but Eclipse is much more than a Java IDE. (Source) [To use on Vista and Linux, I downloaded and installed Eclipse IDE for Java Developers.]

If you know any good tutorials on any of these, it would be great if you could share, thanks! :-)

Wednesday, July 16, 2008

Including jar files in your projects in Eclipse*

Wednesday, July 16, 2008 7:36:43 AM (GMT Standard Time, UTC+00:00)

In previous posts, I've discussed how to include .jar files in the CLASSPATH variable. These settings work fine if you're coding in gedit (or SciTE) and using the javac and java commands, however, if using an IDE such as Eclipse you will get error messages when you include packages (or jar files) in your code. Below I outline how I solved this issue in Eclipse.

In Eclipse (version 3.4.0) go to the menu then 'Project'
In the panel on the left, Select 'Java Build Path'
In the 'Java Build Path' panel now loaded on the right Select the 'Libraries' tab
Click the button 'Add External JARs...'
Browse to your JAR file, select it then Click OK.
Finally, Click OK in the 'Java Build Path' panel to exit it

Eclipse should now (hopefully) recognise the included package and the errors should disappear. If this doesn't happen, possibly try to exit and reload Eclipse. This worked for me, so I hope it can do the same for you!

(PS. This was done on a Linux box, but I don't imagine Windows would be much, if any different.)

Monday, July 14, 2008

How to set CLASSPATH (and PATH) for Java in Linux*

Monday, July 14, 2008 6:01:12 AM (GMT Standard Time, UTC+00:00)

Background: The CLASSPATH in a UNIX-based system is an environment variable that is a list of directories that the operating system looks in to find library classes and modules. For example, to compile Java, the Java *.class files must be in your CLASSPATH.

To set your CLASSPATH: For bash shell use - "export CLASSPATH=$CLASSPATH:/java/classes"

Sometimes .jar files also need to be included into the CLASSPATH. A good example of doing this is for XOM (a new XML object model available under LGPL) is:
For bash shell use - "export CLASSPATH=$CLASSPATH:~/xom/xom-1.1.jar"

I must say however, the problem with the above method is that it only sets this variable for your current bash session! Therefore, what you likely want to know is how to set this variable permanently,and thus accessible in all subsequent sessions. To do this, go to your user home directory ("cd ~/" should do the trick), in it should be the file .bashrc, open this file (I used Vi), scroll down to where the CLASSPATH variable is set and append the relevant directory (I used ~/xom/xom-1.1.jar), then save and close. (Ensure you don't overwrite the last line after the CLASSPATH is set, i.e. "export CLASSPATH".. if this is not exported, this WILL lead to problems.) Now, for every new session of bash, the added class directory or .jar file will be referenced. You can try "echo $CLASSPATH" to test.

The main reference for this article was is Setting your Classpath at Linux Headquarters. At that link you can also find information on setting the PATH variable.

Enjoy!

Wednesday, July 09, 2008

How to set PATH and CLASSPATH for Java in Vista*

Wednesday, July 09, 2008 7:10:42 AM (GMT Standard Time, UTC+00:00)

How to set PATH and CLASSPATH system variables for Java in Windows Vista..

Control panel (Classic View)
System
Click on "Advanced system settings"
Environmental Variables
System Variables
Select the PATH
Click Edit
Add your path to the PATH variable.... normally .. C:\Program Files\Java\jdk1.6.0_(version)\bin

This tip is thanks to 'sha-k' at http://www.computing.net/answers/progra ... 15739.html

Regarding the CLASSPATH, it's also important to ensure the the CLASSPATH includes "." i.e. the current directory, preferably this is the first entry as well. This ensures Java checks your current directory first when looking to execute the class file with the "java" command (when using for e.g. Command Prompt).

Saturday, June 28, 2008

Running Java classes with packages in Command Prompt*

Saturday, June 28, 2008 7:31:54 PM (GMT Standard Time, UTC+00:00)

For a few hours today I've been fighting with a java problem so in the interest of goodwill I've documented it and the solution below. I think for someone new to java (or someone who hasn't used it in ages aka me) this will be rather useful.

The problem: I wanted to run a Java file 'he.java', which is in a Java package (and Windows directory) called 'her'. Below you can see that when I compiled everything went fine, however when I tried to run the file that became somewhat of a problem! ..

R:\tech\her>javac he.java
R:\tech\her>java he
Exception in thread "main" java.lang.NoClassDefFoundError: he (wrong name: her/he)
        at java.lang.ClassLoader.defineClass1(Native Method)
        at java.lang.ClassLoader.defineClass(Unknown Source)
        at java.security.SecureClassLoader.defineClass(Unknown Source)
        at java.net.URLClassLoader.defineClass(Unknown Source)
        at java.net.URLClassLoader.access$000(Unknown Source)
        at java.net.URLClassLoader$1.run(Unknown Source)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        at java.lang.ClassLoader.loadClassInternal(Unknown Source)

The solution:
1. Because of the package the command will actually be "java her.he"
2. With that command alone, Java will look for "her.he.class" in "her" directory. However, because you are already in the "her" directory, you'll likely get the same error again, so you need to go up a directory i.e. "cd .."
3. Now try "java her.he"
R:\tech\>java he
Hello Jason!

I thank this article for enlightening me on this exception. It also has more detail, therefore I recommend it if you're interested.