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

Assignment Help:

 

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

 


Related Discussions:- How to execute class with a main() method in a package

Explain what is object in java language, Explain what is Object in JAVA lan...

Explain what is Object in JAVA language? They are foundation of object oriented language. They are data structure holds data fields and properties and methods

Decode the code, By pressing ‘6’ (i.e. key’6’ one time) on the keypad, the ...

By pressing ‘6’ (i.e. key’6’ one time) on the keypad, the mobile shows ‘m’ on display screen in write text message area

Zhtml requirements, In addition to your Java code requirements, you also ne...

In addition to your Java code requirements, you also need to enhance the ZHTML for your application. As before, you can continue working with the page(s) you used for the previous

Design a game in java, Ten pigs were all in a pen, enjoying their morning s...

Ten pigs were all in a pen, enjoying their morning slop when a bird flew down from a nearby tree and began picking all the best bits out from the trough. This greatly perturbed the

Javascript validarion, 1. Obtaining the new script: Download and save the a...

1. Obtaining the new script: Download and save the attached comment CGI mailer script form-mail2.pl to your server''s cgi-bin directory, and change the permissions on the script to

Need android geolocation service app, Need Android GeoLocation Service App ...

Need Android GeoLocation Service App Project Description: I want an android service app that will run on the background. The app has to get the users location (latitude an

Describe the final keyword, Describe the final keyword ? The final key...

Describe the final keyword ? The final keyword is used in various different contexts as a modifier meaning in which what it modifies cannot be changed in a few sense. final c

What is a jsp and what is it used for?, Java Server Pages (JSP) is a platfo...

Java Server Pages (JSP) is a platform independent presentation layer technology that comes with SUN s J2EE platform. JSPs are normal HTML pages with Java code pieces embedded in th

Write Your Message!

Captcha
Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd