在运行时选择可运行 jar 中的主类 [英] Selecting main class in a runnable jar at runtime

查看:27
本文介绍了在运行时选择可运行 jar 中的主类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在应用中有两个主要类.当我将它打包到一个可运行的 jar(使用 Eclipse 导出功能)时,我必须选择一个默认的主类.

I have two main classes in the app. When I package it to a runnable jar (using Eclipse export function) I have to select a default main class.

有没有办法在运行时从 jar 访问非默认主类?

Is there a way to access the non-default main class from the jar at runtime?

推荐答案

您可以通过 java -cp myapp.jar com.example.Main1java -cp myapp.jar 访问com.example.Main2.jar 中的默认主类用于通过 java -jar myapp.jar 调用应用程序.

You can access both via java -cp myapp.jar com.example.Main1 and java -cp myapp.jar com.example.Main2. The default main class in the jar is for when you invoke your app via java -jar myapp.jar.

有关详细信息,请参阅 JAR_(file_format).当您在 Eclipse 中选择主类时,这将设置在:Main-Class: myPrograms.MyClass 中的 jar 清单 META-INF/MANIFEST.MF 中jar 文件.

See JAR_(file_format) for more details. When you select the main class in Eclipse this is what gets set in: Main-Class: myPrograms.MyClass inside of the jar manifest META-INF/MANIFEST.MF in side of the jar file.

这篇关于在运行时选择可运行 jar 中的主类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