Maven 依赖项在 primefaces 中不起作用?

Maven depedency not working in primefaces?

我想在 primefcaes.For 中显示条形码,我创建了一个基于 Maven 的项目并为这些库添加了两个依赖项,例如

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

我在 primefaces 文档中读到 barcode4j-2.1 在 maven 中可能不可用,所以我需要 manual install the jar in maven repo

我已经在 eclipse 中使用此命令将 jar 安装到 maven repo

install:install-file -Dfile=D:\qrgen-1.4.jar -DgroupId=net.glxn -DartifactId=qrgen -Dversion=1.4 -Dpackaging=jar

 install:install-file -Dfile=D:\barcode4j-light-2.1.jar -DgroupId=net.sf.barcode4j -DartifactId=barcode4j-light -Dversion=2.1 -Dpackaging=jar

POM.XML

<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.prime</groupId>
    <artifactId>primedemop</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>primefaces</name>
    <dependencies>
        <dependency>
            <groupId>com.sun.faces</groupId>
            <artifactId>jsf-api</artifactId>
            <version>2.2.2</version>
        </dependency>
        <dependency>
            <groupId>com.sun.faces</groupId>
            <artifactId>jsf-impl</artifactId>
            <version>2.2.2</version>
        </dependency>
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>javax.servlet-api</artifactId>
            <version>3.0.1</version>
        </dependency>
        <dependency>
            <groupId>org.primefaces</groupId>
            <artifactId>primefaces</artifactId>
            <version>5.1</version>
        </dependency>
        <dependency>
            <groupId>net.glxn</groupId>
            <artifactId>qrgen</artifactId>
            <version>1.4</version>
        </dependency>
        <dependency>
            <groupId>net.sf.barcode4j</groupId>
            <artifactId>barcode4j-light</artifactId>
            <version>2.1</version>
        </dependency>
    </dependencies>
</project>

但是,如果我在 lib 文件夹中添加 barcode4j-light-2.1 jar 文件,那么我无法生成任何条形码,那么我能够生成条形码,但不能生成QR码,但现在我连条形码都不能生成。

当我将 jar 文件安装到 maven 存储库时,我在 eclipse 控制台上得到以下输出。

对于 qrgen jar

对于 barcode4j

查看 groupId 和 artifactId 以了解您的依赖项和您安装的内容:

qrgen:       -DgroupId=net.glxn.qrgen -DartifactId=qrgen
qrgen-light: -DgroupId=net.glxn.qrgen -DartifactId=qrgen

您的依赖项显示不同 group/artifactId:

<dependency>
    <groupId>net.glxn</groupId>                 <--- here
    <artifactId>qrgen</artifactId>              <--- here
    <version>1.4</version>
</dependency>
<dependency>
    <groupId>net.sf.barcode4j</groupId>         <--- here
    <artifactId>barcode4j-light</artifactId>    <--- here
    <version>2.1</version>
</dependency>

您手动将 jars 安装到 Maven 存储库中名为 net/glxn/qrgen/qrgen 的目录中,但您的依赖项期望分别在 net/glxn/qrgennet/sf/barcode4j/barcode4j-light 中找到它们。

您需要将手动安装命令更新为:

install:install-file -Dfile=D:\qrgen-1.4.jar -DgroupId=net.glxn -DartifactId=qrgen -Dversion=1.4 -Dpackaging=jar

install:install-file -Dfile=D:\barcode4j-light-2.1.jar -DgroupId=net.sf.barcode4j -DartifactId=barcode4j-light -Dversion=1.4 -Dpackaging=jar