Can I designate the package inside the JAR file as a class pass?

Asked 2 years ago, Updated 2 years ago, 51 views

Build an application with a class called ExampleJob into a JAR file It is possible to take this JAR file as a class pass and run the Sample Job class. Like below:

#!/bin/bash
JAVA_HOME=/usr/local/jdk1.8.0_121
CLASSPATH=test.jar

$JAVA_HOME/bin/java -cp $CLASSPATH com.test.job.ExampleJob

# Path to physical file 
# # test.jar
#   Come on
#       t test
#           j Job
#               Ex Example Job.class

Here, I would like to omit the package of Example Job without specifying it, but is there a way to designate the package as a class pass?

$JAVA_HOME/bin/java -cp $CLASSPATH ExampleJob 
# Error: Unable to find or load the default class ExampleJob.

When I posted the above question in the stack overflow,

The Manifest.mf file would have the main-class information - e.g. MyJar.jar\META-INF\MANIFEST.MF

Manifest-Version: 1.0
Main-Class: com.mycomp.myproj.dir1.MainClass1
Class-Path: MyJar.jar
MyJar.jar\META-INF\MANIFEST.MF

Then just run it with java -jar MyJar.jar

Similarly for your project you can have your main class configured in the Manifest.mf

I got this answer, is there any other way to designate the main class like this?

java shell

2022-09-22 21:14

1 Answers

None.

That's the package and class pass rule (spec) of jvm.


2022-09-22 21:14

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.