Apache POI usage with Apache Felix - apache-poi

I'm trying to import Apache POI to Atlassian Jira Plugin for reading excel files.
At the beginning, I started with adding just
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi</artifactId>
<version>${poi.version}</version>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml-schemas</artifactId>
<version>${poi.version}</version>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
<version>${poi.version}</version>
</dependency>
poi.version is 3.14
then when I started the plugin it gave
Unresolved constraint in bundle com.tezExtensions [165]: Unable to resolve 165.0: missing requirement [165.0] osgi.wiring.package; (osgi.wiring.package=com.sun.javadoc)
Then I edited pom with some instructions which I found on another StackOverflow question Pax Exam issue with Apache POI wrapped bundle
<instructions>
<Atlassian-Plugin-Key>${atlassian.plugin.key}</Atlassian-Plugin-Key>
<!-- Add package to export here -->
<Export-Package>com.sony.poc.api,</Export-Package>
<_exportcontents>
org.apache.poi.*;version=${poi.version},
org.openxmlformats.schemas.*;version=${poi.schema.version},
schemasMicrosoftComOfficeExcel.*;version=${poi.schema.version},
schemasMicrosoftComOfficeOffice.*;version=${poi.schema.version},
schemasMicrosoftComOfficePowerpoint.*;version=${poi.schema.version},
schemasMicrosoftComVml.*;version=${poi.schema.version},
org.etsi.uri.*;version=${poi.security.version}
</_exportcontents>
<!-- Add package import here -->
<Import-Package>
com.sun.javadoc;resolution:=optional,
com.sun.tools.javadoc;resolution:=optional,
org.apache.crimson.jaxp;resolution:=optional,
org.apache.tools.ant;resolution:=optional,
org.apache.tools.ant.taskdefs;resolution:=optional,
org.apache.tools.ant.types;resolution:=optional,
junit.framework.*;resolution:=optional,
junit.textui.*;resolution:=optional,
org.junit.*;resolution:=optional,
org.apache.xml.security.*;resolution:=optional,
org.apache.jcp.xml.dsig.internal.dom.*;resolution:=optional,
org.springframework.osgi.*;resolution:="optional", org.eclipse.gemini.blueprint.*;resolution:="optional", *</Import-Package>
<DynamicImport-Package>
org.apache.xmlbeans.*,
schemaorg_apache_xmlbeans.*
</DynamicImport-Package>
With this configuration, I get this error;
Unable to resolve 165.0: missing requirement [165.0] osgi.wiring.package; (osgi.wiring.package=org.apache.xml.resolver)
Is there anyone have an idea?

Finally, I found a solution.
I have added these as dependency
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi</artifactId>
<version>${poi.version}</version>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-scratchpad</artifactId>
<version>${poi.version}</version>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
<version>${poi.version}</version>
<exclusions>
<exclusion>
<groupId>stax</groupId>
<artifactId>stax-api</artifactId>
</exclusion>
<exclusion>
<groupId>xml-apis</groupId>
<artifactId>xml-apis</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.codehaus.woodstox</groupId>
<artifactId>woodstox-core-asl</artifactId>
<version>4.4.1</version>
</dependency>
And also added these are to inside of Import-Package tag
*;resolution:=optional, com.ctc.wstx.stax.*
That's all.

Related

Log4j, Maven dependency

How to tell the compiler to use log4j2 version whenever it encounters log4j (1.x.y version) ?
I Want to replace on every encounter of :
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.17</version>
</dependency>
With :
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
<version>${log4j2-version}</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>${log4j2-version}</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-slf4j-impl</artifactId>
<version>${log4j2-version}</version>
</dependency>

Scenario.getSourceTagNames not including tags under examples section of a scenario outline

