How Do I Publish My Working Project (corresponding dot jar doesn'twork on other's PCs)

M

markspace

On my own PC under NetBeans, I have no problem. I see the following from five print statements!


Job one when debugging is to reproduce the problem. Where is the
command line that works? I saw you list your command line in the
previous post, but the one you used here is missing.
 
C

clusardi2k

Job one when debugging is to reproduce the problem. Where is the
command line that works? I saw you list your command line in the
previous post, but the one you used here is missing.

I setup my PC's "Classpath" environment variable to point to the two dot jar files.

Then on my PC at the Command Prompt, with the below command I get the following error message.

java testing.jar

Error: Could not find or load the main class testing.jar.

Thank you,
 
L

Lew

(unknown) said:
System.out.println("Hello 1");

I then ran the project on my friend's PC using the Command Prompt and the command: java testing.jar

This command tells Java to run a 'main()' method from the class 'testing.jar',
which would reside in a class file relative to a classpath element "testing/jar.class".

This class does not exist. Therefore
I received the error message:

Exception in thread "main" java.lang.NoClassDefFoundError: testing/jar

Exactly so.
Caused by: java.lang.ClassNotFoundException: testing.jar
...
Could not find the main class: testing.jar. Program will exit.

Solution:
Don't tell Java to run a nonexistent class.

You need to read the tutorial markspace linked:

Pay attention.
 
C

clusardi2k

About this process, I have two dot jar files in my project. I guess I put both of them in the Manifest.txt file. Question 1: Do I separate these two jar file names with a comma?

That link, basically, says to use the command:

