0

I am trying to run a jar file from the Win7 command line, but am getting the dreaded could not find or load main class PRCreateExecution.

I can successfully build the jar file from a Win7 batch file on the command line.

My current manifest file is named PRCreateExecution.mf and is located in here: C:\WDEclipseIDEWorkspace\MC3\src\PurchaseRequests\

The manifest file contains:

Manifest-Version: 1.0
Created-By: 1.8.0_40 (Oracle Corporation)
Main-Class: PurchaseRequests.PRCreateExecution.class

(extra LF is here)

I run the Win7 batch file to build the jar from C:\WDEclipseIDEWorkspace\MC3\src\PurchaseRequests:

jar -cvmf PRCreateExecution.jar C:\WDEclipseIDEWorkspace\MC3\bin\PurchaseRequests\PRCreateExecution.mf C:\WDEclipseIDEWorkspace\MC3\bin\PurchaseRequests\PRCreateExecution.class C:\WDJarFiles

The jar file gets created successfully.

Now I'm using this batch statement to try and run the jar file:

java -cp C:\WDEclipseIDEWorkspace\MC3\bin\PurchaseRequests;. PurchaseRequests.PRCreateExecution

from in here:

C:\WDEclipseIDEWorkspace\MC3\src\PurchaseRequests

but am getting the could not find main class PurchaseRequests.PRCreateExecution.

PRCreateExecution source snippet:

package PurchaseRequests;
public class PRCreateExecution {
public static void main(String[] args)

Thanks for any help...

Jon Skeet
  • 1,421,763
  • 867
  • 9,128
  • 9,194
user337447
  • 69
  • 9
  • Usually when I run `.jar` files from batch files, I use the code `java -jar JarFileName.jar`. – hyper-neutrino Apr 30 '15 at 18:51
  • I'm using a package so I'm pretty sure mine needs to be package.jarFilename.jar – user337447 Apr 30 '15 at 20:26
  • If you go to `File > Export`, you can select the `class` with the `main` method. Then, export it as a `.jar` file. That way, all referenced code will be put into the `.jar` file. Run it with `java -jar ClassWithMainMethodName.jar`. – hyper-neutrino May 01 '15 at 14:23

3 Answers3

0

Firstly, it sounds like you're not actually trying to run your jar file at all. You're not mentioning it anywhere on your command line.

Secondly, it looks like your classpath is wrong - it should probably be

java -cp C:\WDEclipseIDEWorkspace\MC3\bin;. PurchaseRequests.PRCreateExecution

That's assuming that the bin directory contains a PurchaseRequests directory which contains PRCreateExecution.class

Thirdly, you should follow Java naming conventions for packages - they should be lower case.

Jon Skeet
  • 1,421,763
  • 867
  • 9,128
  • 9,194
0

I faced a similar kind of issue building distributable jar files using Netbeans. My suggestion would be to try and run the jar directly from the command line and from within the directory path of its location.

It is seen that you have something like this in your manifest file:

Manifest-Version: 1.0 Created-By: 1.8.0_40 (Oracle Corporation) Main-Class: PurchaseRequests.PRCreateExecution.class (extra LF is here)

I suggest you change the lines as follows:

Manifest-Version: 1.0 Created-By: 1.8.0_40 (Oracle Corporation) (insert CF)
Main-Class: PurchaseRequests.PRCreateExecution.class (extra LF is here)

You may use this as your reference:

https://docs.oracle.com/javase/tutorial/deployment/jar/appman.html

This post might be of use, too:

http://stackoverflow.com/questions/12767886/use-of-manifest-file-in-java
Satadru
  • 1
  • 1
0

Remove the .class suffix from the manifest.

It should look like:

Manifest-Version: 1.0
Created-By: 1.8.0_40 (Oracle Corporation)
Main-Class: PurchaseRequests.PRCreateExecution

Afterwards run java -jar (name of your jar-file).jar

mp911de
  • 17,546
  • 2
  • 55
  • 95
  • I removed the .class from the .mf file. java -jar PurchaseRequests.PRCreateExecution.jar Error:Unable to access jarfile PurchaseRequests.PRCreateExecution.jar – user337447 Apr 30 '15 at 20:13
  • I had a typo but your response was the solution. How do I give you the credit? – user337447 Apr 30 '15 at 22:56