Problem running pdf2text jar. File not found exception - java

I have been trying to run the pdf2text tool provided by apache. I initially got the 'failed to load main-class manifest attribute' error. So I modified the manifest file in the jar to include the Main-Class attribute. Wrote it as -
Main-Class: org.apache.pdfbox.ExtractText
But after this, I am getting the exception -
Exception in thread "main" java.io.FileNotFoundException:
org.apache.pdfbox.ExtractText (No such file or directory)
at java.io.FileInputStream.open(Native Method)
at java.io.FileInputStream.<init>(FileInputStream.java:106)
at java.io.FileInputStream.<init>(FileInputStream.java:66)
at org.apache.pdfbox.pdmodel.PDDocument.load(PDDocument.java:978)
at org.apache.pdfbox.ExtractText.startExtraction(ExtractText.java:196)
at org.apache.pdfbox.ExtractText.main(ExtractText.java:76)
What can possibly be the mistake here?

try to switch to this entry point (Main-class):
org.apache.pdfbox.PDFBox
edit: this setup should also work (if you want to extract text)
java -cp ./pdfbox-1.6.0.jar org.apache.pdfbox.PDFBox ExtractText some.pdf
note that you need to add Apache's logging package and so on to your CLASSPATH variable, unless you set that at the command line as well..

Related

How do I build my maven project that includes my environment variables

please I need help. I'm trying to package my maven build and also include environment variables but my program cannot find the .env file. How can I resolve this issue? I have been using eclipse, but I don't know where I can configure the path to the .env file. I used io.github.cdimascio to read environment variables. The program works fine on my IDE. The trouble starts when I run the program outside the IDE. What should I do?
Exception in thread "Thread-1" Exception in thread "Thread-0" java.lang.ExceptionInInitializerError
at com.arcalitegames.Main$2.run(Main.java:29)
at java.lang.Thread.run(Unknown Source)
Caused by: io.github.cdimascio.dotenv.DotEnvException: Could not find ./.env on the classpath
at io.github.cdimascio.dotenv.internal.ClasspathHelper.loadFileFromClasspath(ClassPathHelper.kt:37)
at io.github.cdimascio.dotenv.internal.DotenvReader.read(DotenvReader.kt:36)
at io.github.cdimascio.dotenv.internal.DotenvParser.parse(DotenvParser.kt:26)
at io.github.cdimascio.dotenv.DotenvBuilder.load(Dotenv.kt:119)
at com.arcalitegames.connector.Devs.getDotenv(Devs.java:10)
at com.arcalitegames.connector.Connector.<clinit>(Connector.java:14)
... 2 more
I had this same problem when I tried to deploy my program to Glassfish. You need to specify a location on the file system like ~ and place your .env file there.
Here is an example on how to do this:
Dotenv env = Dotenv.configure().directory(System.getProperty("user.home")).load();
Dotenv should now be able to find the file if you've placed it at ~/.env.

Class-Path line too long

