importing Apache POI Java - import

Hi I'm having a bit of trouble using the Apache POI library in java. I've downloaded and imported the library into my project, but am unable to import it into my java class. (like you would do):
import java.awt.*;
Am I looking at this the wrong way, or am I missing something?

If you are using maven, map de dependecies:
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi</artifactId>
<version>3.14</version>
</dependency>
Then import and use the apache poi library:
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
//..
FileInputStream file = new FileInputStream(new File("C:\\test.xls"));

Related

java.lang.NoClassDefFoundError: javax/xml/transform/TransformerConfigurationException

I am using dummy html string and trying to create the pdf from that...
once it tries to create ITextRenderer object, I am getting the "java.lang.NoClassDefFoundError: javax/xml/transform/TransformerConfigurationException"
Document doc = Jsoup.parse("<html><head><title>Pdf Generation..!</title></head><body><p>Pdf generated using flying saucer pdf openpdf!!!!</p></body></html>","UTF-8");
doc.outputSettings().syntax(Document.OutputSettings.Syntax.xml);
try (OutputStream os = new FileOutputStream("output.pdf")){
ITextRenderer renderer = new ITextRenderer();
SharedContext cntxt = renderer.getSharedContext();
cntxt.setPrint(true);
cntxt.setInteractive(false);
renderer.setDocumentFromString(doc.html(), "");
renderer.layout();
renderer.createPDF(os);
logger.info("PDF Generation using OpenPDF Done Successfully!!!");
}
catch(Exception ex){
ex.printStackTrace();
}
This is a maven archetype project and dependencies used for this are,
<dependency>
<groupId>org.jsoup</groupId>
<artifactId>jsoup</artifactId>
<version>1.14.3</version>
</dependency>
<dependency>
<groupId>org.xhtmlrenderer</groupId>
<artifactId>flying-saucer-pdf-openpdf</artifactId>
<version>9.1.20</version>
</dependency>
<dependency>
<groupId>org.xhtmlrenderer</groupId>
<artifactId>flying-saucer-core</artifactId>
<version>9.1.20</version>
</dependency>
I have looked through some of the shared suggestions, but none of it could resolve this...
Check the Import-Package directive in the BND Maven plugin. Either import javax.xml.transform explicitly or import everything (*)
javax.xml.transform.* is a provided API which is present in many bundle definitions. The correct Import-Package should include something like this:
javax.xml.transform,version=2.1.0 from org.apache.felix.framework (0)

Maven setup for spark project in Eclipse Scala IDE

Im using Eclipse for Scala IDE to develop a Spark application.
Im using a Maven project, but when i try to import sparkcon like :
import org.apache.spark.SparkConf
I have the error :
object apache is not a member of package org can you help me to setup
spark dependancies
You need to put the Spark dependency in your pom.xml file. As of now, the latest version of Spark can be obtained by putting:
<dependency>
<groupId>org.apache.spark</groupId>
<artifactId>spark-core_2.10</artifactId>
<version>2.2.0</version>
</dependency>
in the dependencies in your pom.xml.
Please check the tutorial from
https://sparktutorials.github.io/2015/04/02/setting-up-a-spark-project-with-maven.html
Online tutorial
https://www.youtube.com/watch?v=4sO-VgqHLp4

How to import TwitterUtils library from scala

I am using DSE 4.8. I am trying to import twitterutils library by using:
import org.apache.spark.streaming.twitter.TwitterUtils
It's showing error:
object twitter is not a member of package org.apache.spark.streaming.
Please let me know how to add package so that I can stream twitter data
I think you have missed to add dependency spark-streaming-twitter.
<!-- https://mvnrepository.com/artifact/org.apache.spark/spark-streaming-twitter_2.10 -->
<dependency>
<groupId>org.apache.spark</groupId>
<artifactId>spark-streaming-twitter_2.10</artifactId>
<version>1.6.1</version>
</dependency>
You can alternatively use --package option to let spark auto download the jar for you if you have internet connection.
spark-shell --packages org.apache.bahir:spark-streaming-twitter_2.11:2.1.0
** Change version of the library as per your spark(scala) version

How to convince Scala IDE to recognize org.apache.spark.graphx._ package?

When I try to include GraphX into my work, it seems I'm doing something wrong because Scala IDE doesn't recognize org.apache.spark.graphx._ or anything related to graphs (!)
Did I miss something when I first created my project? Do I need to include additional libraries (how?)?
You need to add the GraphX dependency to your pom file.
<dependency>
<groupId>org.apache.spark</groupId>
<artifactId>spark-graphx_2.10</artifactId>
<version>1.6.1</version>
</dependency>
There is now a --packages option for the Spark shell. You use it like this:
spark-shell --packages [maven:coordinates:here]

Eclipse cannot resolve org.springframework.extensions.*

I should develope a java backed web script for alfresco but some libraries are missing on the classpath so most of the classes I like to use can not be resolved. I can build the project but Eclipse can not find the classes:
import org.springframework.extensions.webscripts.AbstractWebScript;
import org.springframework.extensions.webscripts.WebScriptException;
import org.springframework.extensions.webscripts.WebScriptRequest;
import org.springframework.extensions.webscripts.WebScriptResponse;
Where can I download the jar to add it to the classpath? I already searched and googled but I cannot find a download :/
if you are using maven ,add this to your pom.xml
<dependency>
<groupId>org.springframework.extensions.surf</groupId>
<artifactId>spring-webscripts</artifactId>
<version>1.0.0.M3</version>
</dependency>
<dependency>
<groupId>org.springframework.extensions.surf</groupId>
<artifactId>spring-webscripts-api</artifactId>
<version>1.0.0.M3</version>
</dependency>