How to execute class with a main() method in a package, JAVA Programming

 

Example:  You have a class named "Set" in a project folder "e:\myProject" and package named com.zxy.client, will you be able to compile and execute it as it is

 

 

package com.xyz.client;

 

public class Pet {

public static void main(String[] args) {

System.out.println("I am found in the classpath");

}

}

 

To run-> e:\myProject> java com.zxy.client.Set

 

The answer is no and you would get the following exception: "Exception in thread "main" java.lang.- NoClassDefFoundError: com/zxy/client/Set". You have to set the classpath. How shall you do that? One of the following ways:

 

1. Set the operating system CLASSPATH environment variable to have the project folder "e:\myProject".

2. Set the operating system CLASSPATH environment variable to have a jar file "e:/myProject/client.jar", which has the Set.class file in it.

3. Run it with -classpath or -cp option as given below:

c:\>java -cp c:/myProject com.xyz.client.Pet

OR

c:\>java -classpath c:/myProject/client.jar com.xyz.client.Pet

 

Posted Date: 7/25/2012 12:29:37 AM | Location : United States







Related Discussions:- How to execute class with a main() method in a package, Assignment Help, Ask Question on How to execute class with a main() method in a package, Get Answer, Expert's Help, How to execute class with a main() method in a package Discussions

Write discussion on How to execute class with a main() method in a package
Your posts are moderated
Related Questions
The method should printout line numbers from 1 to howmany in the previous format -ONLY WHEN is divisble by 3 but is should not oupt more then 3 numbers on the line. input 1 outpu

Define network organization? What are important features of network organization? Network Organization : Network organization is an inter firm organization in which is charac

Describe advantage of the event-delegation model over the earlier event-inheritance model ?

Explain The java.net package Each package describes a number of classes, interfaces, exceptions, and errors. For instance, the java.net package contains these, classes, interfa

Why we Avoiding Short Circuits ? If you need all of your boolean expressions evaluated regardless of the truth value of each, then you can use & and | instead of && and ||. The

Explain the term Naming Packages in details? As you saw previously name space conflicts arise if two pieces of code declare the similar name. Java remains track of what belongs

SCHOOL MANAGEMENT SYSTEM

Your first task is to implement the Movie class to store all the relevant information on a single DVD Movie, including its catalog number, title, year of release, rating, rental pe

I have been working on my compiler''s parser now. And for some reason i cant make my parse tree printer to work. SyntaxTree keeps on showing as null when i invoke the print() metho

For this assignment you are provided with a class called LNode which can be used as a list node for a linked list of ints. You are also provided with an abstract class called LList