0

I configed Jenkins to compile and build java project. But I got the below error

[javac] C:\Users\Administrator\.jenkins\workspace\AMRM\AMRM-rad-workspace\AMRM\src\com\bidv\amrm\struts2\jdbc\DeclareAppImpl.java:232: error: incompatible types
    [javac]                   return DB.getConnection().queryForObject(sql, new Object[]{id}, new DTOMapper());
    [javac]                                                           ^
    [javac]   required: ListAppDTO
    [javac]   found:    Object

I found a solution to fix is adding the line: @SuppressWarnings("unchecked") before relate function in java code

But, are there any other solution ? Such as config in Jenkins ? I don't want to change my code, because My project still compiled success in Eclipse (but error in Jenkins)

taibc
  • 897
  • 2
  • 15
  • 39
  • 3
    This really has nothing to do with Jenkins but all with the Java program you are trying to compile. Are you using the same language version on both? – Henry Jan 04 '18 at 10:56
  • 1
    What is the signature of the method `DB.getConnection().queryForObject()` ? – Bentaye Jan 04 '18 at 11:03
  • 1
    Is the Java (version) running in Jenkins machine and development machine are same? – Vishwa Dany Jan 04 '18 at 12:14
  • The question doesn't show sufficient information about the program in order to give precise answers, but we can see two things: (1) Eclipse and javac give different answers (which version of each??) and (2) the program involves raw types / unchecked conversions. JLS rules about raw types are quite tricky and both compilers are known to have bugs in this area, some have been fixed between versions, but most importantly: Java programmers should strictly refrain from using raw types. So, as long as your program uses `@SuppressWarnings("unchecked")` it can and should be improved. – Stephan Herrmann Jan 05 '18 at 10:56
  • In Eclipse, my project used Java 1.6 for compiler. In jenkins, I tried to config jdk 1.6, 1.7, 1.8 but still error – taibc Jan 08 '18 at 02:19
  • I also got error with this function: @SuppressWarnings("unchecked") @Override public ChiNhanhHoiSoChinhDTO getChiNhanhHoiSoChinhDTOById(int id) { try { String strSelect = "SELECT ID, MACHINHANH, TENCHINHANH, TENVIETTAT, SODIENTHOAI FROM DANHSACH_CN_HSC WHERE ID = ?"; return DB.getConnection().queryForObject(strSelect, new Object[] { id }, new ChiNhanhHoiSoChinhDTOMapper()); } catch (Exception ex) { System.out.println(ex.toString()); } return null; } – taibc Jan 08 '18 at 12:35

1 Answers1

0

I found the reason, it is because my jenkins still use a different java version.

So I pass the correct version (1.6) into build statement javac, then it is successful (java.home = C:\Program Files\Java\jdk1.6.0_23)

<javac fork="yes" executable="${java.home}\bin\javac" includeantruntime="false" encoding="utf-8" srcdir="${workspace}/${project.name}/src" destdir="${workspace}/${project.name}/WebContent/WEB-INF/classes" classpath="${was_cp}">
        </javac>

But, I got another error:

Caused by: java.io.IOException: Cannot run program "C:\java1.6\bin\javac": CreateProcess error=206, The filename or extension is too long.
taibc
  • 897
  • 2
  • 15
  • 39