Barcode issue on linux server

UI Components for JSF
Post Reply
rafaelcaranga
Posts: 3
Joined: 14 Jan 2013, 22:15

12 Jun 2013, 06:08

Hi, I have tested the dynamicbarcode example from showcase, and it works pretty well on my IDE enviroiment. But when I Export my war file and deploy it in my production server, the barcode doesn't appear.

Look this code:

Code: Select all

        	
File barcodeFile = new File("dynamicbarcode");
if (!barcodeFile.exists()){
      barcodeFile.createNewFile(); //enter here when running on production enviroiment
}
BarcodeImageHandler.saveJPEG(BarcodeFactory.createCode128(adesao.getChaveAcesso()), barcodeFile);
barcode = new DefaultStreamedContent(new FileInputStream(barcodeFile), "image/jpeg");
when running in production, i cant instantiate the File, getting a blank image on the screen.

How can I solve this issue? maybe permission? or some setting is missing?


My Development enviroiment: Eclipse + Tomcat 6 running under Windows Plataform
Production Enviroiment: Tomcat 6 running under Ubuntu 12.04

Primefaces v.3.4.1
JSF 2.0

User avatar
andyba
Expert Member
Posts: 2473
Joined: 31 Mar 2011, 16:27
Location: Steinfeld, near Bremen/Osnabrück, DE
Contact:

12 Jun 2013, 13:42

This could be caused by several issues

- missing or incompatible libraries on your production server
- tomcat not running headless on your production server
- file permissions

Have you checked the production server log files?
Have you debugged on the production server?
Have you tried a different UBUNTU server?
Have you checked the value returned by barcodeFile.createNewFile()?

The issue is most likely down to permissions. You also don't want to simply create a new file at whatever file root happens to be the default for the current user under which the server runs. You should always be explicit about where you want to create new files.
PF 4.x (Elite versions), PF 5, Pf 5.1, PF 6.0
Glassfish 4.1, Mojarra 2.x, Java 8, Payara 4.1.1.
If you haven't read the forum rules read them now

rafaelcaranga
Posts: 3
Joined: 14 Jan 2013, 22:15

12 Jun 2013, 15:03

I understand that i Have to instance this specific file named "dynamicbarcode".

This verification if file not exists, then create new File, I have added because the SaveJpeg method was throwing a NullPointerException because the file was null. Remember, in dev. enviroiment

When I call saveJpeg method, passing a blank new file as a parameter, the return is a blank image.

Then... I think that i'll solve my problem, locating this file named dynamicbarcode and grant permission for tomcat user.

Where can I find this file named "dynamicbarcode"?

User avatar
andyba
Expert Member
Posts: 2473
Joined: 31 Mar 2011, 16:27
Location: Steinfeld, near Bremen/Osnabrück, DE
Contact:

14 Jun 2013, 18:49

rafaelcaranga wrote:I understand that i Have to instance this specific file named "dynamicbarcode".

This verification if file not exists, then create new File, I have added because the SaveJpeg method was throwing a NullPointerException because the file was null. Remember, in dev. enviroiment

When I call saveJpeg method, passing a blank new file as a parameter, the return is a blank image.

Then... I think that i'll solve my problem, locating this file named dynamicbarcode and grant permission for tomcat user.

Where can I find this file named "dynamicbarcode"?
You should always create files with absolute paths, usually under the context path of the application (search for ServletContext.getRealPath on how to do this).
If you use absolute paths then you always know where the file will be before you create it.
One other thing, using the same filename all the time is not going to work for multiple users for obvious reasons.
PF 4.x (Elite versions), PF 5, Pf 5.1, PF 6.0
Glassfish 4.1, Mojarra 2.x, Java 8, Payara 4.1.1.
If you haven't read the forum rules read them now

rafaelcaranga
Posts: 3
Joined: 14 Jan 2013, 22:15

18 Jun 2013, 14:36

Ok brothers, problem solved.

