JetBrains / lets-plot-kotlin

Grammar of Graphics for Kotlin
https://lets-plot.org/kotlin/
MIT License
419 stars 36 forks source link

Getting errors while exporting image outside of Intellij IDEA #199

Closed vkupar closed 11 months ago

vkupar commented 11 months ago

Hi,

Exporting as png file works perfectly while running from Intellij IDEA.

I'm getting these errors when I run the code locally in terminal or in CI environment: An exception occurred while executing the Java class. Provider org.apache.xerces.jaxp.SAXParserFactoryImpl not found ... javax.xml.parsers.FactoryConfigurationError: Provider org.apache.xerces.jaxp.SAXParserFactoryImpl not found ... Can't export plot to raster formats: NoClassDefFoundError "Could not initialize class org.apache.batik.anim.dom.SAXSVGDocumentFactory". Please add "lets-plot-image-export-<version>.jar" to your classpath.

pom.xml:

<dependency>
  <groupId>org.jetbrains.lets-plot</groupId>
  <artifactId>lets-plot-kotlin-jvm</artifactId>
  <version>4.3.0</version>
  <scope>test</scope>
</dependency>

<dependency>
  <groupId>org.jetbrains.lets-plot</groupId>
  <artifactId>lets-plot-image-export</artifactId>
  <version>3.1.0</version>
  <scope>test</scope>
</dependency>

Code:

import org.jetbrains.letsPlot.export.ggsave
import org.jetbrains.letsPlot.geom.geomPoint
import org.jetbrains.letsPlot.letsPlot

fun main() {
  val xs = listOf(0,  0.5, 1, 2)
  val ys = listOf(0, 0.25, 1, 4)
  val data = mapOf<String, Any>("x" to xs, "y" to ys)

  val fig = letsPlot(data) + geomPoint(
    color = "dark-green",
    size = 4.0
  ) { x = "x"; y = "y" }

  ggsave(fig, "plot.png")
}

Command:

mvn clean dependency:go-offline test-compile exec:java -Dexec.classpathScope="test" -Dexec.mainClass="abc.TestFileKt"

Java version locally:

openjdk 17.0.8 2023-07-18
OpenJDK Runtime Environment Homebrew (build 17.0.8+0)
OpenJDK 64-Bit Server VM Homebrew (build 17.0.8+0, mixed mode, sharing)
alshan commented 11 months ago

Duplicated by https://github.com/JetBrains/lets-plot/issues/842