Discuss / Java / 模块 hello.world 不具有 ModuleMainClass 属性,求帮助

模块 hello.world 不具有 ModuleMainClass 属性,求帮助

Topic source

大家好,我是在没有用IDE的情况下,直接用命令行编译、打包的,删除了原有文件夹中的project文件和.classpath文件,用记事本重写了一个文件test,保存在当前目录E:\Learning_resource\Java\oop-module下,内容如下:

Manifest-Version: 1.0

Main-Class: com.itranswarp.sample.Main

Class-Path: ./ ./bin

(空行)

目录结构如下:

oop-module(当前目录)
├── bin
│   ├── com
│   │   └── itranswarp
│   │       └── sample
│   │           ├── Greeting.class
│   │           └── Main.class
│   └── module-info.class
└── src
│    ├── com
│    │   └── itranswarp
│    │       └── sample
│    │           ├── Greeting.java
│    │           └── Main.java
│    └── module-info.java
│── test   

打包时运行jar -cvfm hello.jar test -C bin . 结果正常,java -jar hello.jar也跑得通,

创建模块时的语句:

E:\Learning_resource\Java\oop-module>jmod create --class-path hello.jar hello.jmod

运行模块时出现以下问题:

E:\Learning_resource\Java\oop-module>java --module-path hello.jar --module hello.world

显示:模块 hello.world 不具有 ModuleMainClass 属性,请使用 -m <模块>/<主类>

如果按提示改成:

E:\Learning_resource\Java\oop-module>java --module-path hello.jar -m hello.world/com.itranswarp.sample.Main

则运行正常。

我生成模块使用的命令为:

E:\Learning_resource\Java\oop-module>jmod create --class-path hello.jar hello.jmod

想请教一下,该如何修改,才能使生成的模块具有ModuleMainClass属性?

提前感谢所有热心关注和解答~

廖雪峰

#2 Created at ... [Delete] [Delete and Lock User]

哪个类是入口需要在jar命令中指定,你的jar命令缺少参数

多谢老师!我再看看~


  • 1

Reply