?
Solved

Jar File Mystery

Posted on 2001-07-16
18
Medium Priority
?
441 Views
Last Modified: 2013-11-23
Hi;

I'm trying to bundle up a Java 2 ( 1.3.1 ) client app as an executable jar
file that the user ( windoze ) can double click like an exe and have it
come up.
 
 
Everything works find executing it from a windows 2000 command line with

"java -jar MyJar.jar"


However, when I double click it ( windows 2000 ) the application comes up,
but it looks like it can't find some of the component classes and it cant
read some of the *.ini ( text ) files I made.


I used a great Jar app called JavaCannery:
http://www.cs.umd.edu/users/starz/cannery/


It goes finds all of you dependencies and writes your manifest file
appropriately.....so that isn't the problem.


I noticed that in Windows Explorer | tools | folder option | file types  
that jar files are executed with "javaw.exe -jar "?

Why the difference from the command line argument?  Does this difference
have anything to do with my app working from the command line and simply
double clicking it?


Thanks in advance

Steve
0
Comment
Question by:Steve34
  • 7
  • 2
  • 2
  • +3
15 Comments
 
LVL 3

Expert Comment

by:superschlonz
ID: 6287634
java.exe and javaw.exe are the same except that javaw.exe doesn't open a log window (DOS box).

Could it be that you have two different JRE's on your machine ? Then you have to specify the full path to the javaw.exe of 1.3.1 in the file types.
0
 

Author Comment

by:Steve34
ID: 6287760
I have several javaw.exe s, but I *think* only one is in my systems envrionmental variables.

I'm on windows 2000.

Here are my germane environ variables:

Path:
======================================
(my JDK folder holds version 1.3.1 )
=======================================
C:\JDK\bin;C:\Perl\bin\;C:\Util;%SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem


Class Path:
=======================================
.;c:\Classes;C:\Util





File Extension Path For Jar Files
===================================
( Obtained from Windows Explorer | tools | folder options | file types| advanced | edit )
this was put in by the software, the other two environ variables above I made
=====================================
C:\Program Files\JavaSoft\JRE\1.3.1\bin\javaw.exe -jar %1
0
 
LVL 7

Expert Comment

by:Igor Bazarny
ID: 6287922
Hi,

Just few brainstorming ideas.

How do you open your .ini files? It might be just working directory problem. Check out "user.dir" system property value. Where are the component classes your app can't load? Is there something special about them? Maybe your manifest has wrong infromation about external references...

Regarsds,
Igor Bazarny
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 92

Expert Comment

by:objects
ID: 6287957
What if you run javaw from the command line?
And from different directory location?

Can we see the code used to load ini's?
0
 
LVL 4

Expert Comment

by:Oliver_Dornauf
ID: 6288534
Well, if you start from the command line the current directory is set different from starting with double click.
To check this use the fully qualified path to you ini file and see what's happens.

0
 

Author Comment

by:Steve34
ID: 6289672
bazarny:
=====================
The ini files are just windows 2000 text files I put the ini extension on.  The path is hardcoded in the application.  For example one ini file is called "ftp.ini".  In the app the path variable ( String ) is set to sPath = "ftp.ini".  The ini files are in the same directory as the jar file.  I have no references to the ini files in the manifest ( do I need them? ).


Everyone:
=============
The jar file works as an application...completely, if I execute it from the windows 2000 command line with:
java -jar MyJar.jar

If I double click it ( see my first comment above ) the app will come up, but it will not find some of the objects.  Nothing special about them.  I used a tool ( see my originial post ) to make the jar file manifest so I know that is not an issue.

Objects:
====================
Nothing happens when I execute javaw.exe from the windows 2000 command line. No error messages, the command prompt just returns whether I do:

"javaw.exe -jar MyJar.jar"   or
"javaw.exe "
0
 

Author Comment

by:Steve34
ID: 6289743
Update:
====================

For some reason
"javaw.exe -jar MyJar.jar" now works from the command line.

The application works perfectly when I do either from the command line:
=====================
"java -jar MyJar.jar"  
or
"javaw.exe -jar MyJar.jar"


However MyJar.jar files to find classes in MyJar.jar and ini files in the same directory when I double click it.

Oliver, what did you mean when you said the command set s the  current directory?  What is set to what?

0
 
LVL 4

Expert Comment

by:Oliver_Dornauf
ID: 6289790
When you start you application from the command line like javaw.exe -jar MyJar.jar the root directory for the java vm is your current directory from where you start.
So, if you jar file is locate in c:\java\myapp and you open a file ftp.ini the real file name is c:\java\myapp\ftp.ini. If you are in a diffrent dir (like when you double click) ftp.ini is not a sufficent file name.
But you can put you *.ini file just inside your jar-file, when you not want to playaround with windows pathnames etc.
Try to put your ini files in the root of your jar file.

0
 

Author Comment

by:Steve34
ID: 6289817
I need to have the ini files outside of the jar file.

Is there some sort of environ variable I can set?  I can always distribute the jar file with an installer that can change the needed environ variable.