jar cfm NEW.jar Manifest.txt MyPackage/*.class

But executing that command, I get the error message:
MyPackage\*.class : no such file or directory.

So, Question 2: What do I put in place of "MyPackage/*.class". The NetBeans build process creates the folder (C:\testing\build\classes\) which contains about 40 dot .class files.

Thanks,
 
C

clusardi2k

Executing the command:

jar cfm Install_Test.jar Manifest.txt C:\testing\build\classes\testing\*.class does produce a large Install_Test.jar file, but with the below command, I get the associated error message.

java Install_Test.jar
Error: Could not find or load main class Install_Test.jar

Thanks,
 
C

clusardi2k

There are many other classes in the testing project under another folder in C:\testing\build\classes\, but none of them have a main method. I did not mention them on the "jar cfm ..." command line.

The only main method in the testing project is in a package called testing. The testing package is in one of the two dot jar files mentioned in the Manifest.txt file.

I guess there isn't suppose to be a comma between the dot jar files mentioned in the Manifest.txt file.

Thank you,
 
L

Lew

(unknown) said:
java Install_Test.jar

Error: Could not find or load main class Install_Test.jar

Asked and answered upthread. Did you read the answer?

Apparently not. It is rude to disregard answers and ask the same
question again.

Your command line is wrong. Study the docs for how to invoke the "java" command.

As stated, "java Install_Test.jar" tries to run a class called "jar" in the package "Install_Test",
which I'm pretty sure is not what you're trying to do.

RTFM.

http://docs.oracle.com/javase/7/docs/technotes/tools/windows/java.html

in case you don't know where to look for documentation of the "java" command.

RTFM.

Know where TFM is.
 
L

Lew

(unknown) said:
About this process, I have two dot jar files in my project. I guess I put both of them in the Manifest.txt
file. Question 1: Do I separate these two jar file names with a comma?

No. RTFM.
That link, basically, says to use the command:

jar cfm NEW.jar Manifest.txt MyPackage/*.class

But executing that command, I get the error message:

MyPackage\*.class : no such file or directory.

Is there such a file or directory on your system? No? Then why did you specify it?
So, Question 2: What do I put in place of "MyPackage/*.class". The NetBeans build process creates the
folder (C:\testing\build\classes\) which contains about 40 dot .class files.

The actual folder, not the example in a tutorial. Really?
 
A

Arne Vajhøj

I added the path to all my dot jars into an environment variable (user varianble and not a system variable) called classpath

Still not the optimal way.
and was unable to run the project. I mean nothing happened.

Based on the information provided the most likely explanation is
a defect return key on the keyboard.

:)

But maybe there are some information that you are not giving us!

Things like the command line used, the error message etc..

Arne
 
A

Arne Vajhøj

I added the following as the first executable statement (etc) in the project:

System.out.println("Hello 1");

I then ran the project on my friend's PC using the Command Prompt and the command: java testing.jar

I received the error message:

Exception in thread "main" java.lang.NoClassDefFoundError: testing/jar

Well give that the java command is in the format:

java -classpath myprog.jar mypackage.MyClass

or:

java -jar myprog.jar

then that is not surprising.

Arne
 
C

clusardi2k

(1) Research:

Here are notes from books. Obviously, the solution to this problem involvessimply looking-up "manifest files" on the Internet.

(1) The manifest.txt (or dot mf) file:

Main-Class: ClassName

Where the ClassName is the fully qualified name of the class that contains the main method that is executed to start the application. It isn't required, but it's typical to use the extension.mf for manifest files.

For example, suppose you have an application whose main class is GuessingGame, and all the class files for the application are in the package com.lowewriter.game. First, create a manifest file named game.mf in the com\lowewriter\game directory. This file contains the following line:

Main-Class: com.lowewriter.game.GussingGame

Then, run the jar command with the options cfm, the name of the archive to create, the name of the manifest file, and the path for the class files. For example:

jar cfm game.jar com\lowewriter\game\game.mf com\loweweriter\game\*.class

Now, you can run the application directly from a command prompt by using the java comand with the -jar switch and the name of the archive file. For example:

java -jar game.jar

This command starts the JRE and executes the main method of the class specified by the manifest file in the game.jar archive file.

If your operating system is configured properly, you can also run the application by double-clicking an icon for the jar file.

(2) You can add images to a Manifest file if you want.

(3) Complex manifests can have many more entries. The manifest entries are grouped into sections. The first section in the manifest is called the mainsection. It applies to the whole JAR file. Subsequent entries can specify properties of named entities such as individual files, packages, or URLs. Those entries must begin with a Name entry. Sections are separated by blank lines. For example,

Manifest-Version: 1.0
lines describing this archive

Name: Woozle.class
lines describing this file

Name: com/mycompany/mypkg/
lines describing this package

To edit the manifest, place the lines that you want to add to the manifest into a text file. Then run

jar cfm JARFileName ManifestFileName ...

For example, to make a new JAR file with a manifest, run:

jar cmf MyArchive.jar manifest.mf com/mycompany/mpkg/*.class

To add items to the manifest of an existing JAR file, place the additions into a text file and use a command such as

jar ufm MyArchive.jar manifest-additions.mf
 
A

Andreas Leitgeb

Here's the simple approach: [...]

That didn't answer the question about whether your
customers even have Java installed.

It might satisfy for an answer, to describe what
symptoms of not-working they saw - or reported to you.

e.g.: "Upon double-clicking your jar file the mouse fell apart."
 
C

clusardi2k

... wrote: > Here's the simple approach:
[...] That didn't answer the question about whether your customers even have
Java installed. It might satisfy for an answer, to describe what symptoms of
not-working they saw - or reported to you. e.g.: "Upon double-clicking your jar
file the mouse fell apart."

I don't have to explain anything else. Using the link that I supplied, it works perfectly. There are no errors showing up any longer. By following that process, the project works fine on my friends computer!.
 
G

Gene Wirchenko

Here's the simple approach: [...]

That didn't answer the question about whether your
customers even have Java installed.

It might satisfy for an answer, to describe what
symptoms of not-working they saw - or reported to you.

e.g.: "Upon double-clicking your jar file the mouse fell apart."

Of course, one double-clicks on the jar file's filename or icon.
Someone may have tried: "I clicked the jar twice with the mouse. The
jar broke my mouse. And there was pickle juice all over."

Write "click" to see the options menu.

Sincerely,

Gene Wirchenko
 
N

Nigel Wade

Yes I totally forgot about that. I guess I don't actually run java from
the command line very often.

That leaves setting the classpath in the jar itself, which is kind of
tricky if you are going to be moving the jar to other people's
computers. Java WebStart and OneJar come in handy here.

It's not tricky at all if you setup the correct type of NetBeans
project, as I already said. NetBeans will do it all for you. There's no
need to start messing with jar's, manifests or Ant. It's very often
easier to re-create the project as a Java Application than it is to
"fix" a broken one.

With a NetBeans Java application all you need is the contents of the
dist/ directory. The main project jar will have a properly constructed
manifest to allow the jar to be executed with "java -jar project.jar".
Dependency jar's will be in the dist/lib directory, and a Class-Path:
entry in the manifest will include that directory. When you build the
project NetBeans very helpfully tells you exactly how to run it:

"To run this application from the command line without Ant, try:
java -jar "/path/to/project/dist/project.jar".

All you need to distribute to anyone else is the dist/ directory.
There's even a clue in the name.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,981
Messages
2,570,188
Members
46,731
Latest member
MarcyGipso

Latest Threads

Top