Jar file only works on my pc

S

stinkinrich88

Hello! I've created a jar file, works fine on my pc (in any directory)
but won't work on anyone elses computer. (One person got the "can't
find main class" message")

any ideas? this is the first time I've ever created a jar file

thanks!
 
J

Jeff

Hello! I've created a jar file, works fine on my pc (in any directory)
but won't work on anyone elses computer. (One person got the "can't
find main class" message")

any ideas? this is the first time I've ever created a jar file

thanks!


Need a lot more info.
Does the jar contain more than one class?
How are you creating the jar?
A jar file contains a manifest file and a pile of classes. Have you
looked at the jar to see what is inside? Do you call any classes in
libraries (report generators, etc.)?
 
I

iherage

Hello! I've created a jar file, works fine on my pc (in any directory)
but won't work on anyone elses computer. (One person got the "can't
find main class" message")

any ideas? this is the first time I've ever created a jar file

thanks!

My suggestion is to delete all the jar file and redo the process.
 
A

Andy Dingley

Hello! I've created a jar file, works fine on my pc (in any directory)
but won't work on anyone elses computer.

As a wild guess, it's not the JAR that's at fault. Instead it probably
has a dependency on something that your PC has installed on the
classpath, but their's doesn't.
 
S

stinkinrich88

As a wild guess, it's not the JAR that's at fault. Instead it probably
has a dependency on something that your PC has installed on the
classpath, but their's doesn't.

ahh your joking!! I just posted a massive post and it didn't show up.
I clicked "reply to author" and I think it went to Andy. Would you
mind posting it for me please?? sorry! (thanks!)
 
S

stinkinrich88

ok, quick note until andy posts my post:

I use textPad 4 to compile (so just javac) and command line to make
jar. I open the jar file using 7zip and all of the class files are
there (as in, the ShutTheBox.class and ShutTheBox$1-10.class (what are
these for!!)) plus the gif files, plus a folder called META-INF with
the manifest file in it. It works fine in any directory on my pc.

Do you recon it's the class file? My mate can't get the applet version
on http://www.txfiles.co.uk/rich/ShutTheBox.html to work. can you? All
my other applets work fine. Is it the stupid $ signs?

I think I have the $'s because of my actionListener inner classes. Is
this a problem? good practice etc?

thanks!!!
 
I

iherage

ok, quick note until andy posts my post:

I use textPad 4 to compile (so just javac) and command line to make
jar. I open the jar file using 7zip and all of the class files are
there (as in, the ShutTheBox.class and ShutTheBox$1-10.class (what are
these for!!)) plus the gif files, plus a folder called META-INF with
the manifest file in it. It works fine in any directory on my pc.

Do you recon it's the class file? My mate can't get the applet version
onhttp://www.txfiles.co.uk/rich/ShutTheBox.htmlto work. can you? All
my other applets work fine. Is it the stupid $ signs?

I think I have the $'s because of my actionListener inner classes. Is
this a problem? good practice etc?

thanks!!!

I think the $ is needed because when you write more than one classes
in a file, java compiler will produce exact the same number of class
files.
I have encountered this kind of problems before. As I remembered I
just carried out the procedure again and carefully followed the
instruction provided by sun.
 
A

Andrew Thompson

On Feb 4, 11:02 am, (e-mail address removed) wrote:
....
I use textPad 4 to compile (so just javac) and command line to make
jar. I open the jar file using 7zip and all of the class files are
there (as in, the ShutTheBox.class and ShutTheBox$1-10.class (what are
these for!!))

Inner/anonymous classes.
..plus the gif files, plus a folder called META-INF with
the manifest file in it. It works fine in any directory on my pc.

The best way to prepare a jar is using the jar tool
provideed with the SDK. Some other tools will use
a less rigourous file structure, and offer non-standard
forms of compression.
Do you recon it's the class file? My mate can't get the applet version
onhttp://www.txfiles.co.uk/rich/ShutTheBox.htmlto work. can you?

Yes it works fine for me, using Java 1.6.
(or at least seems to - 'spinnable dice' appear etc.)
Did your 'mate' get some console output?
What was it?

