0

Trying to create an executable jar file - but I can't seem to get the manifest correct

manifest file "tdms.mf"

Manifest-Version: 1.0
Main-Class: rackserials.tdms

Jar creation

jar cfvm rackserials.jar tdms.mf  *.class assetdata.xlsx
added manifest
adding: Asset.class(in = 10946) (out= 3918)(deflated 64%)
adding: TDMSConnection.class(in = 2599) (out= 1372)(deflated 47%)
adding: tdms.class(in = 13402) (out= 6732)(deflated 49%)
adding: assetdata.xlsx(in = 23998) (out= 20987)(deflated 12%)

Running this command from within Directory called "tdms" contents:

Asset.class
TDMSConnection.class
tdms.class **where my main is located**
tdms.mf
assetdata.xlsx

CLI

java -jar rackserials.jar 
Error: Could not find or load main class rackserials.tdms
David
  • 13
  • 1
  • 7

1 Answers1

0

The directory structure inside the JAR file must match the package structure of your classes, and the Main-Class attribute must be set to the fully-qualified name of the class that contains the public static void main(String[] args) method that is the entry point of your application.

Are your classes in the package rackserials? Then the *.class files inside the JAR file must be in a directory named rackserials, and not in the root directory of the JAR file.

You can list the content of a JAR file using jar tvf rackserials.jar. It should look like this:

META-INF/MANIFEST.MF
rackserials/tdms.class
(whatever other files)

See Packaging Programs in JAR Files in Oracle's Java Tutorials for all the details of creating JAR files and working with manifest files to create an executable JAR.

Jesper
  • 202,709
  • 46
  • 318
  • 350
  • Thank you Jesper - this got me on the right track. The classes are in the package rack serials but I was attempting to make my JAR file from within the directory they were all contained within as well - so the classpath was wrong. Looking at how I could run using java rackserials.tdms got me thinking and I arrived to the same conclusion you posted here. Thanks again – David Nov 16 '18 at 22:37