• Post Reply Bookmark Topic Watch Topic
  • New Topic

Classpath driving me mad  RSS feed

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Help - I've been stuck on this for over a week
MY classpath is set to C:\javaclasses and have added this to my PATH

In C:\javaclasses\com\lowewriter\util, I run
java PackageTest

I get the message "Could not find or load main class PackageTest"

I've read other posts on this subject.

It compiled ok - here's the code -

(In C:\javaclasses\lowewriter\com\util\PackageTest.java) -

package com.lowewriter.util;

import com.lowewriter.util.*;

public class PackageTest
{
public static void main(String[] args)
{
while (Console.askYorN("Keep going?"))
{
System.out.println("D'oh!");
}
}
}


and
in c:\javaclasses\com\lowewriter\util -


package com.lowewriter.util;

import java.util.Scanner;

public class Console
{

static Scanner sc = new Scanner(System.in);

public static boolean askYorN(String prompt)
{
while (true)
{
String answer;
System.out.print("\n" + prompt + " (Y or N) ");
answer = sc.next();
if (answer.equalsIgnoreCase("Y"))
return true;
else if (answer.equalsIgnoreCase("N"))
return false;
}
}

}
 
Rancher
Posts: 999
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
MY classpath is set to C:\javaclasses and have added this to my PATH


PATH and class path are two different things.
 
Ranch Hand
Posts: 679
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Amanda Phillips wrote:In C:\javaclasses\com\lowewriter\util, I run
java PackageTest

I get the message "Could not find or load main class PackageTest"

Your class is not called PackageTest, it's called com.lowewriter.util.PackageTest, so your command line should be
java com.lowewriter.util.PackageTest
 
Amanda Phillips
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks, Stuart. That's the trouble with "Teach Yourself" books - no teacher to ask.
Is there a way to shorten the call ? - I'm not a champion typist.
 
Stuart A. Burkett
Ranch Hand
Posts: 679
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Amanda Phillips wrote:Thanks, Stuart. That's the trouble with "Teach Yourself" books - no teacher to ask.
Is there a way to shorten the call ? - I'm not a champion typist.

Afraid not. And once you have more than one project to work with, you'll find the CLASSPATH environment variable is not a good idea because different projects will need different settings. At that point you have to specify the classpath on the command line (with the -cp option) which makes it even longer.
And there are plenty of other command line options that you will need from time to time.
The good news is that when you get to that point, you'll probably know the intricacies of using java and javac on the command line so well, that you'll be safe moving to using an IDE which makes everything a lot easier as long as you know these basic things first.

The best advice I can give you at the moment is to put your command line in a batch file and then just run that.

Have fun
 
Java Cowboy
Sheriff
Posts: 16060
88
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Amanda Phillips wrote:Is there a way to shorten the call ? - I'm not a champion typist.

You could make a small Windows .bat file that contains the command.

For example, create a file called "run.bat" with the command in it. Then when you want to run it, you just have to type "run" <enter>.
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!