We add the aspose.cad.24.jar in eclipse, and try to run simple program throw error
import com.aspose.cad.License;
import com.aspose.cad.Image;
import com.aspose.cad.fileformats.cad.CadDrawTypeMode;
import com.aspose.cad.fileformats.cad.CadImage;
import com.aspose.cad.fileformats.cad.cadobjects.CadText;
import com.aspose.cad.imageoptions.CadRasterizationOptions;
import com.aspose.cad.imageoptions.PdfOptions;
public class test {
public static void main(String[] args) {
// TODO Auto-generated method stub
System.out.println("Testing 123456");
License license = new License();
license.setLicense("D:\\Temp\\Aspose.CADProductFamily.lic");
System.out.println("Testing 12345");
Image image = Image.load("D:\\Temp\\test.dwg");
Testing 123456
Testing 12345
Exception in thread “main” java.lang.VerifyError: Illegal type at constant pool entry 64 in class com.aspose.cad.internal.gK.dC
Exception Details:
Location:
com/aspose/cad/internal/gK/dC.(Lcom/aspose/cad/internal/gK/ii;)V @27: invokestatic
Reason:
Constant pool index 64 is invalid
Bytecode:
0000000: 2ab7 003f 2a2b b500 182a bb00 1359 2ab4
0000010: 0018 b700 37b6 003c b200 1cb8 0040 b900
0000020: 4202 00b2 001d b900 4102 00b2 001e b900
0000030: 4302 00c0 0002 b500 19b1
at com.aspose.cad.internal.gK.ii.d(Unknown Source)
at com.aspose.cad.internal.gK.ay.e(Unknown Source)
at com.aspose.cad.internal.gK.ay.a(Unknown Source)
at com.aspose.cad.internal.hf.n.a(Unknown Source)
at com.aspose.cad.internal.gI.i.a(Unknown Source)
at com.aspose.cad.internal.gI.bY.a(Unknown Source)
at com.aspose.cad.internal.gI.bW.a(Unknown Source)
at com.aspose.cad.Image.a(Unknown Source)
at com.aspose.cad.Image.load(Unknown Source)
at test.main(test.java:21)
@snazeer
The error you are encountering when trying to load a DWG file using Aspose.CAD in your Java application may be related to a few common issues. Here are some steps you can take to troubleshoot and resolve the problem:
-
Check Library Compatibility: Ensure that the version of the Aspose.CAD library you are using is compatible with your Java version. Sometimes, using an incompatible version can lead to runtime errors.
-
Verify License File: Make sure that the license file path you provided is correct and that the license is valid. An invalid or improperly set license can cause issues when loading files.
-
Correct File Path: Double-check the file path of the DWG file you are trying to load. Ensure that the file exists at the specified location and that your application has the necessary permissions to access it.
-
Dependencies: Ensure that all required dependencies for Aspose.CAD are included in your project. Missing dependencies can lead to runtime errors.
-
Java Version: The error message you received (java.lang.VerifyError
) can sometimes be caused by using an incompatible Java version. Make sure you are using a supported version of Java for the Aspose.CAD library.
-
Sample Code: Here is a simple example of how to load a DWG file using Aspose.CAD:
import com.aspose.cad.Image;
import com.aspose.cad.License;
public class LoadDwgExample {
public static void main(String[] args) {
try {
// Set license
License license = new License();
license.setLicense("D:\\Temp\\Aspose.CADProductFamily.lic");
// Load DWG file
Image image = Image.load("D:\\Temp\\test.dwg");
System.out.println("DWG file loaded successfully.");
} catch (Exception e) {
e.printStackTrace();
}
}
}
If you continue to experience issues after checking these points, consider reaching out to Aspose support for further assistance, as they can provide more specific guidance based on your environment and setup.
If you have any additional questions or need further clarification, feel free to ask!
@snazeer,
please share one test DWG file, so we can check.
test.7z (125.1 KB)
we cannot use maven , we added the jar directly , could you advise what other jar need to be added.
@snazeer,
could you please try if release versions 24.3 or 24.2 work for this file? Please find them here: Aspose.CAD Java 24.4 | CAD and BIM Processing Conversion Java API SDK, there is Versions tab with jar files.
24.3 is working, thanks .do you have any sample to add annotations and stamp and save dwg as dxf file.
@snazeer,
Here is the example how to convert DWG to DXF:
CadImage cadImage = (CadImage)Image.load(in);
cadImage.save(dxfName, new DxfOptions());
Please share what you mean by annotation and stamp.