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

查看:603
本文介绍了在运行时选择可运行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.Main1 java -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天全站免登陆