The other, more important issue is that when double clicked
MyJar.jar can't find objects inside of itself
0
 

Author Comment

by:Steve34
ID: 6290208
Hi;

I thought I would restate the problem as some things have changed to make it clear.


I have a Java 1.3.1 Swing Application I would like to distribute through
an executable jar file that windows users can activate by double clicking.

When I double click abc.jar the application comes up but then
fails.  It looks like abc.jar isn't finding one of the classes inside of
itself ( abc.jar )

However, abc.jar works perfectly when I execute it from the windows 2000 command
line using:


java -jar abc.jar
or
javaw -jar abc.jar


Why is this?

What can I do to fix it when I distribute the app to my users.

BTW here are my windows 2000 environment variables in case that is an
issue:
===============================================================

Class Path:
.;c:\Classes;C:\Util


Path:
.;C:\JDK\bin;C:\Perl\bin\;C:\Util;%SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem


I have the jdk 1.3.1 installed in:
C:\JDK

I have the JRE 1.3.1 installed in:
C:\Program Files\JavaSoft\JRE\1.3.1

The association for jar files ( window explorer | tools | folder options |
file types ):
C:\Program Files\JavaSoft\JRE\1.3.1\bin\javaw.exe -jar %1






0
 

Author Comment

by:Steve34
ID: 6291299
I found my problem.

Its explained in the copy of the bug report I submitted to sun



==========================================
Hi;

I just submitted this bug report to sun.

It could save you a lot of pain


======================================================================
Bug Report: JDK 1.3.1 doesn't match JRE 1.3.1
======================================================================

Hi;

I discovered that the jre ( java.exe, javaw.exe ) that comes with the
jdk 1.3.1 supports a deprecated option that the stand alone jre 1.3.1
does not. Not all jre 1.3.1's of the same build are the same.

In the jre that comes with jdk 1.3.1 you can execute code that uses
"Cp850" for character encoding. In the stand alone jre 1.3.1 you
cannot and get an exception thrown.


This is a particularly insidious bug as many java programmers have
both the jre that comes with the jdk and a stand alone version on
their computers( for example, getting the java plugin for your browser).
You can easily compile, run, and distribute java code that you think will
work with the jre 1.3.1 only distribution....but will not.

I figured this out ( after much pain ) after taking the c:\jdk\bin out
of my path. The same code which execute with the jdk's jre, failed
with the same version sun jre that I got as a separate distribution.


Here is the chunk of code where I discovered this. I have put the
block of code between "=======" lines. The code is further followed
by more explanatory details:


================================================================

public static void main(String argv[])
{

String result = " ";

// Read The Input File Into A String
try
{
FileInputStream file = new FileInputStream ("in.txt");
DataInputStream in = new DataInputStream (file);
byte[] b = new byte[ in.available() ];

in.readFully (b);
in.close ();

//result = new String (b, 0, b.length, "US-ASCII");
result = new String (b, 0, b.length, "Cp850");

System.out.println(result);
}
catch ( Exception e )
{
e.printStackTrace();
}
}
=================================================================


I ran the command "java -version" on both jre 1.3.1 s just to make
sure that each jre 1.3.1 was the same. The output of "java -version
was identical:




From:
C:\Program Files\JavaSoft\JRE\1.3.1\bin\java.exe ( & javaw.exe )
=========================================================
java version "1.3.1"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.3.1-b24)
Java HotSpot(TM) Client VM (build 1.3.1-b24, mixed mode)



From:
C:\JDK\bin\java.exe ( & javaw.exe )
=========================================================
java version "1.3.1"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.3.1-b24)
Java HotSpot(TM) Client VM (build 1.3.1-b24, mixed mode)


My apologies if this "bug" is really an illusion of my ignorance.
0
 
LVL 7

Expert Comment

by:Igor Bazarny
ID: 6291412
Hi,

I guess that your problem is that your second jre is not internationalized version--it doesn's support most  encodings. BTW, it would help if you include stack trace of your exception.

Check out lib\i18n.jar presence/content for your default jre (check out registry key HKEY_LOCAL_MACHINE\SOFTWARE\JavaSoft\Java Runtime Environment\1.3 for location). Look for sun/io/ByteToChar*.class to find supported encodings.

Anyway, I agree that this problem is really annoying and hard to find. Unsupported encoding often leads to really strange error reports. Especially when it's encoding choosen by default.

Regards,
Igor Bazarny
0
 
LVL 92

Expert Comment

by:objects
ID: 6291705
Good to hear you got it fixed :)
And thanks for the info, will keep it in mind :)
0
 

Author Comment

by:Steve34
ID: 7495852
I would like to delete this question.

The problem was never resolved.

There should be a way to delete a question once someone else offers an answer or a comment.  Sometimes the experts don't answers
0
 

Accepted Solution

by:
modulo earned 0 total points
ID: 7498028
PAQ and points refunded.

modulo

Community Support Moderator
Experts Exchange
0

Featured Post

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
Suggested Courses
Course of the Month13 days, 13 hours left to enroll

755 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question