cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Using external dependency in Java bean annotation

mohan-sharma
Product and Topic Expert
Product and Topic Expert
0 Likes
473

Let's say I want to use opencsv. I have added the dependency in `external-dependencies.xml` asked to download the dependency by saying usemaven='true'. The jar file is downloaded and stored in the lib folder of the extension.

Now if I want to use this dependency to generate Java bean which contains annotation example.

<bean class="com.something.dto.IndirectSaleData">
    <import type="com.opencsv.bean.CsvBindByName"/>
    <property name="firstName" type="java.lang.String">
        <annotations>@CsvBindByName(column = "first_name", required = true)</annotations>
    </property>
</bean>

Why is it not able to resolve the dependency?

On the other hand if I directly create the Java Class it works totally fine example-

import com.opencsv.bean.CsvBindByName;
public class Data {

    @CsvBindByName(column = "first_name", required = true)
    private String name;

}

Accepted Solutions (0)

Answers (1)

Answers (1)

mohan-sharma
Product and Topic Expert
Product and Topic Expert
0 Likes

There is a way to plug in the dependency in the build class path. We can use `buildcallbacks.xml` for this. What I did is I moved the external dependency to `platform/core/lib` as I want it to be available during generation of model classes. code snippets:

<macrodef name="yourExtensionName_before_build"> 
   <sequential> 
      <echo message="Copy external jar to platform core"/> 
      <!-- Copy the jar from your extension lib folder to platform core --> 
      <copy file="${ext.yourExtensionName.path}/lib/your-dependency.jar" todir="${platformhome}/ext/core/lib" failonerror="true"/> 
   </sequential> 
</macrodef>