Trying the example found from here: https://itextpdf.com/en/products/itext-7/pdfxfa
public static void main() {
XFAFlattenerProperties flattenerProperties = new XFAFlattenerProperties()
.setPdfVersion(XFAFlattenerProperties.PDF_1_7)
.createXmpMetaData()
.setTagged()
.setMetaData(
new MetaData()
.setAuthor("iText Samples")
.setLanguage("EN")
.setSubject("Showing off our flattening skills")
.setTitle("Flattened XFA"));
XFAFlattener xfaf = new XFAFlattener()
.setFlattenerProperties(flattenerProperties);
xfaf.flatten(new FileInputStream("xfaform.pdf"), new FileOutputStream("flat.pdf"));
}
and getting java.lang.NoClassDefFoundError: org.mozilla.javascript.ScriptableObject
when trying to do
XFAFlattener xfaf = new XFAFlattener();
Not using Maven or POM. I have the following JARs in classpath:
io-7.1.10.jar
kernel-7.1.10.jar
layout-7.1.10.jar
itext-licensekey-3.0.6.jar
pdfrender-1.0.0.jar
pdfxfa-2.0.5.jar
Am I missing something?
You need org.mozilla:rhino:1.7R4 dependency: https://mvnrepository.com/artifact/org.mozilla/rhino/1.7R4
But as #Harry Coder mentioned, you should use Maven or Gradle or any other Maven-compatible build system that will download all the dependencies including transitive ones automatically for you
Related
Following the setup described in Simple sharing of artifacts between projects, we are in the special case where we have a multi module gradle build that produce different types of jars and we would like to declare a dependency to those jar in a configuration.
dependencies {
instrumentedClasspath(project(path: ":producer", configuration: 'instrumentedJars'))
}
from the docs works great.
In the project dependency-tests I have a project that reproduce the setup (with different names, but the idea is the same).
But I am doing this in a Gradle-plugin and I would like to have the same declaration in java.
DependencyHandler dependencyHandler = project.getDependencies();
// this adds a dependency to the main jar of the 'producer' project:
dependencyHandler.add("instrumentedClasspath", project.getRootProject().findProject(":producer"));
// this is not working:
dependencyHandler.add("instrumentedClasspath", project.getRootProject().findProject(":producer").getConfigurations().getByName("instrumentedJars"));
Failing with:
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':printConf'.
> Could not resolve all dependencies for configuration ':instrumentedJars'.
> Cannot convert the provided notation to an object of type Dependency: configuration ':producer:instrumentedJars' artifacts.
The following types/formats are supported:
- Instances of Dependency.
- String or CharSequence values, for example 'org.gradle:gradle-core:1.0'.
- Maps, for example [group: 'org.gradle', name: 'gradle-core', version: '1.0'].
- FileCollections, for example files('some.jar', 'someOther.jar').
- Projects, for example project(':some:project:path').
- ClassPathNotation, for example gradleApi().
Comprehensive documentation on dependency notations is available in DSL reference for DependencyHandler type.
* Try:
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.
project(...)
inside the dependencies block comes from the DependencyHandler, and
path: ":producer", configuration: 'instrumentedJars'
is actually a map {"path"=":producer", "configuration"="instrumentedJars"}.
So something like that should work in Java:
Map<String, String> map = new HashMap<>();
map.put("path", ":producer");
map.put("configuration", "instrumentedJars");
dependencyHandler.add("instrumentedClasspath", dependencyHandler.project(map));
Note: When using Kotlin build script you can easily see types and declarations of functions and might be easier for discovering API. So in Kotlin project(...) in the dependencies block is an extension method defined as:
fun DependencyHandler.project(
path: String,
configuration: String? = null
): ProjectDependency =
uncheckedCast(
project(
if (configuration != null) mapOf("path" to path, "configuration" to configuration)
else mapOf("path" to path)
)
)
I have the following setup:
I have the following dependency in my POM:
<dependency>
<groupId>com.google.protobuf</groupId>
<artifactId>protobuf-java</artifactId>
<version>3.14.0</version>
</dependency>
I have a very simple proto file:
syntax = "proto3";
package com.ziath.genericdecoderserver;
option java_outer_classname = "DecodePackage";
message DecodeData {
string template = 1;
bytes image = 2;
int32 startColumn = 3;
int32 endColumn = 4;
}
I'm generating the proto file using the version 3.14.0, binary for win64:
PS C:\Users\neilb\Documents\GitHub\GenericDecoderServer\src\main\protobuf\bin> .\protoc.exe --version
libprotoc 3.14.0
This matches the maven dependency I'm pulling in. However the file generated has error with the override annotation:
#java.lang.Override
public com.ziath.genericdecoderserver.DecodePackage.DecodeData buildPartial() {
com.ziath.genericdecoderserver.DecodePackage.DecodeData result = new
com.ziath.genericdecoderserver.DecodePackage.DecodeData(this);
result.template_ = template_;
result.image_ = image_;
result.startColumn_ = startColumn_;
result.endColumn_ = endColumn_;
onBuilt();
return result;
}
The reported error is:
The method buildPartial() of type DecodePackage.DecodeData.Builder must override a superclass method
So this method is in the Builder class which is defined as:
public static final class Builder extends com.google.protobuf.GeneratedMessageV3.Builder<Builder> implements
// ##protoc_insertion_point(builder_implements:com.ziath.genericdecoderserver.DecodeData)
com.ziath.genericdecoderserver.DecodePackage.DecodeDataOrBuilder {
Eclipse is correct the method buildPartial is not in either of the interfaces protobuf is referencing so it looks like a version mismatch but the versions are the same. There are scores of errors in this generated code along the same lines. Does anybody know what the problem is or even seen this before because my searches show nothing from this?
Thanks.
Cheers,
Neil
Solved it! The project was created using Spring Initilaser and for some reason that made the java version to be 1.5 in eclipse. 1.5 does not allow override for interface methods.
Eclipse Aether doesn't seem to return the correct release when I try to resolve a LATEST version:
val artifact = DefaultArtifact("org.testng:testng:LATEST")
val versionResult = system.resolveVrsion(session, VersionRequest(artifact, repositories, null))
println(versionResult)
produces:
6.9.8 # maven (https://jcenter.bintray.com/, default, releases+snapshots)
However, 6.9.10 is the latest, and JCenter is reporting it correctly, both in the directory and also in the maven-metadata.xml:
<metadata>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>6.9.10</version>
<versioning>
<latest>6.9.10</latest>
<release>6.9.10</release>
Why am I getting 6.9.8 instead of 6.9.10?
There are two things which might the cause of your problem. First you assume that the magic word LATEST is supported by Aether and if i remember correctly (and looking into the code of Aether it is not supported). This means you should use a version range to get the latest.
Furthermore if you have a version range you need to call resolveVersionRange(...) instead of resolveVersion(..).
String versionRange = "[0,)";
Artifact artifact =
new DefaultArtifact( "org.testng:testng:jar:" + versionRange );
VersionRangeRequest rangeRequest = new VersionRangeRequest();
rangeRequest.setArtifact( artifact );
rangeRequest.setRepositories( remoteRepos );
VersionRangeResult rangeResult = repository.resolveVersionRange( repositorySystemSession, rangeRequest );
List<Version> versions = rangeResult.getVersions();
The above is a slightly modified version taken from a plugin i wrote. There is also a ctor of DefaultArtifact which contains only the appropriate parameters which might be a better alternative to use instead of concatenating the strings.
I created a blank struts 2 archetype using maven 3, m2eclipse plugin for eclipse Indigo. I encountered this error after project generation.
The method addConfigurationProvider(XmlConfigurationProvider) is undefined for the type
ConfigurationManager
This is from the ConfigTest.java
protected void setUp() throws Exception {
super.setUp();
XmlConfigurationProvider c = new XmlConfigurationProvider("struts.xml");
configurationManager.addConfigurationProvider(c);
configurationManager.reload();
}
How do I resolve this?
Thanks in advance.
The method addConfigurationProvider was marked as deprecated and replaced by addContainerProvider. With version 2.3.x this method was removed.
That was the bug with the struts2-archetype-blank.I believe you need to change the following settings
configurationManager.addConfigurationProvider(c);
to this:
configurationManager.addContainerProvider( c );
I hope this fill fix your issue
I have a java project that is built with buildr and that has some external dependencies:
repositories.remote << "http://www.ibiblio.org/maven2"
repositories.remote << "http://packages.example/"
define "myproject" do
compile.options.target = '1.5'
project.version = "1.0.0"
compile.with 'dependency:dependency-xy:jar:1.2.3'
compile.with 'dependency2:dependency2:jar:4.5.6'
package(:jar)
end
I want this to build a single standalone jar file that includes all these dependencies.
How do I do that?
(there's a logical followup question: How can I strip all the unused code from the included dependencies and only package the classes I actually use?)
This is what I'm doing right now. This uses autojar to pull only the necessary dependencies:
def add_dependencies(pkg)
tempfile = pkg.to_s.sub(/.jar$/, "-without-dependencies.jar")
mv pkg.to_s, tempfile
dependencies = compile.dependencies.map { |d| "-c #{d}"}.join(" ")
sh "java -jar tools/autojar.jar -baev -o #{pkg} #{dependencies} #{tempfile}"
end
and later:
package(:jar)
package(:jar).enhance { |pkg| pkg.enhance { |pkg| add_dependencies(pkg) }}
(caveat: I know little about buildr, this could be totally the wrong approach. It works for me, though)
I'm also learning Buildr and currently I'm packing Scala runtime with my application this way:
package(:jar).with(:manifest => _('src/MANIFEST.MF')).exclude('.scala-deps')
.merge('/var/local/scala/lib/scala-library.jar')
No idea if this is inferior to autojar (comments are welcome), but seems to work with a simple example. Takes 4.5 minutes to package that scala-library.jar thought.
I'm going to use Cascading for my example:
cascading_dev_jars = Dir[_("#{ENV["CASCADING_HOME"]}/build/cascading-{core,xml}-*.jar")]
#...
package(:jar).include cascading_dev_jars, :path => "lib"
Here is how I create an Uberjar with Buildr, this customization of what is put into the Jar and how the Manifest is created:
assembly_dir = 'target/assembly'
main_class = 'com.something.something.Blah'
artifacts = compile.dependencies
artifacts.each do |artifact|
Unzip.new( _(assembly_dir) => artifact ).extract
end
# remove dirs from assembly that should not be in uberjar
FileUtils.rm_rf( "#{_(assembly_dir)}/example/package" )
FileUtils.rm_rf( "#{_(assembly_dir)}/example/dir" )
# create manifest file
File.open( _("#{assembly_dir}/META-INF/MANIFEST.MF"), 'w') do |f|
f.write("Implementation-Title: Uberjar Example\n")
f.write("Implementation-Version: #{project_version}\n")
f.write("Main-Class: #{main_class}\n")
f.write("Created-By: Buildr\n")
end
present_dir = Dir.pwd
Dir.chdir _(assembly_dir)
puts "Creating #{_("target/#{project.name}-#{project.version}.jar")}"
`jar -cfm #{_("target/#{project.name}-#{project.version}.jar")} #{_(assembly_dir)}/META-INF/MANIFEST.MF .`
Dir.chdir present_dir
There is also a version that supports Spring, by concatenating all the spring.schemas