473,326 Members | 2,126 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

Question about classpath

Hi everyone, I recently installed the Sun J2SE SDK on my machine, and
I am having trouble running the java.exe interpreter for my Java
compiled code. I remember that I had to set my environment CLASSPATH
variable to whatever the current directory is, but I forgot the exact
characters to denote this. Or that there was an extra call to the
java interpreter (like -cp or -classpath) to indicate the current
directory, but that escapes me as well. Can anyone help?

Thanks
Jul 17 '05 #1
7 4150
Herman,

It might be that you're confusing the CLASSPATH environment variable with
the PATH variable. The CLASSPATH should not contain any references to where
the "java.exe" is located. This must be set in your PATH environment
variable.

Depending on which os you're on you can specify the jdk/bin directory in
different ways, ie:

Windows:
------------------------
Add a reference to the JDK bin directory in the PATH environment variable.
From the command line (cmd) this can be done by issuing the following
statement
set PATH=%PATH%;<path to your jdk bin directory>
To see what's in your path:
echo %PATH%

Setting the PATH environment can also be done by right-clicking the "My
computer"-icon on your desktop, selecting properties from the pop-up menu.
Click the "Advanced"-tab and select the "Environment variables"-button. the
Path can be appended from this window. By doing it this way, the PATH
environment will be set permanently as opposed to the method above where it
will only be set locally for the command prompt shell.

Linux:
------------------------
Set your PATH for the shell you're in by issuing the following statement:
export $PATH=$PATH:<path to your jdk bin directory>

To set the PATH more permanently for the logged in user, this depends upon
what kind of command shell you're using. For bash you can include the above
statements in the file ".user_profile" that is located on the user root
directory (~username).

Solaris:
------------------------
Manipulate the symbolic link /usr/java to point to the directory where the
JDK is installed. This can be done by deleting the existing symbolic link
and creating a new:
delete /usr/java
ln -s /usr/java :<path to your jdk directory>
I'm sorry for "overanswering" your request, but this is something lots are
troubled with, so I figured it wouldn't hurt with some details.

--
Millian Brave

"Herman" <he*******@hotmail.com> skrev i melding
news:d6************************@posting.google.com ...
Hi everyone, I recently installed the Sun J2SE SDK on my machine, and
I am having trouble running the java.exe interpreter for my Java
compiled code. I remember that I had to set my environment CLASSPATH
variable to whatever the current directory is, but I forgot the exact
characters to denote this. Or that there was an extra call to the
java interpreter (like -cp or -classpath) to indicate the current
directory, but that escapes me as well. Can anyone help?

Thanks

Jul 17 '05 #2
Hi Millan, I can run the java.exe fine from wherever I am. The only
thing is, I get an exception when I run the program, called

Exception in thread "main" java.lang.NoClassDefFoundError: Hello

I believe that the CLASSPATH variable doesn't know where to look to
find the .class file, but can't find it. How do I set CLASSPATH to
the current directory?

Thanks
Jul 17 '05 #3
Hey guys, I figured it out, so don't bother with the Classpath
question. Thanks anyway.

Regarding another question, how do I check whether or not a String
object is not null? For example,

if (args[0].length() <= 0 || args[1].length() <= 0)
{
System.out.println("Need the name of input file as first parameter");
System.out.println("And name of output file as second parameter");
System.exit(0);
}

doesn't work. I get the following exception:

Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 0

When I pass no parameters. The String class doesn't have any IsEmpty
methods like CString in Visual C++. What's the Java equivalent?
Thanks
Jul 17 '05 #4
Herman wrote:
Hey guys, I figured it out, so don't bother with the Classpath
question. Thanks anyway.

Regarding another question, how do I check whether or not a String
object is not null? For example,

if (args[0].length() <= 0 || args[1].length() <= 0)
{
System.out.println("Need the name of input file as first parameter");
System.out.println("And name of output file as second parameter");
System.exit(0);
}

doesn't work. I get the following exception:

Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 0

When I pass no parameters. The String class doesn't have any IsEmpty
methods like CString in Visual C++. What's the Java equivalent?
Thanks


To answer your question, the test you have above is fine to detect if a
valid String reference is an empty string.

To answer your next question, you can test if a String reference is
valid by comparing it to the keyword "null":

String myString = makeAStringOrReturnNull();
if (myString == null)
{
// error handling
}
else
{
// use myString
}

Now, that answers the questions you are asking. The real problem,
however is that you are not asking the right questions.

The actual problem is that the args array (argument to the main method)
is zero-length. What you need to is check the length of the args array
before using args[0] or args[1] like so:

if (args.length < 2)
{
System.out.println("Need the name of input file as first parameter");
System.out.println("And name of output file as second parameter");
System.exit(0);
}

// Now you can check if the args are empty
// If you are really paranoid, you can check for null, but I suspect
// JVM wouldn't produce null arguments
if (args[0] == null || args[0].length() == 0
|| args[1] == null || args[1].length() == 0)
{
System.out.println("Need the name of input file as first parameter");
System.out.println("And name of output file as second parameter");
System.exit(0);
}

HTH,
Ray

Jul 17 '05 #5
If you really meant CLASSPATH, the period represents the current directory
in both Windows and Unix. For example:

Windows (backslashes and semicolons):
CLASSPATH=c:\foo;.;c:\bar;

