Log in

View Full Version : Java Question


mirkazemisaman
09-07-2003, 02:57 AM
Sorry, this is perhaps not the best place to ask this question since it is not Pocket PC related, but this is the only place I could think of after searching for about 30 minutes on the net plus you developers could help me (who knows, maybe I'll write something for PPC in a few decades...).
Here's the deal, I just started learning Java after working with C++ for a little while. I have downloaded and installed the newest SDK (1.4.2 I think) from java.sun.com.

Now I need to edit and compile my code through Command Prompt. So I set up the DOS Box to work with the Java Compiler and made a dir to work in and also made some modifications to the sysedit file based on some advice I got from a beginner java site.

The compiler works well, but I have problems importing files:

I have put the following three files I needed for some specific project in the same directory as my other java files (C:\JavaFiles):

TerminalIO.jar
TurtleGraphics.jar
BreezySwing.jar

But when I try to import them (TerminalIO for example) in my program and compile them I get the following error message:
******************
test.java:1: package TerminalIO does not exist
import TerminalIO.*;
^
1 error
******************
Now I thought as long as I have those *.jar files in the dir, i should be OK; but it doesn't seem so. Do i need the files to be in some mysterious "package format"? Do I need to make a batch file? Any help would be greatly appreciated.

Jacob
09-07-2003, 03:03 AM
This sounds like a problem with how the classpath is set.

How are you setting the classpath in the compile command line?

Steven Cedrone
09-07-2003, 03:12 AM
Sorry, this is perhaps not the best place to ask this question since it is not Pocket PC related

Never hurts to ask... :wink:

I did move the post to the "Off-Topic" forum though...

Steven Cedrone
Community Moderator

Janak Parekh
09-07-2003, 04:15 AM
Jacob hit the nail precisely on the head. Java relies on an environment variable called the CLASSPATH. If you don't have it set, by default it's set to ".", i.e., the current directory. However, it will only look for .class files in that directory. In order for it to look inside JAR files, you must explicitly specify them in the CLASSPATH, or use a special parameter to java/javac. If you do, make sure to add a "." or the path to the directory itself so that the .class files will still be found.

See this Java documentation page (http://java.sun.com/j2se/1.4.2/docs/tooldocs/windows/classpath.html) for the full details on how this stuff works.

BTW, if you don't want to deal with these hassles, download an IDE; they automate much of the process. NetBeans (www.netbeans.org) and Eclipse (www.eclipse.org) are two fantastic completely free IDEs.

--janak

mirkazemisaman
09-07-2003, 05:51 AM
ummm. i don't know 8O . I did set the class path. Although I really shouldn't have to since the files are in the same directory. Anyways it still doesn't work.
I am probobly going to go with an IDE...

Janak Parekh
09-07-2003, 05:53 AM
ummm. i don't know 8O . I did set the class path. Although I really shouldn't have to since the files are in the same directory.
No. You must set the CLASSPATH. And you must explicitly state the JARs in them. e.g., something like

set CLASSPATH=C:\JavaFiles;C:\JavaFiles\TerminalIO.jar;C:\JavaFiles\TurtleGraphics.jar;C:\JavaFiles\BreezySwing.jar

would be the best.

Trust me, I've been programming Java for 7 some-odd years and even teach it. ;)

--janak