0

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?

noritersand
  • 18
  • 1
  • 1
  • 3

1 Answers1

1

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

vlaxmi
  • 468
  • 4
  • 18
  • thank for answer. but i want without MENIFEST.MF file. is there any other solution? – noritersand Apr 21 '17 at 05:30
  • 1
    @noritersand Yes. Put the class in the default package, i.e. remove the package statement at the beginning of the source file, and place the .class file directly inside the .jar file. – Andreas Apr 21 '17 at 05:47