为什么我能够直接从bash中执行的JAR? [英] Why am I able to execute JARs directly from bash?

查看:99
本文介绍了为什么我能够直接从bash中执行的JAR?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是一个长期的Java的家伙,知道路与中引用一个主类运行一个JAR一个 MANIFEST.MF 的Jar文件中很容易:

I'm a longtime Java guy, and know that the way to run a JAR with a main class referenced in a MANIFEST.MF file within the Jar is easy:

Java的罐子theJar.jar

我是用这个来启动服务器Fabric3(包含在其标准发行斌/的server.jar )。我注意到,当我从分发压缩包解压缩它,它被标记为可执行文件。一时兴起,我试过

I was using this to start up the Fabric3 server (contained in bin/server.jar in its standard distribution). I noticed that when I unpacked it from the distribution tarball, it was flagged as executable. On a whim, I tried

./的server.jar

从我庆典命令行(庆典 4.1.5版本在Ubuntu 10.10),你瞧,服务器启动,如果我输入了正常 Java的罐子... 命令。该JAR的结构像一个正常的JAR;我做了一个就可以了,也没有#!中的前几个字节命令,这样庆典不应神奇知道启动Java虚拟机吧,对不对?或者有这个版本的庆典的成长与正确适当的清单开始的JAR文件的能力吗?好奇之心想知道...

from my bash command line (bash version 4.1.5 in Ubuntu 10.10), and lo and behold, the server started up as if I had typed the normal java -jar ... command. The JAR is structured like a normal JAR; I did a head on it, and there was no #! command in the first few bytes, so bash shouldn't magically know to start a Java VM with it, right? Or has this version of bash grown the ability to start JARs with a proper manifest correctly? Inquiring minds want to know...

推荐答案

这可能不是bash中的一项功能都没有。如果您运行的是Linux(如你已标记),你可能有 binfmt_misc 内核模块,这确实是一个神奇的一点,当你尝试执行程序。基本上,这样做是它扩展了二进制格式的Linux可以从仅仅精灵执行也包括一些用户定义的格式,有足够的指令来运行它们。

This may not be a feature of bash at all. If you are running linux (as you have tagged) you may have the binfmt_misc kernel module, which does a little bit of magic, when you try to execute a program. Basically what this does is it extends the binary formats that linux can execute from just elf to also include some user defined formats, with enough instructions to run them.

这篇关于为什么我能够直接从bash中执行的JAR?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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