bluebyte
bluebyte

Reputation: 560

How to make jar file?

Folder with program:

C:\ProgramFolder

In folder there is a package with classes:

com\mysite\my_program

Main class name:

Program.class

... or fullname:

com.mysite.my_program.Program

In the root folder there is manifest file with content:

Manifest-Version: 1.0
Main-Class: com.mysite.my_program.Program

And I'm making jar-file:

jar cmf MANIFEST.MF my_program.jar com\mysite\my_program\*.class

and trying to lunch it:

java -jar my_program.jar -a -b -c http://google.com/ google

this:

-a -b -c http://google.com/

are paramerts to my program. Tesult is the same without them.

And I'am getting error:

Couldn't find or load main class Цjar

In real program manifest file looks like this:

manifest file

So, I don't know why Цjar

Upvotes: 2

Views: 787

Answers (4)

Biswas
Biswas

Reputation: 127

NetBeans id generate jar file automatically. You have no need to extra work for jar file. You have to just copy the project in NetBeans and compile it.

Upvotes: 0

Ahmed Masud
Ahmed Masud

Reputation: 22402

In C:\ProgramFolder create a subdirectory called META-INF and move the MANIFEST.MF into that, recreate your jar file. and try again.

EDIT

actually the jar m will add that into the right location, but you are missing Class-Path:

Upvotes: 2

gprathour
gprathour

Reputation: 15333

There is a standard way to create packages in Java.

Using command like this :

javac -d . *.java

But if you will simply make Folders and then treat it as packages it will not work.

Try making proper packages.

Upvotes: 0

KV Prajapati
KV Prajapati

Reputation: 94653

Use e (entrypoint) that way you may create a jar without adding manifest file.

jar -cfe my_program.jar com.mysite.my_program.Program.class

or

jar -cfe my_program.jar com/mysite/my_program/Program.class

and launch the program:

java -jar my_program.jar -a -b -c "http://google.com/ google"

Upvotes: 2

Related Questions