to solve it, was necessary to use the absolute path to know exactly where the file would be created. Like Andyba says.

In my case, I used double slashs in path to get to the spot. using single slashes, always was thrown IOException.

Code: Select all


File barcodeFile = new File("//tmp//"+filename);

the tmp directory in my distro (ubuntu) is all permitted by default.

putting the cherry on cake's top, the filename is a dynamic String, so in multiple users, doesn't got any conflict.

hacksewe
Posts: 1
Joined: 12 Aug 2013, 04:38

12 Aug 2013, 04:48

Guys. Recently I copied a sample code to create barcode. But it did not work. I did not find the reason why this happened. Any ideas? Here is the sample code:
// Build Java Code39 barcode object
Code39 barcode = new Code39();

// Encode Code39 data
barcode.setData("CODE39-IN-JAVA");

// Generate Code39 barcode & print into Graphics2D object
barcode.drawBarcode("Java Graphics2D object");

// Generate Code39 barcode & encode into GIF format
barcode.drawBarcode("C://barcode-code39.gif");

// Generate Code39 barcode & render into JPEG format
barcode.drawBarcode("C://barcode-code39.jpg");

// Draw Code39 barcode & paint into EPS image format
barcode.drawBarcode2EPS("C://barcode-Code39.eps");
I have read the creation guide. I still can't figure it out.

cindy313
Posts: 6
Joined: 05 Sep 2013, 09:59

17 Mar 2014, 05:04

hacksewe wrote:Guys. Recently I copied a sample code to create barcode. But it did not work. I did not find the reason why this happened. Any ideas? Here is the sample code:
// Build Java Code39 barcode object
Code39 barcode = new Code39();

// Encode Code39 data
barcode.setData("CODE39-IN-JAVA");

// Generate Code39 barcode & print into Graphics2D object
barcode.drawBarcode("Java Graphics2D object");

// Generate Code39 barcode & encode into GIF format
barcode.drawBarcode("C://barcode-code39.gif");

// Generate Code39 barcode & render into JPEG format
barcode.drawBarcode("C://barcode-code39.jpg");

// Draw Code39 barcode & paint into EPS image format
barcode.drawBarcode2EPS("C://barcode-Code39.eps");
I have read the creation guide. I still can't figure it out.
you just copy the code ? maybe they are not compatible

User avatar
andyba
Expert Member
Posts: 2473
Joined: 31 Mar 2011, 16:27
Location: Steinfeld, near Bremen/Osnabrück, DE
Contact:

17 Mar 2014, 17:15

There is a rash of Thread resurrection going on lately. This is against the Forum rules. Please read them if you haven't already and read them again if you have.
As far as this sort of things is concerned make sure you are adding meaningful content in a meaningful place, ie not in a Thread that has been inactive for months/years.
PF 4.x (Elite versions), PF 5, Pf 5.1, PF 6.0
Glassfish 4.1, Mojarra 2.x, Java 8, Payara 4.1.1.
If you haven't read the forum rules read them now

Ktueethall
Posts: 1
Joined: 16 Jun 2014, 04:07

16 Jun 2014, 04:18

The code 39 barcode generator you recommended is what I need actually, I have been searching for a java barcode creator for a long time that should be easy to use and simple to integareted to create both 1d and 2d barcodes freely, and of course, the 2d qr code barcode should be supportable.

jackmay
Posts: 2
Joined: 26 Nov 2014, 06:57

27 Nov 2014, 09:30

Ktueethall wrote:The code 39 barcode generator you recommended is what I need actually, I have been searching for a java barcode creator for a long time that should be easy to use and simple to integareted to create both 1d and 2d barcodes freely, and of course, the 2d qr code barcode should be supportable.
I have used this barcode generator,it worked perfectly!

Post Reply

Return to “PrimeFaces”

  • Information
  • Who is online

    Users browsing this forum: Baidu [Spider] and 27 guests