Reputation: 1532
I have a conflict using two packages in my java project - apache fop and lesscss. I figured out the reason of the error - less compiler uses
context.setLanguageVersion(Context.VERSION_1_7);
in it's constructor, where context is an object of class org.mozilla.javascript.Context (rhino package). But apache fop has patched version of this object (http://mvnrepository.com/artifact/org.apache.xmlgraphics/batik-js/1.7), which doesn't support 1.7 language version. So here is extremely simplified set of files, which can demonstrate my issue. All you need is
1) pom.xml with the following content:
<?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>test</groupId>
<artifactId>test</artifactId>
<packaging>war</packaging>
<version>0.1</version>
<dependencies>
<dependency>
<groupId>org.mozilla</groupId>
<artifactId>rhino</artifactId>
<version>1.7R4</version>
</dependency>
<dependency>
<groupId>org.apache.xmlgraphics</groupId>
<artifactId>fop</artifactId>
<version>1.0</version>
</dependency>
<dependency>
<groupId>javax</groupId>
<artifactId>javaee-api</artifactId>
<version>7.0</version>
<scope>provided</scope>
</dependency>
</dependencies>
</project>
2) Some test servlet with the following content:
package main;
import org.mozilla.javascript.Context;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
public class TestServlet extends HttpServlet {
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
{
Context context = new Context();
context.setLanguageVersion(Context.VERSION_1_7);
}
}
Compiling this using mvn clean package will cause
java.lang.IllegalArgumentException: Bad language version: 170
That's because patched (by fop) Context is using, but I want Rhino original Context, which supports 1.7 version. If you remove fop dependency from pom.xml, everything will work just fine.
So how can I use both fop and lesscss without any errors?
Upvotes: 1
Views: 622
Reputation: 625
I hit this problem in production and solved it by removing batik-js from the classpath.
Empirically, org.apache.xmlgraphics 1.7 works fine with rhino 1.7R4 (unpatched), which is what org.lesscss/lesscss 1.3.3 depends on. So, just exclude batik-js from your build/classpath.
Upvotes: 1