I create a very simple java programe c:\temp\Test.java as:
import com.aspose.words.Document;
public class Test
{
public static void main(String args[])
{
try
{
System.out.println("abc");
Document doc = new Document("c:/temp/wordTemplate.doc");
}
catch (Exception e)
{
e.printStackTrace();
}
}
}
I have Aspose.Words.jdk14.jar copied to c:\temp
I also have c:/temp/wordTemplate.doc created
Then I complied the c:\temp\Test.java with the command as: c:\temp > javac -classpath Aspose.Words.jdk14.jar Test.java
It compiled successfully with Test.class created in c:\temp.
But when I tried to run “Test.class”, it throw Exception. The command and Exception is like:
**C:\temp>**java -classpath c:\temp;c:\temp\Aspose.Words.jdk14.jar Test
abc
Exception in thread "main" java.lang.NoClassDefFoundError: edu/emory/mathcs/bac
port/java/util/concurrent/ConcurrentMap
at com.aspose.words.nonpublic.bf.(Unknown Source)
at com.aspose.words.kx.(Unknown Source)
at com.aspose.words.Styles.(Unknown Source)
at com.aspose.words.Document.(Unknown Source)
at com.aspose.words.Document.(Unknown Source)
at com.aspose.words.Document.(Unknown Source)
at Test.main(Test.java:12)
**C:\temp>**
It’s very strange case. We do not using java.util.concurrent.* package. So ours users don’t need in backport-util-concurrent-x.x.jar for launching Aspose.Words for Java under java 1.4.
Probably, something wrong with your environment (?) May be you launching Aspose.Words jdk1.4 jar under java 1.5 or java 1.6? What version of Aspose.Words and what jdk are you using?
The simplest workaround for your problem is using Aspose.Words.jdk15.jar under JDK 1.5. Another way – if you prefer using JDK 1.4, you can download backport-util-concurrent-3.0.jar and add it to your classpath. This jar you can download from http://dcl.mathcs.emory.edu/util/backport-util-concurrent/dist/backport-util-concurrent-3.0/Java14/backport-util-concurrent-3.0.zip .
It’s very strange case. We do not using java.util.concurrent.* package. So ours users don’t need in backport-util-concurrent-x.x.jar for launching Aspose.Words for Java under java 1.4.
Probably, something wrong with your environment (?) May be you launching Aspose.Words jdk1.4 jar under java 1.5 or java 1.6? What version of Aspose.Words and what jdk are you using?
The simplest workaround for your problem is using Aspose.Words.jdk15.jar under JDK 1.5. Another way – if you prefer using JDK 1.4, you can download backport-util-concurrent-3.0.jar and add it to your classpath. This jar you can download from http://dcl.mathcs.emory.edu/util/backport-util-concurrent/dist/backport-util-concurrent-3.0/Java14/backport-util-concurrent-3.0.zip .
d’oh! I got the same error, so I’ve added the backport-util-concurrent jar
Rewind: I’ve installed JDK 1.4.2, re-compiled (previously I was compiling using JDK1.5 with 1.3 compiler compliance…).
Now I got this error:
java.lang.NoClassDefFoundError: com/sun/org/apache/xerces/internal/impl/dv/util/Base64
at com.aspose.words.u.a(Unknown Source)
at com.aspose.words.u.a(Unknown Source)
at com.aspose.words.u.a(Unknown Source)
at com.aspose.words.License.setLicense(Unknown Source)
I have reproduced your bug under jdk 1.4. Thanks you for reporting the thing to us. The bug will be fixed shortly. Meantime i suggest you using jdk 1.5 for your first Aspose.Words app – there are some very convenient things in java 1.5 (annotations, generics, autoboxing/unboxing, etc.) that facilitate your work.
Thanks for the help and I am glad that I reported a bug.
Unfortunately, we have to use jdk1.4, since we use Websphere 6.0, which acquire jdk1.4.
After I add the backport jar to the classpath, no exception throws. But when I use MailMerg function, another exception is thrown. Could you help me on this?
My java file:
---------
import com.aspose.words.Document;
public class Test
{
public static void main(String args[])
{
try
{
System.out.println("abc");
Document doc = new Document("c:\\temp\\wordTemplate.doc");
String[] fieldName = {"username", "projectname"};
Object[] fieldValues = {"ggao1", "UPS"};
doc.getMailMerge().execute(fieldName, fieldValues);
}
catch (Exception e)
{
e.printStackTrace();
}
}
}
---------
My word file does have 2 merge fields with name “username” and “projectname”
**C:\temp>**java -classpath c:\temp;Aspose.Words.jdk14.jar;backport-util-concurrent.
jar Test
abc
com.aspose.words.PleaseReportException: Attempted to copy a by reference attribu
te '60': class com.aspose.words.nonpublic.fq, but the attribute does not expose
the complex attribute interface. For free technical support, please post this er
ror and the file in the Aspose.Words Forums [http://www.aspose.com/forums/ShowFor](/forums/ShowFor)
um.aspx?ForumID=75.
at com.aspose.words.cx.a(Unknown Source)
at com.aspose.words.cx.eA(Unknown Source)
at com.aspose.words.DocumentBuilder.a(Unknown Source)
at com.aspose.words.DocumentBuilder.dO(Unknown Source)
at com.aspose.words.DocumentBuilder.moveTo(Unknown Source)
at com.aspose.words.DocumentBuilder.a(Unknown Source)
at com.aspose.words.DocumentBuilder.a(Unknown Source)
at com.aspose.words.DocumentBuilder.a(Unknown Source)
at com.aspose.words.DocumentBuilder.a(Unknown Source)
at com.aspose.words.DocumentBuilder.a(Unknown Source)
at com.aspose.words.DocumentBuilder.moveToDocumentStart(Unknown Source)
at com.aspose.words.DocumentBuilder.setDocument(Unknown Source)
at com.aspose.words.DocumentBuilder.(Unknown Source)
at com.aspose.words.ih.a(Unknown Source)
at com.aspose.words.MailMerge.execute(Unknown Source)
at com.aspose.words.MailMerge.execute(Unknown Source)
at Test.main(Test.java:17)
**C:\temp>**
If you need in JDK 1.4 you have to revert to Aspose.Words for Java ver. 2.1 for a while. All should work properly in 2.1 except of absence of html import functionality. Both bugs (implicit need of backport-util jar and “by reference attribute ‘60’”) will be fixed shortly and released as Aspose.Words for Java ver.2.2.1.
Thanks for the help. When I use Aspose.Words for Java ver. 2.1 with jdk1.42, I didn’t get these 2 exception and I can do “simple mail merge” successfully. But the “mail merge with region” seems not work for me. Is it possible also an issue related with jdk1.42? Any suggestion?
Exception in thread “main” java.lang.NoClassDefFoundError: edu/emory/mathcs/bac
port/java/util/concurrent/ConcurrentMap
at com.aspose.words.nonpublic.bf.(Unknown Source)
at com.aspose.words.kx.(Unknown Source)
at com.aspose.words.Styles.(Unknown Source)
at com.aspose.words.Document.(Unknown Source)
at com.aspose.words.Document.(Unknown Source)
at com.aspose.words.Document.(Unknown Source)
I got the same exact problem. Have switched back to 2.1 and it’s working now…
I have a table in DB named “CAR”, which has 2 records and columns named “SCREEN_CODE”, “CREATED_USER”
This is my word template (all merge fields are in a same row of a table)
-----------------
A. CONTRACT INFORMATION
«TableStart:CAR»
«SCREEN_CODE»
«CREATED_USER»
«TableEnd:CAR»
-----------------
When I run doc.getMailMerge().execute(rs);
I got a word file like:
-------------------
A. CONTRACT INFORMATION
«TableStart:CAR»
C_SP
ACCOSUP122
«TableEnd:CAR»
B. CONTRACT INFORMATION
«TableStart:CAR»
123456
54212
«TableEnd:CAR»
------------------
Since I want the records to be in the same table, so I use:
doc.getMailMerge().executeWithRegions(rs);
But this function doesn’t work, the generated word file is just same as the template, without any data from the ResultSet. This is the generated word file:
Quote from Aspose.Words Programmer’s Guide (you can find it on Aspose.Words for Java | Aspose API References ): “If you want to dynamically grow portions inside the document, use mail merge with regions.” So doc.getMailMerge().execute(rs) performed as expected.
You don’t need to place TableStart and TableEnd fields into separate cells – it’s better to place TableStart right before (and in one cell with) SCREEN_CODE and, accordingly, TableEnd right after CREATED_USER.
If mailmerge engine didn’t merge any data into template – it just didn’t find any appropriate data to merge. Probably, it is some mismatch in a table names. Please check rs.getMetaData().getTableName(1) (gets a table name of the very first resultset’s column) – it should be equal to “CAR”.
But as I can see from your pictures (it will be better just to send the files:) – merged only the first row of a table (?).
The following is the link to the doc generated by MailMergeWithRegion. There is no merge action happens actually, not even for 1 row. Sorry for the mistake in the previous post.
I run rs.getMetaData().getTableName() for all the column to try to get table name, and nothing returns. This maybe the reason why MailMergeWithRegions doesn’t work for me. It looks like a limitation of JDBC driver that I could not get table name from ResultSetMeta. The JDBC driver we are using is JTDS for MS SQL Server 2000.
Is there any possible workaround for this issue? Besides MailMergeWithRegions, is there another way to dynamically grow the data portions inside the document?
Yes, some jdbc drivers don’t fully comply with the ResultSet contract. There are several MailMerge.executeWithRegions() overloads intended for such cases.
MailMerge.executeWithRegions(String tableName, ResultSet dataTable) better suits for your case. With this overload you can manually set the table name.