mvn install:install-file -Dfile=jbarcode-0.2.7.jar -DgroupId=org.jbarcode -DartifactId=jbarcode -Dversion=0.2.7 -Dpackaging=jar
说明:-DgroupId和-DartifactId的作用是指定了这个jar包在repository的安装路径,只是用来告诉项目去这个路径下寻找这个名称的jar包。
mvn install:install-file -Dfile=jbarcode-0.2.7.jar -DgroupId=org.jbarcode -DartifactId=jbarcode -Dversion=0.2.7 -Dpackaging=jar
就是指把jbarcode-0.2.7.jar安装到—目录下,执行完命令后,如果需要在项目中使用这个jar,则在pom.xml中添加如下配置即可:
<dependency>
<groupId>org.jbarcode</groupId>
<artifactId>jbarcode</artifactId>
<version>0.2.7</version>
</dependency>
import java.awt.image.BufferedImage;
import java.io.FileOutputStream;
import org.jbarcode.JBarcode;
import org.jbarcode.encode.EAN8Encoder;
import org.jbarcode.paint.EAN8TextPainter;
import org.jbarcode.paint.WidthCodedPainter;
import org.jbarcode.util.ImageUtil;
/**
* 2022-11-01
* @author wb
* 支持EAN13,EAN8,UPCA,UPCE,Code 3 of 9,Codabar,Code 11,Code 93,Code 128,MSI/Plessey,Interleaved 2 of PostNet等
*/
public class OneBarcodeUtil {
public static void main(String[] paramArrayOfString) {
try {
//这里以EAN8为例
JBarcode localJBarcode = new JBarcode(EAN8Encoder.getInstance(),WidthCodedPainter.getInstance(),EAN8TextPainter.getInstance());
String str = "2219644";
BufferedImage localBufferedImage = localJBarcode.createBarcode(str);
saveToJPEG(localBufferedImage,"EAN8.jpeg");
}
catch (Exception localException) {
localException.printStackTrace();
}
}
static void saveToJPEG(BufferedImage paramBufferedImage,String paramString) {
saveToFile(paramBufferedImage,paramString,"jpeg");
}
static void saveToFile(BufferedImage paramBufferedImage,String paramString1,String paramString2) {
try {
FileOutputStream localFileOutputStream = new FileOutputStream("C:\\Users\\wb227\\Desktop\\test" + paramString1);
ImageUtil.encodeAndWrite(paramBufferedImage,paramString2,localFileOutputStream,96,96);
localFileOutputStream.close();
}
catch (Exception localException) {
localException.printStackTrace();
}
}
}