PrimeFaces Barcode Not Working?

I'm trying to run a barcode from PrimeFaces Showcase , but when I put the XHTML code in and let it work in my local Wildfly 8, I just get full of garbage. Each barcode numbers are too big and the QR code doesn't work at all.

I believe I may have a missing Maven dependency, but I am having a hard time finding the right one.

Following the documentation, I think I need to integrate a dependency for barcode4j-light

in version 2.1

, but I cannot find this version on Maven.

How do I integrate this? I would appreciate any help! Thanks in advance!

My Barcode.xhtml:

<!DOCTYPE html>
<html   xmlns="http://www.w3c.org/1999/xhtml"
        xmlns:h="http://java.sun.com/jsf/html"
        xmlns:p="http://primefaces.org/ui"
        xmlns:f="http://xmlns.jcp.org/jsf/core">
    <h:head/>
    <h:body>
        <p:panelGrid columns="2">
            <h:outputText value="Interleaved 2 of 5" />
            <p:barcode value="0123456789" type="int2of5" />

            <h:outputText value="Codabar" />
            <p:barcode value="0123456789" type="codabar"/>

            <h:outputText value="Code39" />
            <p:barcode value="0123456789" type="code39" />

            <h:outputText value="Code128" />
            <p:barcode value="0123456789" type="code128"/>

            <h:outputText value="EAN-8" />
            <p:barcode value="20123451" type="ean8"/>

            <h:outputText value="EAN-13" />
            <p:barcode value="0123456789012" type="ean13"/>

            <h:outputText value="UPC-A (PNG)" />
            <p:barcode value="01234567895" type="upca" format="png"/>

            <h:outputText value="UPC-E (Vertical)" />
            <p:barcode value="01234133" type="upce" orientation="90"/>

            <h:outputText value="PDF417" />
            <p:barcode value="0123456789" type="pdf417"/>

            <h:outputText value="DataMatrix" />
            <p:barcode value="0123456789" type="datamatrix"/>

            <h:outputText value="Postnet" />
            <p:barcode value="0123456789" type="postnet"/>

            <h:outputText value="QR" />
            <p:barcode value="0123456789" type="qr"/>
        </p:panelGrid>
    </h:body>
</html>

      

My pom.xml:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.glasses</groupId>
    <artifactId>primeWork</artifactId>
    <version>1.0</version>
    <packaging>war</packaging>

    <name>primeWork</name>

    <properties>
        <endorsed.dir>${project.build.directory}/endorsed</endorsed.dir>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>

    <dependencies>
        <dependency>
            <groupId>javax</groupId>
            <artifactId>javaee-web-api</artifactId>
            <version>7.0</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>org.primefaces</groupId>
            <artifactId>primefaces</artifactId>
            <version>5.1</version>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.1</version>
                <configuration>
                    <source>1.7</source>
                    <target>1.7</target>
                    <compilerArguments>
                        <endorseddirs>${endorsed.dir}</endorseddirs>
                    </compilerArguments>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-war-plugin</artifactId>
                <version>2.3</version>
                <configuration>
                    <failOnMissingWebXml>false</failOnMissingWebXml>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-dependency-plugin</artifactId>
                <version>2.6</version>
                <executions>
                    <execution>
                        <phase>validate</phase>
                        <goals>
                            <goal>copy</goal>
                        </goals>
                        <configuration>
                            <outputDirectory>${endorsed.dir}</outputDirectory>
                            <silent>true</silent>
                            <artifactItems>
                                <artifactItem>
                                    <groupId>javax</groupId>
                                    <artifactId>javaee-endorsed-api</artifactId>
                                    <version>7.0</version>
                                    <type>jar</type>
                                </artifactItem>
                            </artifactItems>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

</project>

      

+3


source to share


2 answers


So, barcode4j-light-2.1

not available in the Maven repository. We need to download it from SourceForge . Download it and unzip it, go to the directory build

. The letter barcode4j-light

will be there.

To install it on your local Maven repository, follow these instructions . Basically, from the command line (from a directory build

and assuming you have Maven installed):

C:\...build>mvn install:install-file -Dfile=barcode4j-light.jar 
                                     -DgroupId=net.sf.barcode4j
                                     -DartifactId=barcode4j-light 
                                     -Dversion=2.1 
                                     -Dpackaging=jar

      

This command should be on one line, not on a line as you can see here. Then you can just add the dependency to your project



<dependency>
    <groupId>net.sf.barcode4j</groupId>
    <artifactId>barcode4j-light</artifactId>
    <version>2.1</version>
</dependency>

      

You will also need this

<dependency>
    <groupId>net.glxn</groupId>
    <artifactId>qrgen</artifactId>  <!-- QR code support -->
    <version>1.4</version>
</dependency>

      

Not step by step like this, but it is described in the Prime Faces User Guide . This worked for me once I followed the steps below.

+4


source


I also added to my pom.xml:

<repositories>
    <repository>
        <url>http://repository.primefaces.org/</url>
        <id>PrimeFaces-maven-lib</id>
        <layout>default</layout>
        <name>Repository for library PrimeFaces-maven-lib</name>
    </repository>
</repositories>

      



Who is solving the dependency issue in NB8 Maven web projects.

+1


source







All Articles