Was this not originally a question about how to get
an *application* working?
..All
my other applets work fine. Is it the stupid $ signs?

I think I have the $'s because of my actionListener inner classes. Is
this a problem?

No - so long as they are all included.
...good practice etc?

'Neither good nor bad' - it depends on the overall
design whether it makes sense to have them.
I do *not* believe this is the cause of the problem,
unless you have not included them all.

One last thing..
'One person got the "can't find main class" message"'
...If at all possible, get a copy/paste of that message.

Andrew T.
 
A

Andrew Thompson

On Feb 4, 11:02 am, (e-mail address removed) wrote: .....

Yes it works fine for me, using Java 1.6.

Except of course, when I select 'Quit' from the menus.

This leads to a (perfectly explainable)..

java.security.AccessControlException: access denied
(java.lang.RuntimePermission exitVM.0)

Did this project start as an application, or applet?

Andrew T.
 
S

stinkinrich88

Hey! thanks for everyone's help!

I use the this command line to create the jar:

jar cmf yo hello.jar *.gif *.class

'cause my manifest is in a file called "yo"

is this the jar tool you were on about in the JDK?

Yeah, sorry! It is about an application, but I was wondering if it was
a problem with the actual class rather than the jar as my friend
couldn't even get the applet to work! I'll find out about any console
output, thanks!
 
A

Andrew Thompson

I use the this command line to create the jar:

jar cmf yo hello.jar *.gif *.class

'cause my manifest is in a file called "yo"

is this the jar tool you were on about in the JDK?

It is best to quote a little of what you are replying
to (if practical), to give context.

But if you are referring to my earlier comments,
then 'yes'. That is certainly the command.

Note also that you were unsure if the '$' classes
were a problem. That form of the command
('*.class') should find and include all the classes.
Yeah, sorry! It is about an application, but I was wondering if it was
a problem with the actual class rather than the jar as my friend
couldn't even get the applet to work!

Yes, but that applet is loose class files, not
a jar file. (And it would be far better to package
the classes into a jar, for any applet.)

Other thoughts. Since you obviously have
a site, why not upload your jar to it, so we
can have a look at it.

Also, I think this is well suited to a 'web start'*
(JWS) launch, since you have a site, and it
requires at least Java 1.2+ (JWS can handle
the Java versioning for your friend, or at least,
prompt them to update, if needed).

* e.g.'s <http://www.physci.org/jws/>

Note that a JWS launch might also be valuable
for debugging.

Andrew T.
 
A

Andrew Thompson

Ok, I have screen shots and console outputs!

A picture speaks a thousand words
(but note that text, where possible,
does it in much less bandwidth!)
right, console output for java applet version from my freinds
computer: ....
it's on about versions. I have jre 1.6 and she has 1.5 I thinik

First thing you need to find out, is what the minimum
version for this code actually is. I would be surprised
if it even needed Java 1.5, in order to run.

The (most definitive) way to find out, is to compile
against an earlier rt.jar using the -bootclasspath
option, then when you have found the minimum
version, add the -source/target attributes for that
version to javac as well. (Then use JWS to set
the minimum version, and invoke an update if not
installed.)

Is it open source?

Andrew T.
 
S

stinkinrich88

wow, that was pretty over my head I'm afraid!! I found this pdf trying
to explain but it's no use http://www.javageeks.com/Papers/
BootClasspath/BootClasspath.pdf

She can access the other two applets on my site. Would it be helpful
if I jared them and sent them to her? I have re-installed windows
since making them so I may have a newer version of the jre or jdk. But
I haven't used anything particularly complex (as you can see from the
app)

my import statements:

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.util.ArrayList;
import java.applet.*;

