Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I find the main class? Entry Point?

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!

like image 418
remove me Avatar asked Mar 24 '26 22:03

remove me


2 Answers

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[]);
}
like image 162
dogbane Avatar answered Mar 26 '26 11:03

dogbane


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.

like image 21
Andrea Colleoni Avatar answered Mar 26 '26 12:03

Andrea Colleoni