Help me with jar file...
I have created a jar file with the following cammand
jar cvf XXX.jar com images
where com is the folder which holding my all .class files and images is the folder which hold all my image files.
but the prob is that when i run my jar file with the following command
javaw XXX.jar com.Main
Main is the main class
i can't see nay images on my buttons in short i can't accress images files...
satinderjit,
Here is some code that you can use to grab an image (whether in a jar or not). Note though that your .class files will live in the com directory. So, in order for your images to load (with image path = "images/myImage.gif", you either have to move your image folder to your com folder or use the following string for your image path "../images/myImage.gif".
/*=*******************************************************************
* getImage(): grabs an image from the same location this file is at. *
* Works for when the images are in a jar or not. *
public static Image getImage(String img) {
/* Replace the 'YourClassName' with the name of your
class. Note that the .class file of the class
that this method resides in must be placed
relative to where the images are stored. So
if the images are in a folder called images,
this .class file must be placed in its parent
directory. */
URL url = YourClassName.class.getResource(img);
Image image = null;
if (url == null) {
System.err.println("Unable to load image: " + img);
} else {
image = Toolkit.getDefaultToolkit().getImage(url);
return image;
}//end getImage
/* use the above method in the following manner
(notice the forward slash). The image path I
provided should work with your current setup. */
ImageIcon icon = new ImageIcon(getImage("../images/myImage.gif"));tajenkins
Similar Messages
-
hi, first of all sorry if my post is in wrong forum...but my application is done using swing so i am posting this here....and regarding my question...
I have made an GUI using Java swings and my application is working fine. Now i want to make an executable jar file for my GUI. I have read some tutorilas on making jar files and this is what i have done...
i have created a manifest file called mainClass.txt which has
Main-Class: MainWindow ,where MainWindow is my main class name.
Then i ran the jar utility with this command line:
jar cmf mainClass.txt example.jar *.class
With this line, I told jar to create a JAR file (option c) with modifications to the manifest file (option m) as specified within mainClass.txt, naming the JAR file (option f) as example.jar and including everything that matches the pattern *Class
everything is file till now but my problem is ...I have some library files from JFreechart software included in my GUI to generate barcharts..How can i include these library files in my example.jar file..
Kindly help me
Thanks
byeeI had this problem too. I ran my program out of JCreator and it worked flawlessly. I jarred it up into and Executable Jar and I would get a runtime error explaning I have not included the correct libraries.
What I did was look at the error, for example say it said something like:
org.uhoh.PathSys ClassDefNotFound (or something similar to this)
What I did was extract the library that contained that class file. Then in my project file where I kept my classes I made the folder org, then in org I made uhoh. Inside uhoh I copied over PathSys.class.
I hope I addressed the problem you speak of. I am only a novice but this is how I figured it out. If anyone knows a better way let us know =D -
hi all
i'm trying to deal with a jar file:
in myPackage.myClass i call:
Class.forName("org.hsqldb.jdbcDriver");i know that this file is contained into the file named "hsqldb.jar"
where shall i place this jar file in order to be found by myPackage.myClass without edit any system variable like class-path?
thanx a lot
sandroFor the jar, no, as jar's must be explicitly referenced on the classpath.
For the un-jar'd classes yes.
If they are extracted so their directory tree starts in the same place as the directory tree of your classes
e.g.
someDirectory
|
+-- yourComapay
| |
| +- yourApp
| |
| +- YourClasses
|
+-- com
|
+- importedPackage
|
+- ImportedClassesSo long as 'someDirectory' is on the classpath. It should run. -
I am new with JAR files please help me
Hi Dear All,
I am new with JAR files, I know concept, but dont know how to careate JAR, and how do i use it?
Please help me.
ThanksThis tutorial covers that:
http://java.sun.com/docs/books/tutorial/deployment/jar/index.html -
How to use javap with jar files ?
how to use javap with jar files ?
thanksAs long as the jar is on the class path, your gold. So,
javap -classpath myjar.jar mypackage.MyClass
Chuck -
URGENT Help for applet with JAR file in Netscape
I am having Applet with few classes
Html is in /www directory
and all class files are in /www/javaclassfiles
I jared all javaclassfiles with following command
c:\www\javaclassfiles>jar -cvf sample.jar TaxPaymentAppletForm.class *.class
where sample.jar is my jar file and TaxPaymentAppletForm.class is the main applet class file.
THEN I DELETED ALL CLASS FILES & KEPT ONLY SAMPLE.JAR FILE ON SERVER
My html code is like below:
<APPLET CODE="TaxPaymentAppletForm" ARCHIVE="sample.jar" CODEBASE="JavaClassFiles" WIDTH=460 HEIGHT=400></APPLET>
The things are running on IE properly, but not on Netscape. Netscape is giving following error :
java.io.IOException: <null>
at netscape.net.URLConnection.connect(Compiled Code)
at netscape.net.URLConnection.getInputStream(Compiled Code)
* at netscape.applet.AppletClassLoader.grabArchiveFile(Compiled Code)
at netscape.applet.AppletClassLoader.openArchive(Compiled Code)
at netscape.applet.AppletClassLoader.openArchive(Compiled Code)
at netscape.applet.AppletClassLoader.<init>(Compiled Code)
at netscape.applet.AppletClassLoader.getClassLoader(Compiled Code)
at netscape.applet.DerivedAppletFrame$LoadAppletEvent.dispatch(Compiled Code)
at java.awt.EventDispatchThread$EventPump.dispatchEvents(Compiled Code)
at java.awt.EventDispatchThread.run(Compiled Code)
at netscape.applet.DerivedAppletFrame$AppletEventDispatchThread.run(Compiled Code)
# Unable to load archive http://nearbuy_server:90/iras/JavaClassFiles/sample.jar: java.io.IOException: <null>
# Applet exception: class TaxPaymentAppletForm could not be loaded
# Applet exception: class TaxPaymentAppletForm could not be loaded
# Applet exception: class TaxPaymentAppletForm could not be loaded
In netscape also it is sometimes running some times not, without any logical reson.
Any help regarding this is appreciated
manishaFollowing is the more detailed analysis when applet is running and when not
On local server, it is running fine on both IE / Netscape
When I transfered jar file to live server
On IE it is running for the first time and then onwards not running, If I clear the catch then again applet is running.
For second time it is giving following error :
IOException Loading Archive: http://dev1.janusx-collections.com/iras/JavaClassFiles/AppletForm.jar
java.io.IOException: dev1.janusx-collections.com:80//iras/JavaClassFiles/AppletForm.jar
at com/ms/net/wininet/http/HttpInputStream.connect
at com/ms/net/wininet/http/HttpInputStream.<init>
at com/ms/net/wininet/http/HttpURLConnection.createInputStream
at com/ms/net/wininet/WininetURLConnection.getInputStream
at com/ms/vm/loader/JarArchiveSet.loadNextJar
at com/ms/vm/loader/JarArchiveSet.getResourceBits
at com/ms/vm/loader/JarArchiveSet.getClassData
at com/ms/vm/loader/ResourceLoader.getClassData
at com/ms/vm/loader/URLClassLoader.findClass
at com/ms/vm/loader/URLClassLoader.loadClass
at com/ms/vm/loader/URLClassLoader.loadClass
at com/ms/applet/AppletPanel.processSentEvent
at com/ms/applet/AppletPanel.processSentEvent
at com/ms/applet/AppletPanel.run
at java/lang/Thread.run
java.lang.ClassNotFoundException: TaxPaymentAppletForm
at com/ms/vm/loader/URLClassLoader.loadClass
at com/ms/vm/loader/URLClassLoader.loadClass
at com/ms/applet/AppletPanel.processSentEvent
at com/ms/applet/AppletPanel.processSentEvent
at com/ms/applet/AppletPanel.run
at java/lang/Thread.run
ON Netscape it is NOT running at all on from live server and error is as given in above first post.
manisha -
I'm writing a program in VB that calls on a JAR file. It has been working great for weeks. Last night, I moved the JAR file to a new location on my machine, and it suddenly stopped working at all.
I know nothing about Java. Do I need to recompile the file? I tried moving the whole directory back to its original location but it didn't help.
Thanks in advance.Dude I'm telling you straight up, the program has a bug. The evidence is in the error message. Maybe the bug was not manifested before, but it was there.
Do you have access to the source? Do you know how to compile it? You should recompile it with the -g flag to include debug information. Then the error message will include a method name and line number for the offending portion of code. If you're not able to figure it out yourself, you could post that portion of code here for someone to comment on. -
URLClassLoader - with JAR Files- - - Please Help
Hi all,
I have two seperate JAR files which contain same files but different progressive versions.JAR 1 is version V1 and JAR 2 is Version V1.1
I have a program which loads classes from these two JARS and runs certain comparsions on them.CODE IS SHOWN and SO is ERROR.PLEASE HELP and ADVISE.Im on a UNix box using JDK 1.3.
CODE:
====
1.In my main i define the TWO JARS PATHS and the item to compare called ENTITYNAME as:
String jarFile1 = "/xenv/GFINet_Java/6.2_Z1/1.3.X/gfinet_entities.jar";
String jarFile2 = "/xenv/GFINet_Java/6.1_Y1/1.3.X/gfinet_entities.jar";
String entityName = "gfinet.entities.GFIBasketEntity";
2.Then i call the function
EntityVersionComparator evc = new EntityVersionComparator();
evc.test(jarFile1, jarFile2, entityName);
3.Test function loads the JARS
private void test(String jarFile1, String jarFile2, String entityName) throws Exception {
URLClassLoader jar1 =
(URLClassLoader)newClassLoader(jarFile1);
URLClassLoader jar2 =
(URLClassLoader)newClassLoader(jarFile2);
4. Load that item ENTITYNAME FROM JAR.
// load GFIBasketEntity from Jar1
GFIBaseEntity ent1 =
(GFIBaseEntity)loadClass(jar1, entityName).newInstance();
PROBLEM ERRORS:
==============
Exception in thread "main" java.net.MalformedURLException : no
protocol :/xenv/GFINet_Java/sun4/6.2.Z2/Solaris8/3.3.2/1.3.X/lib/gfinet_entities.jar
at java.net.URL.<init>(URL.java:473)
at java.net.URL.<init>(URL.java:376)
at java.net.URL.<init>(URL.java:330)
at EntityVersionComparator.newClassLoader(EntityVersionComparator.java:143)
at EntityVersionComparator.test(EntityVersionComparator.java:88)
at EntityVersionComparator.main(EntityVersionComparator.java:74)
WHATS GOING ON..Is there something wrong with the path?Pls advise
jasonI also in my CODE have:
private ClassLoader newClassLoader(String path)
throws MalformedURLException
{ URL url = new URL(path);
return new URLClassLoader(new URL[]url); -
Now what? Help with .jar files
Hey. I just finished a program. I want to share it with my friends or anyone else. I can create a .jar file but I have no idea what to do next. Is there an easy way to "publish" your programs (like create a .exe file?). Any help or ideas would be appreciated. Thanks, Merlot14
java -jar MyFile.jarwill work if you've set your manifest correctly. If you're distributing only to Windows users, you could include a shortcut, I believe. Similarly, for distribution to Linux/OS X users, you could include a shell script.
-
I have made an application that uses the javax.comm library for serial port drivers. It works perfectely but when I put all the .class in a .jar and start the application it starts properly with no errors but it doesn't see the com's of the computer.
I would apreciate if you could help me out
greetings
paulYou have to modify the source code of the javax.comm class files you are using.. the line contains "package javax.comm;" should be deleted. And then compile those modified files and put the compiled files to your jar file. Or you can create a folder "javax" and subfolder "comm" in that folder and put those original .class files into "javax/comm". After that, put that "javax" folder into your jar file.
-
Help me this error :"uncaught error fetching image" with Jar file
Hi all.
I have a program written with Swing. This program has one button and fetch Image into this button. Image is in Images directory .When I run this program by IDE, It's OK. However, when I compress classes of this program into Jar file and run, it can not recognize the path to Image. And it leads to this error:
"uncaught error fetching image"
I have tried to look for a lot of information relating to this problem on the internet but nothing is possible.
Please help me. Thank you.
And my program
http://www.mediafire.com/?j0yzun4d0mxWhen you JAR it's different. Try something like this:
BufferedReader br=new BufferedReader(new InputStreamReader(getClass().getResourceAsStream(listname)));
you don't hae to do the BufferedReader, but the getClass().getResource... is what you need. -
Problem with jar file please help!!
Hi everybody
I make a jar file using Jbuilder;my application interact with oracle and when i try to run it ,I get the following message:
"no driver was found "
however i add the oracle driver in my jar file as a library dependencies.
could some one helpI don't know whether this will help you or not.
You have mentioned that drivers are added into jar file which you have created. Similar situation I faced. In my case I added classes12.zip for ORACLE thin drivers. For this to work I had to set classpath for this zip file. Once I set the classpath for this zip file my application started working fine.
So if you are using any zip or jar file for your driver you will have to define it in your classpath.
Mushy -
I have a jar file named Helper.jar with
com.xyz.util.Helper.class in it.
Now I have a SrcFile.java that
imports com.xyz.util.Helper;
It compiles fine with:
java -classpath Helper.jar;. SrcFile.java
...and runs fine with:
java -cp Helper.jar;. SrcFile
When I jar it with:
jar cvfm SrcFile.jar SrcFile.mf *.class
...and run it with:
java -cp Helper.jar;. -jar SrcFile.jar
I get the following exception:
java.lang.NoClassDefFoundError: com/xyz/util/Helper
...but yet, Helpler.jar runs fine with:
java -jar Helper.jar
Does anyone have any idea what I am doing wrong or
do I have to un-jar the Helper.jar file and
re-jar SrcFile.jar with all the .class files?I've replied to this same thread in the New To Java Technology fourm, see there for a suggestion.
-
OK, folks, I need some help here...
And I have researched on this prior to this post, but I still don't get it.
I have a simple application in Reminder.java file. When I compile it, I get Reminder.class and Reminder$ReminderThread.class, because I have an inner class.
I place those files in Reminder directory. I want to make an executable JAR file, so I made a manifest file outside the Reminder directory that contains these lines
Manifest-Version: 1.0
Main-Class: Reminder.Remindersince the Reminder.class is within the Reminder directory, I understood I had to have a prefix "Reminder."
In the command line, I type
jar cmf manifest Reminder.jar Reminder/Reminder.class Reminder/Reminder$ReminderThread.classAnd I do get a Reminder.jar file, but when I double-click on it, I get a popup saying "Could not find the main class. Program will exit!"
So, what am I doing wrong and how can I fix this? As I said, I have researched, but I can't understand what went wrong nor how to fix the problem.
Any help will be greatly appreciated.Never mind, I solved it, I was missing a carriage return in my manifest file. I feel so stupid now...
-
PROBLEM WITH JAR FILES!!! QUICK HELP NEEDED!
Hi guys
What problem could I have if I can run a program with java.exe (I use JDK 1.5) but not in a JAR-File (I added the Main-Class-key to MANIFEST.MF)???
Please answer fast!!!
ThanksWhat problem could I haveThat depends a lot on what you did wrong. What did you do to run the Jar file, and what error message(s) did you then get?
Maybe you are looking for
-
GetProcessForPID is deprecated; what to use instead?
I have been using GetProcessForPID to get the ProcessSerialNumber for the running application, as in ProcessSerialNumber psn; int pid = [[NSProcessInfo processInfo] processIdentifier]; OSStatus error = GetProcessForPID(pid, &psn); I then use this Pro
-
OK, while I do appreciate the new layout control, iWeb seems like a siginificant downgrade from the old .mac homepage application for displaying photographs. In addition to the images being smaller in screen size, they are also larger in terms of mem
-
Does the ACR histogram reflect the full image?
I am trying to streamline camera raw file preperation into a 3rd party color corrector. When I take a raw and zero out all the settings, how come things can still be clipped out? Isn't everything that is captured ---therefore in the histogram? How do
-
Aperture 3 can't read iPhoto library
I have my iPhoto library on an external drive that Aperture 2 could read just fine. After upgrading to Aperture 3, I can no longer import from iPhoto because it can't read the drive with my iPhoto libraries. It can read every other drive. Repairing t
-
Print PDF Attachments Automatically...???
Hello All, I have an eFax account that emails me a PDF attachment when I get a fax... Is there any way that anyone can think of that I print the PDF attachments and automatically when an email comes into that account...?? For billing purposes, I open