I'm looping through scenario.getSourceTagNames() within the #after tearDown method but the tags within my example section are not being shown as part of this list. I see this question has been asked a few times here but I'm afraid the solutions I found haven't been able to fix my issue so far (answers usually suggest updating the cucumber-jvm version). These are my pom configs.
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-jvm</artifactId>
<version>5.4.2</version>
<type>pom</type>
</dependency>
<dependency>
<groupId>info.cukes</groupId>
<artifactId>cucumber-jvm-deps</artifactId>
<version>1.0.5</version>
</dependency>
<dependency>
<groupId>info.cukes</groupId>
<artifactId>gherkin</artifactId>
<version>2.12.2</version>
</dependency>
It looks like you are on the latest (or very recent) Cucumber version.
However, try using <artifactId>cucumber-java</artifactId> (cucumber-java instead of cucumber-jvm).
Also, remove the following dependencies to avoid clashes / problems, as they are transitive dependencies of cucumber:
<dependency>
<groupId>info.cukes</groupId>
<artifactId>cucumber-jvm-deps</artifactId>
<version>1.0.5</version>
</dependency>
<dependency>
<groupId>info.cukes</groupId>
<artifactId>gherkin</artifactId>
<version>2.12.2</version>
</dependency>
Issue to do with dependencies on the pom file as per #marit suggestion.
This is what I have now under my pom file in case it may be helpful to someone else.
<dependencies>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>3.141.5</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
</dependency>
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-jvm</artifactId>
<version>5.4.2</version>
<type>pom</type>
</dependency>
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-junit</artifactId>
<version>5.4.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-core</artifactId>
<version>5.4.2</version>
</dependency>
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-java</artifactId>
<version>5.4.2</version>
</dependency>
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>gherkin</artifactId>
<version>10.0.0</version>
</dependency>
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-picocontainer</artifactId>
<version>5.4.2</version>
</dependency>
</dependencies>

Cucumber V4 [io.cucumber] is not identifying #Given/When/Then and giving error "The import cucumber.api.java.en.When cannot be resolved"

I am migrating from Cucumber Version 1.2.4 [<groupId>info.cukes</groupId>] to V.4.2.2 <groupId>io.cucumber</groupId>. After this, Cucumber Framework is not able to identify #Given/When/Then annotations and given error – The import cucumber.api.java.en.Given/When/Then cannot be resolved
Eclipse suggesting to add below dependency. But my thought is when I am migrating to Cucumber V4(io.cucumber) then why shall I add dependency of V1.2.4(info.cukes). Can someone suggest which is the correct dependency I shall add under V4 i.cucumber. which import i shall add to fix this issue. Can it be resolved without adding info.cukes -> cuucmber-java(1.2.4)
<dependency>
<groupId>info.cukes</groupId>
<artifactId>cucumber-java</artifactId>
<version>1.2.4</version>
</dependency>
Below is the list of dependencies I have added under POM.xml. All are io.cucumber dependencies.
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-core</artifactId>
<version>4.2.2</version>
</dependency>
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-java</artifactId>
<version>4.2.2</version>
</dependency>
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-junit</artifactId>
<version>4.2.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-jvm-deps</artifactId>
<version>1.0.6</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>gherkin</artifactId>
<version>6.0.14</version>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-all</artifactId>
<version>1.10.19</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-testng</artifactId>
<version>2.0.0</version>
</dependency>
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-picocontainer</artifactId>
<version>2.1.0</version>
<scope>test</scope>
</dependency>
Please help me to understand how this error can be resolved under cucumber v4. I do not want to use info.cukes maven id as it does not have V4. So please guide
I have resolved the issue and sharing correct set of dependency. Please add JUnit/TestNG based on your framework requirement.
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-java</artifactId>
<version>4.2.3</version>
</dependency>
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-junit</artifactId>
<version>4.2.3</version>
<scope>test</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/junit/junit -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/io.cucumber/datatable -->
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>datatable</artifactId>
<version>1.1.12</version>
</dependency>
<!-- https://mvnrepository.com/artifact/io.cucumber/cucumber-testng -->
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-testng</artifactId>
<version>4.2.3</version>
</dependency>
<!-- https://mvnrepository.com/artifact/io.cucumber/cucumber-picocontainer -->
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-picocontainer</artifactId>
<version>4.2.3</version>
<scope>test</scope>
</dependency>
Maven looks stopped the <groupId>info.cukes</groupId> cucumber-java, instead of using <groupId>io.cucumber</groupId>.
So, from above version 4.7.0 of (<groupId>io.cucumber</groupId><artifactId>cucumber-java</artifactId>), there is no longer support for cucumber.api.java.en.Given/When/Then.
You can use import io.cucumber.java.en.Given(/When/Then) replacing it.
I too faced this issue. After replacing cucumber.api.java.en.Given/When/Then
with
import io.cucumber.java.en.Given(/When/Then)
the feature file was running the mapped methods

