apache poi - how to get resource in a jar file ? (poi && image) -
i using poi apache generate excel file, have add picture file problems when export project runnable jar, not working.
inputstream = exceltools.class.getclassloader().getresourceasstream( "./ensao/pfa/opendelib/resources/logoopen.jpg" ); byte[] bytes = ioutils.tobytearray(is); int pictureidx = wb.addpicture(bytes, workbook.picture_type_jpeg); is.close(); drawing drawing = sheet.createdrawingpatriarch(); hssfclientanchor anchor = new hssfclientanchor(40, 10, 65, 20, (short) 0, 0, (short) 0, 0); anchor.setanchortype(1); picture pict = drawing.createpicture(anchor, pictureidx); pict.resize();
the problem launched line :
byte[] bytes = ioutils.tobytearray(is);
problem in bad path image. ide configured environment ($classpath, file path, etc) in 1 manner, real running operate other environment. find working directory print debug pwd analog.
this links may useful: http://www.java-forums.org/new-java/434-how-can-i-get-current-directory.html http://www.mkyong.com/java/how-to-get-the-current-working-directory-in-java/ getting current working directory in java
Comments
Post a Comment