简体   繁体   English

尝试创建jar文件时找不到文件异常

[英]file not found exception when trying to create jar file

I have the following Java file(apples.java): 我有以下Java文件(apples.java):

public class apples
{
   public static void main(String[] args)
    {
       System.out.println("Apples here.");
    }
}

saved in the source folder of the MyProject directory. 保存在MyProject目录的source文件夹中。

I compile apples.java and save the apples.class file into the classes folder of the MyProject directory. 我编译apples.java并将apples.class文件保存到MyProject目录的classes文件夹中。

I then create manifest.txt with the following content: 然后,我创建带有以下内容的manifest.txt:

Main-Class: apples

I then navigate into the MyProject/classes directory via cmd prompt(Windows XP) and type the following command: 然后,我通过cmd提示符(Windows XP)导航到MyProject / classes目录,并键入以下命令:

jar -cvmf manifest.txt app1.jar apples.class

I get the following message in the command prompt: 我在命令提示符下收到以下消息:

java.io.FileNotFoundException: manifest.txt (The system cannot find the file specified)

           at java.io.FileInputStream.open(Native Method)

What is wrong and how do I fix it? 有什么问题,我该如何解决?

Put the .jar argument first 首先放.jar参数

jar -cvmf app1.jar manifest.txt apples.class

Make sure both "apples.class" and "manifest.jar" are in the current directory. 确保“ apples.class”和“ manifest.jar”都在当前目录中。

I would also encourage you to: 我也鼓励您:

1) Use packages (instead of the default package) 1)使用软件包(而不是默认软件包)

2) Capitalize your class names ("Apples.java" instead of "apples") 2)大写您的类名(“ Apples.java”而不是“ apples”)

Here's a nice, short tutorial that might help: 这是一个不错的简短教程,可能会有所帮助:

http://www.mkyong.com/java/how-to-add-your-manifest-into-a-jar-file/ http://www.mkyong.com/java/how-to-add-your-manifest-into-a-jar-file/

It is a common mistake people make. 这是人们常犯的错误。 While creating the manifest.txt, make sure that you don't name it "manifest.txt", after you've already selected the file to be a txt. 在创建manifest.txt时,请确保已将文件选择为txt之后,不要将其命名为“ manifest.txt”。 That makes it "manifest.txt.txt". 这就是“ manifest.txt.txt”。 Hope it helps. 希望能帮助到你。

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

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