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

Need to modify joomla component, Project Description: I want to modify J...

Project Description: I want to modify Joomla component. Now there is Akeeba subscription component on this site. It works and the whole thing is fine, but there is no "teaser

Explain the ? operator in java, Explain The ?  operator in Java ? The...

Explain The ?  operator in Java ? The value of a variable frequent depends on whether a particular boolean expression is or is not true and on nothing else. For example one ge

Overview of struts?, Struts is a framework with set of co operating servlet...

Struts is a framework with set of co operating servlets, classes and JSP tags that create a reusable MVC 2 design.     1. Client (Browser) : A request from the cli

Bluej program, program to find the frequency of a digit in a number

program to find the frequency of a digit in a number

Relate in brief - microsoft vs java, Relate in brief - Microsoft vs Java ...

Relate in brief - Microsoft vs Java Microsoft hates Java, as a Java program (portable) isn't tied to any particular operating system. If Java is popular, then programs written

Java developer with spring framework prerequisite, Java developer with spri...

Java developer with spring framework prerequisite from anywhere Let me know that you have proven experience in java with spring frame work. Send some sample data and provide inf

Unix-like CLI in Java (simple), The assignment is implementing a CLI in Jav...

The assignment is implementing a CLI in Java with several usable commands, using Threads.

Action listener and event listener, differende between action listener and ...

differende between action listener and event listener

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