nothing very unusual (for me) apart from swing timers and anonamous
inner classes (whatever they're called) these things:

Timer diceTm = new Timer(70, new ActionListener() {
public void actionPerformed(ActionEvent e)
{

and

ActionListener coverEv = new ActionListener(){public void
actionPerformed(ActionEvent e)
{

I'd prefer not to disclose all my code as it is a project for a whole
module for my computer science degree. I don't want other people
getting my code!! (ask if you want any other snippets)
thanks!!
 
S

stinkinrich88

wow, that was pretty over my head I'm afraid!! I found this pdf trying
to explain but it's no use http://www.javageeks.com/Papers/
BootClasspath/BootClasspath.pdf

She can access the other two applets on my site. Would it be helpful
if I jared them and sent them to her? I have re-installed windows
since making them so I may have a newer version of the jre or jdk. But
I haven't used anything particularly complex (as you can see from the
app)

my import statements:

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.util.ArrayList;
import java.applet.*;

nothing very unusual (for me) apart from swing timers and anonamous
inner classes (whatever they're called) these things:

Timer diceTm = new Timer(70, new ActionListener() {
public void actionPerformed(ActionEvent e)
{

and

ActionListener coverEv = new ActionListener(){public void
actionPerformed(ActionEvent e)
{

I'd prefer not to disclose all my code as it is a project for a whole
module for my computer science degree. I don't want other people
getting my code!! (ask if you want any other snippets)
thanks!!
 
A

Andrew Thompson

wow, that was pretty over my head I'm afraid!! I found this pdf trying
to explain but it's no usehttp://www.javageeks.com/Papers/
BootClasspath/BootClasspath.pdf

We can come back to that, but I have no PDF
reader amd could not be bothered finding the
'convert to HTML' link for that.
She can access the other two applets on my site. Would it be helpful
if I jared them and sent them to her?

No. Not in their current form.
..I haven't used anything particularly complex (as you can see from the
app)

No I cannot.
my import statements:

import javax.swing.*;

Swing was introduced in 1.2, but had extra
classes and attributes added in 1.4, and
was consistently updated.
import java.awt.*;

Same thing - I do not believe there is a
single Java version that had no changes
to AWT. This tells us nothing.
I'd prefer not to disclose all my code as it is a project for a whole
module for my computer science degree.

Fair enough, but you might either
- take this further, on your own PC, to determine
the minimum version, and compile to that version
(using a -bootclasspath).
- wrap it in web start, and specify '1.6+', with
a download URL for the JRE.
- wrap it in web start/launch it as you do now,
specify '1.5+', but compile for 1.5 using the
-source/-target flags (and hope for the best).

Given it should only have a small distribution,
I would be tempted to try the last (easiest)
option.

Andrew T.
 
A

Andrew Thompson

thanks a lot! Didn't know you could have jar applets, i'll look into
it. Also, I will look into the webstart stuff.
*
here's the jar file:http://www.txfiles.co.uk/rich/hello.jar

Here's an example..
<http://www.physci.org/test/shutthebox/>
...or more specifically..
<http://www.physci.org/test/shutthebox/hello.jnlp>

That JNLP specifies a minimum Java of 1.6+,
and gives a download URL from Sun. It is
premature though, because at this moment,
there is no 'auto download' available for 1.6,
so if your friend would be willing to send you/us
some screenshots, that would be most
interesting.

The exact JNLP file shown there, is..

[hello.jnlp]
<?xml version='1.0' encoding='UTF-8' ?>
<jnlp spec='1.0'
codebase='http://www.physci.org/test/shutthebox'
href='hello.jnlp'>
<information>
<title>Shut The Box</title>
<vendor>Stinkin' Rich</vendor>
<description kind='one-line'>
Test of the ShutTheBox application using Java 1.6+
</description>
<offline-allowed />
</information>
<resources>
<j2se version='1.6+' href='http://java.sun.com/products/autodl/
j2se' />
<jar href='hello.jar' main='true' />
</resources>
<application-desc main-class='ShutTheBox' />
</jnlp>
[/hello.jnlp]

You would need to change the codebase, for
your own site.

I noticed that the application does not resize
very well. That indicate the layouts are used
in a fragile way, or set to null, or something
worse.

It would pay to fix the (underlying) problem,
but failing that, you might set your frame to
resizable 'false'.

Andrew T.
 

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

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,011
Latest member
AjaUqq1950

Latest Threads

Top