我写了一个代码来解析.eml文件到JSON文件.我使用下面的依赖关系
<dependency>
<groupId>com.sun.mail</groupId>
<artifactId>jakarta.mail</artifactId>
<version>2.0.1</version>
</dependency>
以下是我的代码
/**
* Convert .eml file to .json file
*
* @param inputFile .eml file
* @param outputFile .json file
* @return output file
* @throws Exception Exception
*/
public File executeTransform(File inputFile, File outputFile) throws Exception {
try {
Properties properties = new Properties();
Session session = Session.getDefaultInstance(properties);
// Read the .eml file
InputStream emlInputStream = new FileInputStream(inputFile);
MimeMessage emlMessage = new MimeMessage(session, emlInputStream);
// Convert the email message to JSON. convertEmlToJson() This function reads eml, extracts required data from it, puts that data in ObjectNode, and returns that ObjectNode.
ObjectNode jsonNode = convertEmlToJson(emlMessage);
// Write JSON to a file
ObjectMapper objectMapper = new ObjectMapper();
objectMapper.enable(SerializationFeature.INDENT_OUTPUT);
objectMapper.writeValue(outputFile, jsonNode);
} catch (Exception e) {
System.err.println("Test log : error occurred " + e.getMessage());
throw e;
}
return outputFile;
}
运行此代码时,出现以下错误
java.lang.reflect.InvocationTargetException and cause java.lang.NoSuchMethodError: 'void com.sun.mail.util.LineInputStream.<init>(java.io.InputStream, boolean)'
并获得此行的上述错误
MimeMessage emlMessage = new MimeMessage(session, emlInputStream);
有人知道我需要做什么来解决这个问题吗?