Loading an image from a jar with web start
Hi,
I have a jar file that contains all the classes and .gif images that my program uses. I am trying to set this up to use web start. I have the .jnlp file working correctly, but I get i/o errors when my images are loaded via an ImageIcon.
The Developer Guide says that "[t]he jar file will typically contain Java classes that contain the code for the particular application, but can also contain other resources, such as icons and configuration files, that are available through the getResource mechanism. "
I can't figure out how getResource() works. I've tried this:
ClassLoader.getSystemClassLoader().getResource(fileName).getContent()
but the content it returns is an Object, Given the filename, it should be my gif, but I don't know what type of Object it is, much less how to turn it into an Image.
Can't anyone help? I'd really appreciate it!
Thanks,
B. Danny K.
use Thread.currentThread().getContextClassLoader().loadResource() to get the JNLPClassLoader.
The system class loader will not find resources in jars loaded by java web start.
/Dietz
Similar Messages
-
Using Signed Jars with Web Start
Hi
I am working with an application that needs to access disk. I signed the jars, and in the jnlp file I gave full permisions to it. My question is how Web start recognize that the jar is signed, should I upload the certificate and how to do it? I am having permissions problems at the client side.
Thank you!!!http://www.vamphq.com/jwsfaq.htmlI don't want to be picky but the Unofficial Web Start FAQ moved to the Lopica Web Start Paradise site a couple of months ago. Please update your bookmarks. The new web address (URL) is:
http://lopica.sourceforge.net/faq.html
and the ongoing in-progress FAQ Update and Errata page is online @ http://lopica.sourceforge.net/update.html
- Gerald
(Unofficial Web Start FAQ Editor) -
Issues with Loading Images from a Jar File
This code snippet basically loops through a jar of gifs and loads them into a hashmap to be used later. The images all load into the HashMap just fine, I tested and made sure their widths and heights were changing as well as the buffer size from gif to gif. The problem comes in when some of the images are loaded to be painted they are incomplete it looks as though part of the image came through but not all of it, while other images look just fine. The old way in which we loaded the graphics didn't involve getting them from a jar file. My question is, is this a common problem with loading images from a jar from an applet? For a while I had tried to approach the problem by getting the URL of the image in a jar and passing that into the toolkit and creating the image that way, I was unsuccessful in getting that to work.
//app is the Japplet
MediaTracker tracker = new MediaTracker(app);
//jf represents the jar file obj, enum for looping through jar entries
Enumeration e = jf.entries();
Toolkit toolkit = Toolkit.getDefaultToolkit();
//buffer for reading image stream
byte buffer [];
while(e.hasMoreElements())
fileName = e.nextElement().toString();
InputStream inputstream = jf.getInputStream(jf.getEntry(fileName));
buffer = new byte[inputstream.available()];
inputstream.read(buffer);
currentIm = toolkit.createImage(buffer);
tracker.addImage(currentIm, 0);
tracker.waitForAll();
images.put(fileName.substring(0, fileName.indexOf(".")), currentIm);
} //while
}//try
catch(Exception e)
e.printStackTrace();
}compressed files are not the problem. It is just the problem of the read not returning all the bytes. Here is a working implementation:
InputStream is = jar.getInputStream(entry);
ByteArrayOutputStream os = new ByteArrayOutputStream(1024);
try{
byte[] buf = new byte[1024];
int read;
while((read = is.read(buf)) > 0) {
os.write(buf, 0, read);
catch(Exception e){
e.printStackTrace();
return null;
image = Toolkit.getDefaultToolkit().createImage(os.toByteArray());
This works but I think you end up opening the jar a second time and downloading it from the server again. Another way of getting the images is using the class loader:
InputStream is = MyApplet.class.getResourceAsStream(strImageName);
In this case, the image file needs to be at the same level than MyApplet.class but you don't get the benefit of enumerating of the images available in the jar. -
Load image from SQL database with ASP?
Hello,
Does anyone know a tutorial where you can load an image from
a SQL database ?
I would like to show this image in Flash, but i don't know
how to load in from a SQL database using ASP.
Regards,
MichealFlash cannot load images from an SQL database.
Flash can load JPEG, PNG, GIF, SWF, MP3, and FLV files.
An SQL database can be used to store the file names and their
location. ASP can retrieve that data from the SQL and return to
Flash to load the above file formats.
For Flash to do the communication with ASP you need to
determine if you are using URL Encoded or XML data structures.
For URL Encoded data you look at
LoadVars.sendAndLoad
For XML Encoded data you look at
XML.sendAndLoad
Then in their onLoad methods you use
MovieClip.loadMovie
to load JPEG, GIF, PNG and SWF;
Sound.loadSound
for MP3,
NetConnection.connect,
Video.attachVideo and NetStream.play for FLV.
For the ASP side the work with the database has nothing to do
with Flash other than using any search variable sent from Flash
with LoadVars.sendAndLoad or XML.sendAndLoad. In other words it
could be an HTML form sending the same variable and calling the
same ASP script. Same with returning values except with Flash only
URL Encoded or XML data structures are sent back and not
HTML. -
Can't load any classes from infobus.jar (WL 6.0 SP1)
Hi,
I am deploying an .ear file, which has one .war file in it. The war file, has
infobus.jar, inside it under \WEB-INF\lib. Whenever in my servlet code I try to
load a class from infobus.jar, I get the following exception :
About to load class javax.infobus.InfoBusDataConsumer<<<<<<<<<<java.lang.ClassNotFoundException: InfoBusDataConsumer
at weblogic.utils.classloaders.GenericClassLoader.findClass(GenericClassLoader.java:178)
at weblogic.utils.classloaders.ChangeAwareClassLoader.findClass(ChangeAwareClassLoader.java:45)
at java.lang.ClassLoader.loadClass(ClassLoader.java:297)
at java.lang.ClassLoader.loadClass(ClassLoader.java:253)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:313)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:120)
at XDILoginForm.init(XDILoginForm.java:99)
at weblogic.servlet.internal.ServletStubImpl.createServlet(ServletStubImpl.java:638)
at weblogic.servlet.internal.ServletStubImpl.createInstances(ServletStubImpl.java:581)
at weblogic.servlet.internal.ServletStubImpl.prepareServlet(ServletStubImpl.java:526)
at weblogic.servlet.internal.WebAppServletContext.preloadServlet(WebAppServletContext.java:1078)
at weblogic.servlet.internal.WebAppServletContext.preloadServlets(WebAppServletContext.java:1022)
at weblogic.servlet.internal.HttpServer.loadWARContext(HttpServer.java:499)
at weblogic.servlet.internal.HttpServer.loadWebApp(HttpServer.java:421)
at weblogic.j2ee.WebAppComponent.deploy(WebAppComponent.java:74)
at weblogic.j2ee.Application.deploy(Application.java:175)
at weblogic.j2ee.J2EEService.deployApplication(J2EEService.java:173)
at weblogic.management.mbeans.custom.Application.setLocalDeployed(Application.java:217)
at weblogic.management.mbeans.custom.Application.setDeployed(Application.java:187)
at java.lang.reflect.Method.invoke(Native Method)
at weblogic.management.internal.DynamicMBeanImpl.invokeSetter(DynamicMBeanImpl.java:1136)
at weblogic.management.internal.DynamicMBeanImpl.setAttribute(DynamicMBeanImpl.java:773)
at weblogic.management.internal.DynamicMBeanImpl.setAttribute(DynamicMBeanImpl.java:750)
at weblogic.management.internal.ConfigurationMBeanImpl.setAttribute(ConfigurationMBeanImpl.java:256)
at com.sun.management.jmx.MBeanServerImpl.setAttribute(MBeanServerImpl.java:1356)
at com.sun.management.jmx.MBeanServerImpl.setAttribute(MBeanServerImpl.java:1331)
at weblogic.management.internal.ConfigurationMBeanImpl.updateConfigMBeans(ConfigurationMBeanImpl.java:318)
at weblogic.management.internal.ConfigurationMBeanImpl.setAttribute(ConfigurationMBeanImpl.java:259)
at com.sun.management.jmx.MBeanServerImpl.setAttribute(MBeanServerImpl.java:1356)
at com.sun.management.jmx.MBeanServerImpl.setAttribute(MBeanServerImpl.java:1331)
at weblogic.management.internal.MBeanProxy.setAttribute(MBeanProxy.java:291)
at weblogic.management.internal.MBeanProxy.invoke(MBeanProxy.java:173)
at $Proxy7.setDeployed(Unknown Source)
at weblogic.management.console.pages._panels._mbean._application._jspService(_application.java:303)
at weblogic.servlet.jsp.JspBase.service(JspBase.java:27)
at weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubImpl.java:213)
at weblogic.servlet.internal.WebAppServletContext.invokeServlet(WebAppServletContext.java:1265)
at weblogic.servlet.internal.ServletRequestImpl.execute(ServletRequestImpl.java:1622)
at weblogic.kernel.ExecuteThread.execute(ExecuteThread.java:137)
at weblogic.kernel.ExecuteThread.run(ExecuteThread.java:120)
But if I put the infobus.jar on system classpath , everything works out fine.
Can somebody tell me, what is going onGseel is right: you try to instantiate an EJB with the BDK.
Enterprise Java Beans are totally different from graphical/GUI beans. EJBs are thought for dealing with business logic like accessing a database, ldap directory and so on. They run on a application server (simply speaking - a java enabled webserver) and do some processing to handle user requests. Enterprise Java Beans usually don't interact directly with the user, they only do the work in the background and forward their results, which are then rendered for the user. Typically they are employed for handling web requests (a user with a browser), but they can also be used for awt/swing applications. Though - let me repeat - they don't appear visually on the screen.
The only similarities between those two bean types are the following: they have getter/setter methods for their properties, they implement Serializeable (or a sub-interface like Externalizable, Remote) and they have a default no-argument constructor.
If you want to run your been you need an application server (your bean is pre-packaged for the Bea Weblogic app-server). If you want to do something graphical, you'll need to search for GUI beans.
dani3l -
Firefox won't load check images from my online bank.
Firefox won't load check images from my online bank. It had been doing so with no problems, but stopped 2 days ago. I can get into my account and navigate with no problems. But when I click to see the image of a check, I get a blank page.
I am using Firefox 3.6, but I have the same problem on my laptop with Firefox 4
It works fine with Safari and Internet Explorer.If you can't open them in Firefox anymore (you seem to have a plugin: View PDF documents within your web browser) then download the documents to the desktop and open them with a program that can open PDF files.
See also to be sure that that plugin is still selected:
* https://support.mozilla.com/kb/Managing+file+types
Do you otherwise have problems with PDF files? -
Error While loading a image from database
Purpose
Error While loading the Image from the database
ORA-06502: PL/SQL : numeric or value error:Character string buffer too small
ORA-06512: at "Sys.HTP" ,line 1480
Requirement:
I am developing the web pages using PSP(Pl/sql Serverpages) . I have a requirement to show a image in the webpage. I got the following procedures from the oracle website.
I have created the following table to store the images
create table DEMO
ID INTEGER not null,
THEBLOB BLOB
And I also uploaded the Images. Now I am try to get a image from the table using the following procedure .But I am getting the error message line 25( htp.prn( utl_raw.cast_to_varchar2( l_raw ) );) .at it throws the following error messages
ORA-06502: PL/SQL : numeric or value error:Character string buffer too small
ORA-06512: at "Sys.HTP" ,line 1480
Procedure that I used to get the image
create or replace package body image_get
as
procedure gif( p_id in demo.id%type )
is
l_lob blob;
l_amt number default 30;
l_off number default 1;
l_raw raw(4096);
begin
select theBlob into l_lob
from demo
where id = p_id;
-- make sure to change this for your type!
owa_util.mime_header( 'image/gif' );
begin
loop
dbms_lob.read( l_lob, l_amt, l_off, l_raw );
-- it is vital to use htp.PRN to avoid
-- spurious line feeds getting added to your
-- document
htp.prn( utl_raw.cast_to_varchar2( l_raw ) );
l_off := l_off+l_amt;
l_amt := 4096;
end loop;
exception
when no_data_found then
NULL;
end;
end;
end;
What I have to do to correct this problem. This demo procedure and table that I am downloaded from oracle. Some where I made a mistake. any help??
Thanks,
NatsHi Satish,
I have set the raw value as 3600 but still its gives the same error only. When I debug the procedure its throwing the error stack in
SYS.htp.prn procedure of the following line of code
if (rows_in < pack_after) then
while ((len - loc) >= HTBUF_LEN)
loop
rows_in := rows_in + 1;
htbuf(rows_in) := substr(cbuf, loc + 1, HTBUF_LEN);
loc := loc + HTBUF_LEN;
end loop;
if (loc < len)
then
rows_in := rows_in + 1;
htbuf(rows_in) := substr(cbuf, loc + 1);
end if;
return;
end if;
Its a system procedure. I don't no how to proceed .. I am really stucked on this....is their any other method to take picture from the database and displayed in the web page.....???? any idea..../suggesstion??
Thanks for your help!!!. -
How can I best load RAW images from a Canon SX50?
How can I best load RAW images from a Canon SX50?
9Sorry, ........confused about this process. When I attempted to Post the question I had entered, I was told a blank space could not be posted. So, I reentered the Q in the "space"........ which apparently was the space for an answer....!! ??......)
> When I try to load RAW images taken by my Canon SX50 from the SD card, iPhoto 11 - (iMac/OSX 10.6.8) tells me that it can't read the format or something like that. OSX 10.6.8 came out before the SX50, thus, did not include the related program. I want to shoot RAW on the SX50....... but I then want to load them into iPhoto....... which I do directly from pics I take with my Nikon D200.
Not sure if this will help............. -
Is there a way to have the iPad 2 "read" text from iBooks as with web sites or pages?
is there a way to have the iPad 2 "read" text from iBooks as with web sites or pages? A different App perhaps?
Isn't that you asking how to get it (undefined) back?
If you never had Pages '09, you can buy it from Amazon very cheaply:
http://www.freeforum101.com/iworktipsntrick/viewtopic.php?t=432&sid=f68e84cd2ec6 123bd2ed93806c7e7fb6&mforum=iworktipsntrick
Peter -
JAVA, sqlserver - Need to load an image from the sql server database
hi,
I need to load an image from the sql server database using java. I have connected to the database and getting all other records except the records for a photo (datatype = LONGVARBINARY) and Remarks (datatype = LONGVARCHAR).
I am using java and sql server db. The photo and remarks are stored in the db. and i need to show the image and the remarks fetching them from there.
I get the error :
Thread-9 org.hibernate.MappingException: No Dialect mapping for JDBC type: -1
How can I achieve this?
Thanks,
GargiExactly. And are you using MySQL?
No. You are using Microsoft SQL server if I have to believe your initial post. A quick google tells me that the dialect class to use is:
org.hibernate.dialect.SQLServerDialect -
Load multiple images from directory?
What is the best way to use CF to load multiple images from a
server directory please? I have CF calling a stored procedure that
returns an array of file names. I am using a Flex front end, and
wonder if I should just pass the file name array to Flex and let it
loop through and load each image into an array. Or is it possible
from within my CFC to use the file name array to get CF to grab the
images and then pass that image array back to Flex? If so, is there
any advantage to either approach? TIA,
Mic.You don't want to pass the binaries to Flex, you should just
give Flex the image names and load them via HTTP. -
How to read some images from file system with webdynpro for abap?
Hi,experts,
I want to finish webdynpro for abap program to read some photos from file system. I may make MIMES in the webdynpro component and create photos in the MIMES, but my boss doesn't agree with me using this way. He wish me read these photos from file system.
How to read some images from file system with webdynpro for abap?
Thanks a lot!Hello Tao,
The parameter
icm/HTTP/file_access_<xx>
may help you to access the pictures without any db-access.
The following two links may help you to understand the other possibilities as well.
The threads are covering BSP, but it should be useful for WebDynpro as well.
/people/mark.finnern/blog/2003/09/23/bsp-programming-handling-of-non-html-documents
http://help.sap.com/saphelp_sm40/helpdata/de/c4/87153a1a5b4c2de10000000a114084/content.htm
Best regards
Christian -
I can't down load my images from my Nikon D4 to Apeture.
I can't down load my images from my Nikon D4 to Apeture.
Hi skhart1998,
I also use Nikon D4, D2H and D2Xs
I use Nikon Transfert 2, the latest version, to download my shots to my MacBook Pro hard disk in a picture folder. After this I use Aperture Import to place the New folder created in the Nikon folder in the Aperture Inspector folder... This way, I always have the copy of my originals files.
.jpg or .nef work fine.
Denis -
Loading realscale image from memorycard.
Hi.
I made a big image (3550 x 2100 pixels), which my Nokia 6125 didn't zoom enough on the normal Picture preview.
So I decided to make a program for it, so I could see all the details from the pic, and move around on the image. (Like zoom, but I need to get closer.. )
First problem i encountered, was that 4mb application was too big to install on my memorycard... Darn limits...
So I decided to add them seperately, that I'd load the image from the application.
Well when I ran the "File Browser", there was 3 things:
- ".." (Folder up)
- "E:\" (crashes, no access)
- "C:\" (crashes, no access)
So any ideas how could I get it work properly?
Thanks!hmm ... ok .. that sounds good .. but that means that
a servlet must exsist at all time to display the
required image.Servlets are usually instantiated by the servlet container upon an incoming request. -
Loading an image from an arbitrary URL without using an ImageIcon
Can anybody maybe point me in the direction of other (as in harder-to-use, but more flexible) ways to load an image from a URL?
Interesting results:
When I run this test code (the names have been changed to protect the innocent):
package graphicstest;
import javax.swing.*;
import java.net.*;
import javax.imageio.*;
import java.awt.image.*;
* <p>Title: </p>
* <p>Description: </p>
* <p>Copyright: Copyright (c) 2007</p>
* <p>Company: </p>
* @author not attributable
* @version 1.0
public class Foo
extends JFrame {
static ImageIcon ii;
public Foo() {
setSize(200,200);
try {
System.out.println("2=aborted; 8=complete; 4=errored; 1=loading");
ii = new ImageIcon(new URL("http://intranet/part?FOO.JPG"));
System.out.println("image load status: " + ii.getImageLoadStatus());
getContentPane().add(new JLabel(ii));
System.out.println("image load status: " + ii.getImageLoadStatus());
}catch(Throwable t) {t.printStackTrace();}
public static void main(String args[]) {
Foo foo = new Foo();
foo.setVisible(true);
if (ii.getImageLoadStatus() == 4) {
try {
BufferedImage bi = ImageIO.read(new URL(
"http://intranet/part?FOO.JPG"));
ii.setImage(bi);
foo.validate();
foo.repaint();
} catch(Throwable t) {t.printStackTrace();};
}. . . from a box that's not on the VPN, it blows up at the ImageIO.read() call (not unexpectedly). But if I run it from a box that's on the VPN, and able to access the URL, then it returns just fine from the ImageIO.read(), and I get a null pointer exception at the call to setImage().
Clearly, this is trying to tell me SOMETHING, but I don't quite know WHAT.
JHHL
Maybe you are looking for
-
SAP PI problem: User credentials are invalid or user is denied access
Hi! I am about to configure SAP PI. Therefore I have run post installation wizard step PI_00 and get the following errors: Error: Not able to load Function SWF_XI_BPM_AUTO_CUSTOMIZE (cause:Name or password is incorrect (repeat logon)). Step: Execute
-
I create HTML5 help projects from a package called MadCap Flare. It uses what they call an HTML5 'skin' that sets the style/layout of the page and also includes 'Navigate previous' and 'Navigate next' buttons. When viewing the help and pressing these
-
Exception while updating a clob value using dbms_lob.fragment_insert
Hi, Here is the query procedure tempProc(str3 in varchar2) is QI CLOB; -- LOB(QI) STORE AS securefile ; v_cursor refcursor; str varchar2(50); i number default '30'; begin open v_cursor for select b.OCEAN_RATE_XML.getClobVal() from TNMAB_OCEAN_RATE_XM
-
User not displayed under a Group
HI All, We are using BOXIR2 SP2 with .NET and have configured Windows AD authentication. A user belongs to multiple groups. Some times a user may belong to 14- 20 groups. All these groups are added in CMC. The issue is when I do a manual update of th
-
Hyperlinks in email sig on 9300
Hi, is there a way to include hyperlinks (I mean, have say "LinkedIn" visable but when clicked goes to www.linkedin.com) in email signature? Also in the body of the mail when needed. Thanks in advance.