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

Project Description: I am seeking a reliable programmer to do the following task. I want a CMS management system to remotely monitor the Android platform on the network the C

How to start a java project? how to draw a flow chart?

public class Foothill {    public static void main(String[] args)    {       Client person_1 = new Client("Bruce Ruprecht", 16000, 10);       Writer writer_1 = new Writer("Adam Buf

Develop a desktop Chatbot application Project Description: Looking for an in depth and smart working chatbot Seeking someone with skills working with AI and chatbots and t

Create a class called DeckOfCards that stores 52 objects of the Card class. Include methods to shuffle the deck, deal a deck, and report the number of cards left in the deck. The s

Project Description: We have a project on hold to complete a due task of a Java swing desktop audio and video server. The admin panel and other features are already implemented.


What are the advantages of multimedia presentations? Write any five. Following are the benefits of multimedia presentations: • Great tool for efficiently communicating ideas

Web-based Application: CIA - OMP Type                                         Web-based Application Role                                          Weblogic Administrato