-1

I just wrote Java console project , which i shoud pack as jar file. I googled it alot and found different solutions like (Eclipse) Project -> New Configuration -> e.t.c Then export as jar file using speciefied config. That's nice, but it's not what i need. After making repeatedly - it won't work. I tried to do same as mentioned here: click

Second Solution: create jar using manifest. Well it's much better, because i can specifiy entry point of main.class. But it's won't work due to can;t find out where's annother packages.

Upd: Launcher.class looks like this

package backpack.dao;

public class Launcher{
    public static void main(String[] args){
    Backpack.start();
}
}

My project structure:

src/backpack/dao/Item.java
                /Backpack.java
                /Chromo.java
src/backpack/main/launcher/Launcher.java

The Question is: What should i write in manifest instead of this:

Main-Class src/backpack/main/launcher/Launcher to make executable jar successfully?

P.S Launcher class uses instances from Backpack.java Please don't downgrade. I'm rookie

Thanks

Malakai
  • 3,011
  • 9
  • 35
  • 49

1 Answers1

0

What is the package of the Launcher.java? Have you included package name to the classname in manifest.txt? Remember, when Launcher.java is in package "backpack.main.launcher" your classname in manifest.txt will be:

Main-Class src/backpack.main.launcher.Launcher

instead of:

Main-Class src/backpack/main/launcher/Launcher

Also, remember about this:

The text file must end with a new line or carriage return.

To check what exactly is wrong with your jar file run it in the command line using:

java -jar MyJar.jar

and paste here output with error message.

For more help you can check this example from Oracle: link

Edit:

I recreated your project structure and I have found the solution (at least I think I have :) )

  1. Compile your code and go to the parent directory with compiled code (with *.class files, this should be "out" directory or something like this - depending from your IDE). For example: when your project is in some/path/src/backpack/main/launcher go to src directory.
  2. Run command: jar cvfe MyJar.jar backpack.main.launcher.Launcher -C . . (Yes, two dots at the end)

This should create jar with name MyJar.jar and manifest file (-e flag) with main class backpack.main.launcher.Launcher. -C flag include all *.class files recursively from directory . (current one), so both from dao and launcher package.

  1. Test jar: java -jar MyJar.jar
baza92
  • 344
  • 1
  • 10
  • Thanks for the answer, this isn't a good solution. because at launcher.class i invoke method of annother class. This class locates at annother location. so after creating jar via cli ( i receive error 2: 'can't see backpack.dao package'). – Malakai Apr 12 '15 at 18:07
  • I'm a little bit confused about structure of your project: 1. What is package of Item.java, Backpack.java and Chromo.java? 2. According to structure of your project how it is possible that Launcher.java is in package `backpack.dao`? It should be in `backpack.main.launcher` package. Does your project compile? 3. Why do you need to insert Launcher.java in separate directory? – baza92 Apr 12 '15 at 20:46
  • 1
    Hello. Yes, I double checked project. So I'm glad to answer to your questions: 1. All three classes belong to `backpack.dao` package. 2. Simply, I invoke static method run from Backpack.class. No, Launcher already is on `backpack.main.launcher` package 3. Yes. I know it's lil' bit weird why I run program like this, but it prevents me from messing in the code ;) P.S project compiles and run succesfully. The Only thing i need is to pack it as WAR file. – Malakai Apr 15 '15 at 09:50