Jira plugin Apache Poi

I'm having some problems including Apache Poi in a simple Jira plugin. While trying to make a simple proof of concept to generate an Excel file (ooxml actually) I'm getting some dependency / class cast exception issues. My plugin extends AbstractSearchRequestView and the following code snippets tries to output an empty xlsx file.
public void writeSearchResults(SearchRequest sr, SearchRequestParams srp, Writer writer) throws SearchException
{
XSSFWorkbook wb = new XSSFWorkbook();
WriterOutputStream out = new WriterOutputStream(writer);
wb.write(out);
}
Now I have my export option available in the Jira issue search screen, but when running it I'm getting the following classcastexception:
java.lang.ClassCastException: com.ctc.wstx.stax.WstxEventFactory cannot be cast to javax.xml.stream.XMLEventFactory
My pom file POI dependencies look like this:
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi</artifactId>
<version>3.15</version>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
<version>3.15</version>
</dependency>
I have tried to configure everything like in this question / answer but I get the same issue.
Try with below set of dependencies.
<dependency>
<groupId>org.apache.xmlbeans</groupId>
<artifactId>xmlbeans</artifactId>
<version>2.6.0</version>
<exclusions>
<exclusion>
<groupId>stax</groupId>
<artifactId>stax-api</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi</artifactId>
<version>3.14</version>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
<version>3.14</version>
<exclusions>
<exclusion>
<groupId>stax</groupId>
<artifactId>stax-api</artifactId>
</exclusion>
<exclusion>
<groupId>xml-apis</groupId>
<artifactId>xml-apis</artifactId>
</exclusion>
<exclusion>
<groupId>dom4j</groupId>
<artifactId>dom4j</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>ooxml-schemas</artifactId>
<version>1.3</version>
</dependency>

Error while implementing XSSF example

I want to read large Excel files (.xlsx) with java. Apache has an example how to go this here.
So I just copied the whole class, added the path to my .xlsx file and tried to execute it but I get this error:
Error:(96, 69) java: cannot access org.openxmlformats.schemas.spreadsheetml.x2006.main.CTRst
class file for org.openxmlformats.schemas.spreadsheetml.x2006.main.CTRst not found
This error is triggered in this line in the method endElement():
lastContents = new XSSFRichTextString(sst.getEntryAt(idx)).toString();
I use this dependency for maven:
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
<version>3.9</version>
</dependency>
How do I fix this error?
With the help from Gagravarr I was able to fix this issue. I just needed to add the following dependencied to maven:
<dependency>
<groupId>commons-codec</groupId>
<artifactId>commons-codec</artifactId>
<version>1.9</version>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi</artifactId>
<version>3.9</version>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
<version>3.9</version>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml-schemas</artifactId>
<version>3.9</version>
</dependency>
<dependency>
<groupId>stax</groupId>
<artifactId>stax-api</artifactId>
<version>1.0.1</version>
</dependency>
<dependency>
<groupId>org.apache.xmlbeans</groupId>
<artifactId>xmlbeans</artifactId>
<version>2.6.0</version>
</dependency>
<dependency>
<groupId>dom4j</groupId>
<artifactId>dom4j</artifactId>
<version>1.6.1</version>
</dependency>

Resources