How to call JAR CLASS with CMD
I am a newcomer to java.
This is my JAR file
https://drive.google.com/file/d/16bL0n4KS9IP75tDJhhbeNLeiS3boX3iP/view?usp=sharing
I want to use CMD to call the CLASS inside JAR.
I tried to call getHardware()
java -cp uhfrcom13_v1.9.jar com.handheld.uhfr.UHFRManager.getHardware
I got the error
The main method is not found, define the main method as: public static void main(String[] args) Otherwise the JavaFX application class must extend javafx. The application class must extend javafx.application.Application
Please master teach me how to call
In UHFRManager class you have to add public static void main(String[] args) - in this method you can call your getHardware() method. When running jar file, java is always looking for main method in your class.
Make the following changes and it will work.
Make sure to have a main method (public static void main (String [] args)) in your class where getHardware is a method, then call your getHardware method to work on from the main method [you should call the class from CMD and not the specific method!!].
Make sure to use the following command, in CMD, assuming your class is UHFRManager and getHardware is a method inside it,
java -cp "uhfrcom13_v1.9.jar" com.handheld.uhfr.UHFRManager
I hope it works.
Related
how to fix this problem: Main method not found in class jamel.Jamel, please define the main method as:
public static void main(String[] args)
enter image description here
The main method is just a method that java calls that actually does stuff in your program. If you don't create this method then what is your program for? You'll just have a bunch of classes that you don't use.
If Jamel is your main class where your application starts from scratch then you need
public static void main(String[] args) {
}
this is the entrance of your application to start with.
from here on-words in your main method you should start calling other object.
but from the screenshot I assume that that is not your want. My guess may be wrong. but figure out what is your starting class and does it have a main method and main method calling right object to start your application.
package concurrencyTest;
public class concurrencyTest implements Runnable
{
#Override
public void run()
{ System.out.println("Hello from a thread!"); }
public static void main(String[] args)
{
concurrencyTest c = new concurrencyTest();
Thread t = new Thread(c);
t.start();
}
}
Hi, I'm just trying to get my java concurrency test to run. But I'm getting this error :
Error: Main method not found in class concurrencytest.ConcurrencyTest, please
define the main method as:
public static void main(String[] args)
or a JavaFX application class must extend javafx.application.Application
I'm guessing that somewhere, in the myriad of project directories and subfiles that a java program needs to run, the name of the project or class has been wrongly referenced in lowercase letters. I've manually been thru all the files I can find that span from the root directory and renamed any instance of lowercase 'concurrencytest'. But still it seems the compiler finds a reference to lowercase concurrencytest and so refuses to compile. Any idea where this reference may be?
My root directory, source directory, and java code file are all called 'concurrencyTest'
edit
amended the original code for this question to include 'static' in the main method definition. Doing this was necessary but has not fixed the problem.
You wrote the main definition wrong. You should change it as below:
public static void main(String[] args) {
// ...
}
I found a reference to 'concurrencytest' in the meta file ...\concurrencyTest\nbproject\project.properties
So I changed it to 'concurrencyTest'
Also when NetBeans can't find the expected main method in the class it expects, it opens a 'RunProject' window where it lists main methods from classes it has found. For me it found a main in 'concurrencyTest' so I selected it.
One of these actions solved the problem, but not sure which one.
filename: mainoverloading.java
error: could not find or load main class mainoverloading
class simple{
public static void main(int a)
{
System.out.println(a);
}
public static void main(String args[])
{
System.out.println("Hi");
main(10);
}
}
Your class is named simple (not mainoverloading). Rename the class (or move the file "mainoverloading.java" to "simple.java").
When You compile the above given class using
javac mainoverloading.java
It is successfully compiled and a class file named simple.class is generated in your folder.
You can then run it by typing
java simple.
But this is actually not a good practice, as Elliott Frisch said rename your class into simple.java.
have a look For Windows- HelloWorld
For Linux - HelloWorld
Java allow us to use any name for file name, only when class is not public.
Its running nicely, because for eclipse main class it simple, its smart to identify that simple.class will be created.
If you are running from command line ,
class file created for your code is simple.class so JVM will be unable to find mainoverlading.class
When I create a new main.java file in the default package in my Eclipse project, it generates a main method that looks like:
public static void main(String[] args)
{
}
This immediately raises a warning that says This method has a constructor name. The suggested fix is to remove the void:
public static main(String[] args)
{
}
Now rather than a warning, I get an error: Illegal modifier for the constructor in type main; only public, protected & private are permitted. If I remove the static, my code now looks like:
public main(String[] args)
{
}
This time, I still get an error, but a different one that says:
Error: Main method not found in class main, please define the main method as:
public static void main(String[] args)
Argggh! But that takes me right back to where I started. How do I define the main method so that I don't get any errors or warnings?
I'm using Eclipse Juno Service Release 2 and JavaSE-1.7. Please note, I'm very new to Java; I come from a C# background. Also, this is probably a duplicate question, but I can't find it.
Don't call your class main, but Main.
In general, stick to the Java coding standards: start class names with a capital (Main instead of main) and you won't run into these problems.
If you name the file main.java the class has to be named main too, which is against standard (classes start with a capital letter) but possible. In a class a method named the same as the class is considered a constructor. So to fix your problem and fit the standard rename your class and the file to Main with a capital "M"
Change the name of your class from main to Main or to something else. Also, following the JavaBean API specification, your classes must be in CamelCase with the first letter in capital.
Not 100% related with question, but you should also do not create classes with the names of Java JDK classes, for example String:
public class String {
public static void main(String[] args) {
System.out.println("Try to execute this program!");
}
}
This won't only give problems to compiler/JVM but also for future readers (remember that you are a future reader of your own code as well).
Note: to fix the code above, just refer to java.lang.String class using its full name:
public class String {
public static void main(java.lang.String[] args) {
System.out.println("Try to execute this program!");
}
}
Or even better, change the name of the class.
In java, the class name and file name must match. If you have a file named main.java, then the class name has to be Main too, and in that case, the constructor method would be named main, so you couldn't have a main method.
Change your file and class name to something other than main.
I'm getting Java code generated for me from an application.
I took the JRE and extracted all the files into a new directory.
There is a META-INF folder that has a MANIFEST.MF without any main method.
Witin this JRE is the class of the code I'm interested in however when I CMD the following...
java Steve.class
I get this error...
Could not load for find Main Class Steve.class.
I'm assuming that somewhere in all these class files there is a Main class but how do I search all these documents to find it? Is there an application?
Thanks!
You don't need the .class suffix when invoking a Java program. Do it like this:
java Steve
To work out which class has a main method, you can use javap (Java Class File Disassembler) on each class file. For example:
$ javap Foo
Compiled from "Foo.java"
public class Foo extends java.lang.Object{
public Foo();
public static void main(java.lang.String[]);
}
First: every class that exposes this method signature:
public static void main(String[] args) { }
could be a main class launchable from the JVM and eligible to be put in the manifest to enable shell execution.
Second: when you launch a class in a JRE you must specify the fully qualified name of the class; for example if Steve.class file is in a tree structure such as com/mycompany/app, starting from the root of your application where the MANIFEST directory is, you should launch it, from the root directory, typing:
java com.mycompany.app.Steve
So if Steve exposes a main method and if you can correctly point to it from the root, you can launch it.