Unix (slashes and colons):
CLASSPATH=/foo:.:/bar;

"Millian Brave" <mi******@start.no> wrote in message
news:f4******************************@news.teranew s.com...
Herman,

It might be that you're confusing the CLASSPATH environment variable with
the PATH variable. The CLASSPATH should not contain any references to where the "java.exe" is located. This must be set in your PATH environment
variable.

Depending on which os you're on you can specify the jdk/bin directory in
different ways, ie:

Windows:
------------------------
Add a reference to the JDK bin directory in the PATH environment variable.
From the command line (cmd) this can be done by issuing the following
statement
set PATH=%PATH%;<path to your jdk bin directory>
To see what's in your path:
echo %PATH%

Setting the PATH environment can also be done by right-clicking the "My
computer"-icon on your desktop, selecting properties from the pop-up menu.
Click the "Advanced"-tab and select the "Environment variables"-button. the Path can be appended from this window. By doing it this way, the PATH
environment will be set permanently as opposed to the method above where it will only be set locally for the command prompt shell.

Linux:
------------------------
Set your PATH for the shell you're in by issuing the following statement:
export $PATH=$PATH:<path to your jdk bin directory>

To set the PATH more permanently for the logged in user, this depends upon
what kind of command shell you're using. For bash you can include the above statements in the file ".user_profile" that is located on the user root
directory (~username).

Solaris:
------------------------
Manipulate the symbolic link /usr/java to point to the directory where the
JDK is installed. This can be done by deleting the existing symbolic link
and creating a new:
delete /usr/java
ln -s /usr/java :<path to your jdk directory>
I'm sorry for "overanswering" your request, but this is something lots are
troubled with, so I figured it wouldn't hurt with some details.

--
Millian Brave

"Herman" <he*******@hotmail.com> skrev i melding
news:d6************************@posting.google.com ...
Hi everyone, I recently installed the Sun J2SE SDK on my machine, and
I am having trouble running the java.exe interpreter for my Java
compiled code. I remember that I had to set my environment CLASSPATH
variable to whatever the current directory is, but I forgot the exact
characters to denote this. Or that there was an extra call to the
java interpreter (like -cp or -classpath) to indicate the current
directory, but that escapes me as well. Can anyone help?

Thanks


Jul 17 '05 #6
Thanks, Ray. I'm new to Java coming from C++, so that's why a lot of
stuff I don't already know. Thanks again!
Jul 17 '05 #7
Me
To answer your question directly you can ask

if( args[ 0 ] == null)
....

But in this case, it's not the string that's null, it's the array that's
empty. So you can check that with

if( args.length == 0 )
....
Rich

in article d6**************************@posting.google.com, Herman at
he*******@hotmail.com wrote on 10/14/03 6:37 PM:
Hey guys, I figured it out, so don't bother with the Classpath
question. Thanks anyway.

Regarding another question, how do I check whether or not a String
object is not null? For example,

if (args[0].length() <= 0 || args[1].length() <= 0)
{
System.out.println("Need the name of input file as first parameter");
System.out.println("And name of output file as second parameter");
System.exit(0);
}

doesn't work. I get the following exception:

Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 0

When I pass no parameters. The String class doesn't have any IsEmpty
methods like CString in Visual C++. What's the Java equivalent?
Thanks


Jul 17 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Christopher V. Kimball | last post by:
How do I put many jar files into the classpath without having to name each one? This is in Windows 200, in which setting any environmental variable is tedious. Chris Kimball
4
by: Abdelhalim MIMOUNI | last post by:
hi, i'm new to java, and using sun last JDK, and i'm trying to understand how work this feature when we want to compile at command line ? i'm trying to set the classpath to the directory of the...
2
by: Bekkali Hicham | last post by:
hi, i have downloaded the latest version 2.4 of Xerces, and unziped it, i end up with a diectory hierarchy like this c:\xerces-2_4_0\XercesImpl.jar c:\xerces-2_4_0\XercesSamples.jar...
1
by: Dave Keays | last post by:
I am setting-up an experimental web service using Apache Axis but I'm having problems. AXIS can't find a library that I've verified exists on my computer and that CLASSPATH points to it. I'm using...
6
by: Rhino | last post by:
I am writing Java UDFs using DB2 V8.2 (Fixpack 8) on Windows XP. I would like to create some common code classes that are visible to the UDFs on my system but I'm not having a lot of luck so far....
3
by: jeremiah johnson | last post by:
Okay this is going to sound really dumb. Skeet, you can poke fun of me in your own special way if you see fit. Is there a way to reproduce the CLASSPATH functionality of Java within C#? Would...
7
by: dlarsson | last post by:
Okay folks, I thought I was doing something very, very simple, but I cannot seem to get this to work at all. Can anyone identify what I am doing wrong here-? _________________________________ ...
9
by: KevinRobinson | last post by:
Hi, Can anyone please tell me how to add or change a Java classpath in SUSE Linux 9.3. I have set up a Tomcat server but my Java Classes will not run although they do on a windows box. ...
1
Ganon11
by: Ganon11 | last post by:
Hey all, I'm setting up my computer to run Java for a class I'm taking, and I've gotten into a bit of a snag. I've set the CLASSPATH system variable to include the base folder of my homeworks...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.