gpt4 book ai didi

java - batik-rasterizer.jar的调用方法

转载 作者:行者123 更新时间:2023-11-29 05:53:19 29 4
gpt4 key购买 nike

使用 batik 1.7 版本的 batik-rasterizer.jar,我想知道如何正确调用 jar。

java -jar batik-rasterizer-1.7.jar -m image/png -q 0.8 $1

这给了我:

Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/batik/i18n/LocalizableSupport

因此,我一直在寻找要使用的正确的 MainClassClassPath。我会在一分钟内发布我想出的脚本作为答案......

最佳答案

这将是 maven 重新打包方法:

  1. 根据下面的pom.xml创建一个maven项目
  2. 添加 Java 类 Rasterizer
  3. 添加 JUnit 测试 TestRasterizer
  4. 添加示例文件 readandblue.svg
  5. 运行 mvn 安装

你应该得到一个“阴影”jar 文件 target/com.bitplan.rasterizer-0.0.1.jar已经包含了 java.awt.headless 调用:

您也可以使用 pom.xml“独立”并简单地更改其中的主类。

Rasterize.java 包装类

package com.bitplan.rasterizer;

import org.apache.batik.apps.rasterizer.Main;

/**
* Rasterizer main class
* https://stackoverflow.com/questions/13112967/how-to-call-batik-rasterizer-jar
* @author wf
*
*/
public class Rasterizer {
/**
* wrapper entry point for batik rasterizer
* @param args
*/
public static void main(String[] args) {
System.setProperty("java.awt.headless", "true");
// see
// http://www.docjar.org/html/api/org/apache/batik/apps/rasterizer/Main.java.html
Main main=new Main(args);
main.execute();
}
}

TestRasterizer.java JUnit 测试用例

package com.bitplan.rasterizer;

import static org.junit.Assert.*;

import java.io.File;

import org.junit.Test;

/**
* test the rasterizer
* @author wf
*
*/
public class TestRasterizer {

@Test
public void testRasterizer() {
File testFile=new File("src/test/data/redandblue.svg");
File pngFile=new File("src/test/data/redandblue.png");
if (pngFile.exists())
pngFile.delete();
assertTrue(testFile.exists());
String [] args={"-scriptSecurityOff","-m","image/png","-q","0.8",testFile.getPath()};
com.bitplan.rasterizer.Rasterizer.main(args);
assertTrue(pngFile.exists());
}

}

示例 svg 文件:readandblue.svg

<svg xmlns="http://www.w3.org/2000/svg"
width="467" height="462">
<rect x="80" y="60" width="250" height="250" rx="20"
style="fill:#ff0000; stroke:#000000;stroke-width:2px;" />

<rect x="140" y="120" width="250" height="250" rx="40"
style="fill:#0000ff; stroke:#000000; stroke-width:2px;
fill-opacity:0.7;" />
</svg>

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.bitplan.java</groupId>
<version>0.0.1</version>
<artifactId>com.bitplan.rasterizer</artifactId>
<name>com.bitplan.rasterizer</name>
<description>Provide rasterizer access</description>
<properties>
<junit3.version>3.8.1</junit3.version>
<junit4.version>4.11</junit4.version>
</properties>
<dependencies>
<!-- batik rasterizer -->
<dependency>
<groupId>org.apache.xmlgraphics</groupId>
<artifactId>batik-rasterizer</artifactId>
<version>1.7</version>
</dependency>
<!-- https://issues.apache.org/bugzilla/show_bug.cgi?id=44682 -->
<dependency>
<groupId>org.apache.xmlgraphics</groupId>
<artifactId>batik-codec</artifactId>
<version>1.7</version>
</dependency>
<!-- Runtime Junit access -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>${junit4.version}</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>2.3</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<transformers>
<transformer
implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer" />
<transformer
implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<!-- <mainClass>org.apache.batik.apps.rasterizer.Main</mainClass> -->
<mainClass>com.bitplan.rasterizer.Rasterizer</mainClass> -->
</transformer>
</transformers>
<filters>
<filter>
<artifact>*:*</artifact>
<excludes>
<exclude>META-INF/*.SF</exclude>
<exclude>META-INF/*.DSA</exclude>
<exclude>META-INF/*.RSA</exclude>
</excludes>
</filter>
</filters>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>

关于java - batik-rasterizer.jar的调用方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13112967/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com