简体   繁体   English

我如何找到主要班级? 入口点?

[英]How do I find the main class? Entry Point?

I'm getting Java code generated for me from an application. 我正在从应用程序中为我生成Java代码。 I took the JRE and extracted all the files into a new directory. 我使用了JRE,并将所有文件提取到一个新目录中。 There is a META-INF folder that has a MANIFEST.MF without any main method. 有一个包含MANIFEST.MF的META-INF文件夹,没有任何主要方法。

Witin this JRE is the class of the code I'm interested in however when I CMD the following... Witin这个JRE是我感兴趣的代码类,但是当我CMD以下代码时...

java Steve.class 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? 我假设所有这些类文件中的某个地方都有一个Main类,但是如何搜索所有这些文档以找到它呢? Is there an application? 有申请吗?

Thanks! 谢谢!

You don't need the .class suffix when invoking a Java program. 调用Java程序时不需要.class后缀。 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. 要确定哪个类具有main方法,可以在每个类文件上使用javap (Java类文件反汇编程序)。 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. 可能是可以从JVM启动的主类,并且可以放入清单中以启用Shell执行。

Second: when you launch a class in a JRE you must specify the fully qualified name of the class; 第二:在JRE中启动类时,必须指定该类的完全限定名称; 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: 例如,如果Steve.class文件采用com / mycompany / app之类的树形结构,则从应用程序的根目录(MANIFEST目录所在)开始,则应从根目录启动它,键入:

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. 因此,如果Steve公开了main方法,并且您可以从根目录正确指向它,则可以启动它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM