It's not a secret anymore!
The moose likes Beginning Java and the fly likes Unable to Run A Java Program Thar uses java.util.regex package Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Unable to Run A Java Program Thar uses java.util.regex package " Watch "Unable to Run A Java Program Thar uses java.util.regex package " New topic
Author

Unable to Run A Java Program Thar uses java.util.regex package

Kasiraj Murugesa pandian
Greenhorn

Joined: Sep 09, 2011
Posts: 21

Hi ,
I was trying to execute a regular Expression program that was given as an example from the "The Complete Reference :Java 2 Fifth Edition " Book. I typed the program in a Notepad and Compiled it in Command Prompt.
Source Code


Although i could compile the above program successfully . I wasn't able to run it in the Command prompt with the Command :

java Regexp3

Error: Could not find or load main class Regexp3

It would be great if anyone could tell me how exactly can i execute this program in command prompt .

Thanks in Advance


Regards,
Kasiraj
Stephan van Hulst
Bartender

Joined: Sep 20, 2010
Posts: 4087
    
  18

Did you put the class file in the correct directory with regards to its package? Did you set the CLASSPATH variable?


The mind is a strange and wonderful thing. I'm not sure that it will ever be able to figure itself out, everything else, maybe. From the atom to the universe, everything, except itself.
Kasiraj Murugesa pandian
Greenhorn

Joined: Sep 09, 2011
Posts: 21

Stephan van Hulst wrote:Did you put the class file in the correct directory with regards to its package? Did you set the CLASSPATH variable?


Thanks A lot for Letting me know about the Classpath variable. Actually i have set the Classpath variable for Apache Tomcat when i tried to execute a servlet program without using Netbeans . So only after you've told me about it, i just remembered it and removed the Classpath and now it uses the previous classpath that i gave for java .

Thanks Again !

But is it really possible to Set two Classpath Variables ?. If so how do we set them ?.



Regards,
Kasiraj
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 44464
    
  34
It's better to set a classpath for each application, because each application will require a different classpath. We have an FAQ about it.
Try something like set CLASSPATH=.;C:\myFolder\myJar.jar at the command line, which will set it for the lifetime of that command window. Note that syntax won't work on Linux/Mac/Unix, which use the keyword "export".
Ulf Dittmer
Rancher

Joined: Mar 22, 2005
Posts: 42958
    
  73
Actually i have set the Classpath variable for Apache Tomcat

Tomcat does not use the CLASSPATH variable.

But is it really possible to Set two Classpath Variables ?.

No, there is only a single CLASSPATH variable. You can have multiple terminal windows/shells, though, and each can have its own CLASSPATH.

I generally advise never to use the CLASSPATH variable, it's more trouble than it's worth. Better to list the required libraries with a "-cp" switch when using javac or java. If there are too many libraries to make this practical, consider using Ant.
Kasiraj Murugesa pandian
Greenhorn

Joined: Sep 09, 2011
Posts: 21

Ulf Dittmer wrote:Actually i have set the Classpath variable for Apache Tomcat
Tomcat does not use the CLASSPATH variable.


In setting the Classpath for tomcat , i meant to include the library file i.e for the servlet-api file that is located in tomcat/common/lib/ . i guess we can do that . Sorry to be not much specific about it

Thanks Anyways

Kasiraj Murugesa pandian
Greenhorn

Joined: Sep 09, 2011
Posts: 21

Thank you All For your Valuable information that helped me Execute my Regular expression Program .



Thanks Again


Regards,
Kasiraj
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 44464
    
  34
You're welcome
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Unable to Run A Java Program Thar uses java.util.regex package
 
It's not a secret anymore!