• Post Reply Bookmark Topic Watch Topic
  • New Topic

executing with classpath variable set  RSS feed

 
Vidur Koushik
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a folder with java programs at C:\Users\Vidur\Desktop\pros
Then there is a sub-folder inside it as C:\Users\Vidur\Desktop\pros\numbers
The classpath environment variable has been set to pros directory.
Any program written in this folder is being executed.

Now there is a java program in the numbers directory named execs as follows:


There are no issues with compilation.But when i run this program as
C:\Users\Vidur\Desktop\pros\numbers>java execs
it throws an error:

Error: Could not find or load main class execs


If the classpath variable is set to a particular directory,then will the programs in sub-directories not execute?
How do i compile and execute program files in sub-directories?
 
Knute Snortum
Sheriff
Posts: 4279
127
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You use a package statement. For instance:



And then execute like this: java numbers.execs

One more thing: your class name should be "Execs". Class names begin with an uppercase letter by convention.
 
Vidur Koushik
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes.That works.But let us say i have two more levels of sub-directories as follows:

C:\Users\Vidur\Desktop\pros\numbers\nums\prgs\ .
Then at command line,i need to specify

java numbers.nums.prgs.classname.

This becomes longer and tedious.Is there a method in which i could just type
java prgs
and execute?
 
Paweł Baczyński
Bartender
Posts: 2083
44
Firefox Browser IntelliJ IDE Java Linux Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can pack your program into a jar and then execute
java -jar prgs.jar

You can read about it here:
https://docs.oracle.com/javase/tutorial/deployment/jar/
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!