Java project does not recognise imports from a generated jar file

I am using the command line jar cvfm server-model.jar nz to generate a jar file called server-model.jar

Some output:

adding: nz/api/pojos/core/util/(in = 0) (out= 0)(stored 0%)
adding: nz/api/pojos/core/util/RenderMarkdownReqMsg.java(in = 845) (out= 283)(deflated 66%)
adding: nz/api/pojos/core/util/RenderMarkdownRespMsg.java(in = 904) (out= 296)(deflated 67%)

After that I am running jar -tvf server-model.jar

Some output:

   0 Wed Jul 02 16:52:20 NZST 2014 nz/api/pojos/core/util/
  845 Wed Jul 02 16:52:20 NZST 2014 nz/api/pojos/core/util/RenderMarkdownReqMsg.java
   904 Wed Jul 02 16:52:20 NZST 2014 nz/api/pojos/core/util/RenderMarkdownRespMsg.java

My problem is that a simple Java project (because I tried almost everything and the project actually use Maven) can not use those classes because the import statement does not recognise them.

It think there is a problem with the MANIFEST.MF and/or classpath. Any suggestion is appreciated.

MANIFEST.MF

Manifest-Version: 1.0
Created-By: 1.7.0_45 (Oracle Corporation)
Jon Skeet
people
quotationmark

Your jar file contains source code - if you want to use a jar file as a library in a project, you need to compile the source code first, and put the class files in the jar file.

For example:

$ javac -d bin src/nz/api/pojos/core/util/*.java
$ jar -C bin -cvf server-model.jar nz

Then running jar tvf server-model.jar you should see the .class files.

You may also want to include the source code in the jar file, as then IDEs can pick up the source and allow you to see it in your main project, and debug into that code too. But it's not required for building.

people

See more on this question at Stackoverflow