I developed application client by Java and it was running normally by Glassfish ..
But after moving to Wildfly .. i'm facing this error :
Caused by: org.jboss.as.server.deployment.DeploymentUnitProcessingException: WFLYSRV0161: Failed to get manifest for deployment \"/content/Application.jar\"
Caused by: java.io.IOException: line too long"}}
I expect the error is because of the long line of Class-Path in Manifest.mf file.
Class-Path: ../lib/jaybird-2.1.6.jar ../lib/rtfparserkit-1.6.0.jar ../lib/jug-lgpl-2.0.0.jar ../lib/mysql-connector-java-5.1.37-bin.jar ../lib/trilead-ssh2-build213.jar ../lib/wsdl4j-1.6.2.jar ../lib/wsdl4j-qname-1.6.1.jar ../lib/xmlbeans-2.6.0.jar ../lib/poi-3.11-20141221.jar ../lib/poi-ooxml-3.11-20141221.jar ../lib/poi-ooxml-schemas-3.11-20141221.jar ../lib/jersey-apache-client-1.16.jar ../lib/jersey-bundle-1.16.jar ../lib/jersey-core-1.16.jar ../lib/jersey-client-1.16.jar ../lib/jackson-core-asl-1.9.13.jar ../lib/jackson-mapper-asl-1.9.2.jar ../lib/js-14.jar ../lib/drools-core-5.0.1.jar ../lib/activemq-all-5.10.0.jar ../lib/json-simple-1.1.1.jar ../lib/commons-io-2.4.jar ../lib/javassist.jar ../lib/scannotation-1.0.2.jar ../lib/j-text-utils-0.3.3.jar ../lib/commons-lang-2.6.jar ../lib/commons-net-3.3.jar ../lib/opencsv-2.4.jar ../lib/gson-2.2.4.jar ../lib/httpclient-4.3.5.jar ../lib/commons-vfs-20100924-pentaho.jar ../lib/log4j-1.2.17.jar ../lib/commons-logging-1.1.3.jar ../lib/spring-core-3.1.4.RELEASE.jar ../lib/commons-digester-2.1.jar ../lib/commons-beanutils-1.9.2.jar ../lib/ognl-2.7.3.jar ../lib/jxl-2.6.3.jar ../lib/metastore-5.0.1.jar ../lib/edtftpj-2.1.0.jar ../lib/kettle5-log4j-plugin-5.1.0.0-752.jar ../lib/kettle-db-4.4.0-stable.jar ../lib/janino-2.5.16.jar ../lib/commons-compiler-2.7.8.jar
Is there any way else to load all jars inside a folder without typing this long line ? or How to avoid this error message ?
The manifest-file must not contain lines longer than 72 bytes.
You have to break the line after exact 72 bytes.
Class-Path: ../lib/jaybird-2.1.6.jar ../lib/rtfparserkit-1.6.0.jar ../l
ib/jug-lgpl-2.0.0.jar ../lib/mysql-connector-java-5.1.37-bin.jar ../li
b/trilead-ssh2-build213.jar ../lib/wsdl4j-1.6.2.jar ../lib/wsdl4j-qnam
e-1.6.1.jar ...
Look for Line length in the specification:
http://docs.oracle.com/javase/8/docs/technotes/guides/jar/jar.html#JAR_Manifest
Alternative: Do not use the classpath in Manifest. Instead start with commandline argument:
java -cp lib/* mainclass
Make an uber jar containing all the others.
FWIW: After some time looking for a solution to this problem, and I finally found something that works. I tested it successfully on both Windows 10 with java 1.8.0_241 and on Linux Mint 19.1 with java 1.8.0_241
Notice that each classpath entry after the "Class-path:" line is indented 2 spaces, although that might not be required. Here's my MANIFEST.MF file:
Manifest-Version: 1.0
Scala-Compiler-Version: 2.12.10
Main-Class: Main
Class-Path: /opt/uejlib2.12/vastblue_2.12.jar
/opt/uejlib2.12/apps_2.12.jar
/opt/uejlib2.12/scala-reflect.jar
/opt/uejlib2.12/scala-library.jar
/opt/uejlib2.12/better-files_2.12-3.8.0.jar
/opt/uejlib2.12/scala-collection-compat_2.12-2.1.3.jar
/opt/uejlib2.12/chronoscala_2.12-0.3.2.jar
/opt/uejlib2.12/sfm-csv-8.2.1.jar
/opt/uejlib2.12/sfm-map-8.2.1.jar
/opt/uejlib2.12/lightning-csv-8.2.1.jar
/opt/uejlib2.12/sfm-tuples-8.2.1.jar
/opt/uejlib2.12/sfm-reflect-8.2.1.jar
/opt/uejlib2.12/sfm-converter-8.2.1.jar
/opt/uejlib2.12/sfm-util-8.2.1.jar

The process cannot access the file because it is being used by another process (java)

I am trying to replace a jar file after it's been added to the class path programmatically.
When I try to replace a jar that's been loaded, it gives me the subject error.
I'm using Windows 8 , and JDK 7.
Any suggestions or workaround is highly appreciated.
error line
Files.copy(Paths.get(sourcePath), Paths.get(desPath), StandardCopyOption.REPLACE_EXISTING);
exception
java.nio.file.NoSuchFileException: D:\test\test.jar
> D:\project\plugins\test.jar
at sun.nio.fs.WindowsException.translateToIOException(WindowsException.java:79)
at sun.nio.fs.WindowsException.rethrowAsIOException(WindowsException.java:97)
at sun.nio.fs.WindowsFileCopy.copy(WindowsFileCopy.java:205)
at sun.nio.fs.WindowsFileSystemProvider.copy(WindowsFileSystemProvider.java:278)
at java.nio.file.Files.copy(Files.java:1225)
at org.test.Test.apply(Test.java:89)

ClassNotFoundException while running jar

I am getting ClassNotFoundException when I try to run a jar whith below command:
java -jar MyJar.jar
I created the jar with eclipe. MyJar depends of a couple of other jars. I saw in ecplise that all these other jars are there in the classpath.
I also added these jars to the classpath in Unix using export classpath. But still I get the ClassNotFoundException.
Exception Stack Trace:
Exception in thread "main" java.lang.NoClassDefFoundError: org.apache.hadoop.conf.Configuration
at com.a.HDFSCopy.readURI(HDFSCopy.java:16)
at com.a.CopyMain.main(CopyMain.java:9)
Caused by: java.lang.ClassNotFoundException: org.apache.hadoop.conf.Configuration
at java.net.URLClassLoader.findClass(URLClassLoader.java:434)
at java.lang.ClassLoader.loadClass(ClassLoader.java:660)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:358)
at java.lang.ClassLoader.loadClass(ClassLoader.java:626)
... 2 more
Class Path Before:
/opt/ibm/biginsights/IHC/lib/biginsights-gpfs-1.1.1.jar:/opt/ibm/biginsights/IHC/hadoop-core.jar:
Class Path After (included the locations of the jars needed for dependencies) :
[biadmin#big-instght-15 ~]$ echo $CLASSPATH
/opt/ibm/biginsights/IHC/lib/biginsights-gpfs-1.1.1.jar:/opt/ibm/biginsights/IHC/hadoop-core.jar::/home/biadmin/hadoop_jars/commons-logging-1.1.1.jar:/home/biadmin/hadoop_jars/commons-configuration-1.8.jar:/home/biadmin/hadoop_jars/commons-lang-2.4.jar
But, I realized that if I open a new terminal and echo $CLASSPATH, it displays only the Class Path Before. It doesn't reflect the changes I made to the classpath. i.e. it doesn't show Class Path After.
How to fix this?
Thanks,
Mahalakshmi
What is the main class listed in MANIFEST.MF? If you unjar the jar, is it in the jarfile in the correct location?

ZMQ - libzmq.so.3: cannot open shared object file: No such file or directory

I'm trying to embed zeroMQ in my app, I followed this guideline to install ZMQ, so till here everything works fine.
I have this line of code in my app:
ZMQ.Context m_context = ZMQ.context(1);
but above line of code raise below exception:
Exception in thread "main" java.lang.UnsatisfiedLinkError: /tmp/libjzmq-812339378390536247.lib: libzmq.so.3: cannot open shared object file: No such file or directory
at java.lang.ClassLoader$NativeLibrary.load(Native Method)
at java.lang.ClassLoader.loadLibrary1(ClassLoader.java:1939)
at java.lang.ClassLoader.loadLibrary0(ClassLoader.java:1864)
at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1825)
at java.lang.Runtime.load0(Runtime.java:792)
at java.lang.System.load(System.java:1059)
at org.zeromq.EmbeddedLibraryTools.loadEmbeddedLibrary(EmbeddedLibraryTools.java:136)
at org.zeromq.EmbeddedLibraryTools.<clinit>(EmbeddedLibraryTools.java:22)
at org.zeromq.ZMQ.<clinit>(ZMQ.java:38)
at com.castaclip.verticals.Messenger.<init>(Messenger.java:125)
at com.castaclip.verticals.PushMessenger.<init>(PushMessenger.java:30)
at com.castaclip.verticals.pushserver.App.setup(App.java:60)
at com.castaclip.verticals.pushserver.App.main(App.java:41)
The error is exactly pointing to this line.
P.S: its a little bit difficult to fully explain this question.. if you have any question plz let me know. thanks.
If you've successfully built libzmq and jzmq in that order, I would run:
$ sudo ldconfig
to update the system library cache. Then I would check to see if LD_LIBRARY_PATH is defined like Raffian mentioned, or set your library path explicitly to something like:
$ java -Djava.library.path=/usr/lib:/usr/local/lib
Finally I tried to figure out the problem.
I was using zeromq-2.1.10 and this was part of the problem.
So I installed zeromq-3.2.3 from the source and problem resolved.
I encountered a mystifying instance of this message when I:
# java -Djava.library.path=/usr/hf/zmq/lib/ -cp '/usr/hf/lib/*:.' com.zmqtest.MA
Exception in thread "main"
java.lang.UnsatisfiedLinkError: /usr/hf/zmq/lib/libjzmq.so:
libzmq.so.3: cannot open shared object file: No such file or directory
which was fixed with a solution that makes no sense at all to me:
# LD_LIBRARY_PATH=/usr/hf/zmq/lib/ java -Djava.library.path=/usr/hf/zmq/lib/ -cp '/usr/hf/lib/*:.' com.zmqtest.MA
wierd.

Categories