remove me
remove me

Reputation: 65

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!

Upvotes: 2

Views: 12546

Answers (2)

Andrea Colleoni
Andrea Colleoni

Reputation: 6021

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.

Upvotes: 5

dogbane
dogbane

Reputation: 274542

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[]);
}

Upvotes: 6

Related Questions