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
For what purposes FTP is used in networks? FTP is known as file transfer protocol it is basically used to download or upload files / data to a remote computer.

Explain the user defined Exceptions. User Defined Exceptions are the exceptions which are defined by user for specific purposed. This enables custom exceptions to be generated

Do you provides a Complete source Codes for this application: " a. Write an application for a video store. Place the names of 10 of your favorite movies in a combo box. Let the use

I send you these files in order to make clear image about my task that I want you to design for me an application for PC that used to control robot arm via micro controller PIC18.

AskWrite an application that uses an Array to store 10messages of type String. You will store this Array with 10 messages of your choosing. For example, a message could be “I love

What is White Space? explain proper use of white space in java? White space consists mainly of the space character in which you generates through hitting the space bar on your

Write a program on Filling Rectangles ? The drawRect() method draws an open rectangle, a box if you prefer. If you need to draw a filled rectangle, use the fillRect() method. O

What are the different types of messages available in the JMS API? Ans) Message, TextMessage, BytesMessage, StreamMessage, ObjectMessage, MapMessage are the dissimilar messages

I want Multiplayer Backgammon Game Project Description: We want a multiplayer backgammon as short as well as long one. It should be free and on money also. The games fronted

Please check out the given instruction that I received to do the assessment. I can provide you that link to go on and submit the answers. To assess your coding skills, we would