vscode-java icon indicating copy to clipboard operation
vscode-java copied to clipboard

Adding jar file using maven dependencies

Open nitink133 opened this issue 7 years ago • 11 comments

I am sure that this one is not a big thing but it ruined my Friday night and still I do not get my solution.

Well,I am importing itext java library using maven dependencies as we did in eclipse I just paste all itext dependencies in pom.xml and save pom.xml and things goes well but here the problem raise it show me the error Document class not found or so on.

Thanks in advance..

nitink133 avatar Apr 16 '18 05:04 nitink133

It should just work.

Can you execute Force Java compilation (Shift+Alt+B) (full build). Do you see anything in the server log

fbricon avatar Apr 16 '18 15:04 fbricon

Thanks @fbricon for your response Well,I have already tried Force java compilation but still i am facing the same problem while importing library.

This is the error which raise while compiling because of iText library not found.

PS E:\Documents\Sample\2Pdf\com.blackpaper.topdf\src\main\java\in\blackpaper\topdf> javac App.java
App.java:7: error: package com.itextpdf.kernel.pdf does not exist\blackpaper\topdf>
import com.itextpdf.kernel.pdf.PdfDocument;                              ^App.java:8: error: package com.itextpdf.kernel.pdf does not exist
import com.itextpdf.kernel.pdf.PdfWriter;
                              ^
App.java:9: error: package com.itextpdf.layout does not exist
import com.itextpdf.layout.Document;

Even i tried to add library manually but i don't know how can i do this in VSCode,Like In eclipse by inserting jar file into the lib folder and by adding its build path is enough but here i am unable to this.

Well,This is my project folder.Is there something missing?

https://imgur.com/p1umdPe

nitink133 avatar Apr 16 '18 21:04 nitink133

Ok so the error is just occurring when calling javac from command line apparently. When using Maven, you should not do it manually, since the classpath is not computed automatically. I suggest you call Maven from command line instead mvn compile or mvn clean compile. Make sure you read some tutorials about Maven to understand what's happening.

fbricon avatar Apr 16 '18 22:04 fbricon

Okay, let me assume that there is something wrong with Maven then it should not work with eclipse too, but in eclipse code is working perfectly without any warning.

This is my project structure in eclipse and in vscode. eclipse : https://imgur.com/a/sioC6 vscode : https://imgur.com/a/u0lfT

nitink133 avatar Apr 17 '18 06:04 nitink133

This is my project structure

https://imgur.com/a/Ik9QP

nitink133 avatar Apr 17 '18 08:04 nitink133

Does your project build from command line? Can you paste your pom.xml here please? And your .classpath

fbricon avatar Apr 17 '18 11:04 fbricon

Ya,I just build it from cmd.

Well,here is the pom.xml file

<project 
  xmlns="http://maven.apache.org/POM/4.0.0" 
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>in.blackpaper.pdfcreater</groupId>
  <artifactId>in.blackpaper.topdf</artifactId>
  <packaging>jar</packaging>
  <version>1.0-SNAPSHOT</version>
  <name>in.blackpaper.topdf</name>
  <url>http://maven.apache.org</url>
  <dependencies>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>3.8.1</version>
      <scope>test</scope>
    </dependency>
  </dependencies>
  <build>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>3.1</version>
        <configuration>
          <source>1.8</source>
          <target>1.8</target>
          <encoding>UTF-8</encoding>
          <debug>true</debug>
        </configuration>
      </plugin>
    </plugins>
  </build>
</project>

and .classpath

<?xml version="1.0" encoding="UTF-8"?>
<classpath>
	<classpathentry kind="src" output="target/classes" path="src/main/java">
		<attributes>
			<attribute name="optional" value="true"/>
			<attribute name="maven.pomderived" value="true"/>
		</attributes>
	</classpathentry>
	<classpathentry kind="src" output="target/test-classes" path="src/test/java">
		<attributes>
			<attribute name="optional" value="true"/>
			<attribute name="maven.pomderived" value="true"/>
			<attribute name="test" value="true"/>
		</attributes>
	</classpathentry>
	<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8">
		<attributes>
			<attribute name="maven.pomderived" value="true"/>
		</attributes>
	</classpathentry>
	<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
		<attributes>
			<attribute name="maven.pomderived" value="true"/>
		</attributes>
	</classpathentry>
	<classpathentry kind="output" path="target/classes"/>
		<classpathentry kind="lib" path="lib/itextpdf-5.4.1.jar"/>
</classpath>

nitink133 avatar Apr 17 '18 13:04 nitink133

I have the same problem

alejandrosaucedo avatar Nov 21 '18 17:11 alejandrosaucedo

Me too - can't even figure out a workaround:-(

JohnColeman avatar Nov 28 '18 12:11 JohnColeman

have you got the issue resolved>

harshilsd avatar Feb 08 '19 10:02 harshilsd

eventually I got going again - I thrashed around for ages. I made this note at the time, I suppose it might help someone:

how I fixed maven dependency for org.apache.commons.io.IOUtils eclipse maven dependency class not found → I imported commons-io-2.6.jar from /home/john/.m2/repository/commons-io/commons-io/2.6/commons-io-2.6.jar to WebContent/WEB-INF/lib !

whole thing not very satisfactory though.

JohnColeman avatar Feb 08 '19 10:02 JohnColeman