noritersand
noritersand

Reputation: 18

How omit the package when running the java class (with jar)

Here is my question.

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

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

# test.jar
#   ㄴ com
#       ㄴ test
#           ㄴ job
#               ExampleJob.class

This script works fine. but, i want omit package like this:

$JAVA_HOME/bin/java -cp $CLASSPATH ExampleJob 
# error

How can i?

Upvotes: 0

Views: 156

Answers (1)

vlaxmi
vlaxmi

Reputation: 468

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

Upvotes: 1

Related Questions