Jar file doesn't work on the web server - java

I have an Jar file that is working perfectly fine on my Mac using console:
MacBook-Pro-Pavel:PDFparser pavelpigalev$ java -jar PDFparser.jar
Usage: java PDFparser <input-pdf> -p1 <password> -c1 -i0 -s1
-p1 : PDF password
-c1 : write JSON to console
-i0 : don't extract images
-s1 : take page screenshots [WARNING: currently in beta]
MacBook-Pro-Pavel:PDFparser pavelpigalev$ java -jar PDFparser.jar f5.pdf
MacBook-Pro-Pavel:PDFparser pavelpigalev$
It creates a folder and puts out images that I need in that folder.
But if I use it on the web server (also using console) it gives me this error:
[root#somesite.com pdfparser]$ ls
ffive.pdf lib PDFparser.jar README.TXT
[root#somesite.com pdfparser]$ java -jar "PDFparser.jar"
Usage: java PDFparser <input-pdf> -p1 <password> -c1 -i0 -s1
-p1 : PDF password
-c1 : write JSON to console
-i0 : don't extract images
-s1 : take page screenshots [WARNING: currently in beta]
[root#somesite.com pdfparser]$ java -jar "PDFparser.jar" ffive.pdf
Exception in thread "main" java.lang.ClassNotFoundException: javax.vecmath.Vector2d not found in gnu.gcj.runtime.SystemClassLoader{urls=[file:PDFparser.jar], parent=gnu.gcj.runtime.ExtensionClassLoader{urls=[], parent=null}}
at java.net.URLClassLoader.findClass(libgcj.so.10)
at java.lang.ClassLoader.loadClass(libgcj.so.10)
at java.lang.ClassLoader.loadClass(libgcj.so.10)
at java.lang.reflect.Field.getType(libgcj.so.10)
at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.excludeField(ReflectiveTypeAdapterFactory.java:56)
at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.getBoundFields(ReflectiveTypeAdapterFactory.java:111)
at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.create(ReflectiveTypeAdapterFactory.java:72)
at com.google.gson.Gson.getAdapter(Gson.java:353)
at com.google.gson.internal.bind.CollectionTypeAdapterFactory.create(CollectionTypeAdapterFactory.java:52)
at com.google.gson.Gson.getAdapter(Gson.java:353)
at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$1.<init>(ReflectiveTypeAdapterFactory.java:82)
at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.createBoundField(ReflectiveTypeAdapterFactory.java:81)
at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.getBoundFields(ReflectiveTypeAdapterFactory.java:118)
at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.create(ReflectiveTypeAdapterFactory.java:72)
at com.google.gson.Gson.getAdapter(Gson.java:353)
at com.google.gson.Gson.toJson(Gson.java:578)
at com.google.gson.Gson.toJson(Gson.java:565)
at com.google.gson.Gson.toJson(Gson.java:520)
at com.google.gson.Gson.toJson(Gson.java:500)
at pdfparser.PDFparser.main(PDFparser.java:163)
I didn't make this Jar file, I don't really know much about Java. I work with PHP and I really need this program working well on server. Can someone help me with that?

Place vechmath .jar in your class path
Or - Add your supporting .jars to the classpath
export CLASSPATH=$CLASSPATH:/path/to/vecmath.jar
Or - Supply at the Runtime
java -cp vecmath-xxx.jar -jar Yourjar.jar
Importance of Classpath

You're not using the same JVM that the one in your macbook. You're using GNU JVM as seen in not found in gnu.gcj.runtime.SystemClassLoader
Try a java -version to confim that and then change your JVM

Try to find vecmath-1.3.1.jar file on you Mac and place it in the same dir as PDFparser.jar is located. Try to run. If no success then try to run as follow:
java -cp vecmath-1.3.1.jar -jar "PDFparser.jar"

Related

How to access Java dependency on command line?

I have a moderately old, small Java application which has an option to read and export PDF files using the Apache PDFBox library (hereunder, "pdfbox-app.jar"). All the files, including this resource, are stored in a single flat folder.
This works fine when called from a JAR file:
D:\Prog\!GitHub\Arena>java -jar Athena.jar NPCGenerator -p
OED NPC Generator
-----------------
Writing Gwenllian-ElfFtr1Wiz1.pdf
It similarly works fine when run from my IDE (jGrasp).
But it fails when called from the command line, outside of its JAR:
D:\Prog\!GitHub\Arena>java NPCGenerator -p
OED NPC Generator
-----------------
Writing Eoin-HalflingFtr1.pdf
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/pdfbox/pdmodel/PDDoc
ument
at CharacterPDF.writePDF(CharacterPDF.java:49)
at NPCGenerator.printToPDF(NPCGenerator.java:294)
at NPCGenerator.makeAllNPCs(NPCGenerator.java:270)
at NPCGenerator.main(NPCGenerator.java:308)
Caused by: java.lang.ClassNotFoundException: org.apache.pdfbox.pdmodel.PDDocument
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.j
ava:641)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoader
s.java:188)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:520)
... 4 more
What should I be doing to run this on the command line outside of its own JAR?
You should put the pdfbox jar, and any other dependencies, on the classpath:
java -classpath .;pdfbox-app.jar NPCGenerator -p
Without that, Java doesn't know where to look for org/apache/pdfbox classes. It looks for .class files relative to the default classpath (which is just ., the current directory), but does not look inside jars.

Cannot open sever.jar file

So I was trying to make a 1.17.1 minecraft server on my mac. I couldn't open my 1.17.1_server.jar with Java 8 so I download Java 16.0.2.
Unfortunately, everytime I was opening the 1.17.1_server.jar file, I got
"The Java JAR file "1.17._server.jar" could not be launched." .
I first thought that it was because the file was launch by Java 8 instead of 16.
So I went into the terminal and run :<path to java> -jar 1.17.1_server.jar
I then got this : Error: Unable to access jarfile 1.17.1_server.jar
Finally i tried to put the path of the jar file in the command...
So I've run : path to java -jar path to server
and got this :
[main/ERROR]: Failed to load properties from file: server.properties
[15:57:35] [main/WARN]: Failed to load eula.txt
[15:57:35] [main/INFO]: You need to agree to the EULA in order to run the server. Go to eula.txt for more info.
So why I have to agreed Eula if i've never launched it ? Does it think that he already been launched ?
As stated in the error message
[15:57:35] [main/INFO]: You need to agree to the EULA in order to run the server. Go to eula.txt for more info.
You have to open the file and check yes
Okay find the solution: my eula and server properties file were in my user folder dk why (never moved them so...)

Malt Parser throwing class not found exception

I'm trying to parse sentence with Malt Parser in NLTK. When I did raw_parse(sent) it gave an error with exit code 1. I executed java command on terminal and it gives class Not Found exception, I don't understand what is wrong now?
java -Xmx1024m -jar /usr/local/bin/malt.jar -w /home/abc/maltparser-1.7.2 -c engmalt.linear-1.7 -i /home/abc/maltparser-1.7.2/malt_input.conllrPZgwc -o /home/abc/maltparser-1.7.2/malt_output.conllDMSKpg -m parse
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/log4j/Layout
Your working directory is not correctly set. Log4j is a package used by Malt Parser (see: maltparser-1.7.2/lib/log4j.jar). Which is used for logging logically.
In order to run maltparser in NLTK, the working directory should be set to this folder (in your case: /home/abc/maltparser-1.7.2).
So, step one is getting the latest NLTK from git:
git clone https://github.com/nltk/nltk.git
Install NLTK:
sudo python setup.py install
To run Malt Parser using NLTK try this code example:
import os
import nltk
os.environ['MALTPARSERHOME']="/home/abc/maltparser-1.7.2"
verbose = False
maltParser = nltk.parse.malt.MaltParser(working_dir="/home/abc/maltparser-1.7.2",
mco="engmalt.linear-1.7",
additional_java_args=['-Xmx512m'])
print(maltParser.raw_parse('This is a test sentence', verbose=verbose).tree().pprint())
As you may notice I'm using the pre-learned mco file (engmalt.linear-1.7), which can be downloaded from here:
http://www.maltparser.org/mco/english_parser/engmalt.html
Move this mco file to: /home/abc/maltparser-1.7.2 directory.
Finally NLTK only except malt.jar. So create a copy (or rename):
cp maltparser-1.7.2.jar malt.jar
Which can still be located in your /home/abc/maltparser-1.7.2.jar directory.
Hopefully you'll get it running!

How to use Compass through JRuby, for embedding in my soft'?

I've to "compile" compass files dynamically in my java soft'. So, following explications found on stackoverflow, I've done these steps :
Get JRuby (1.7.3), configure PATH to jruby.jar and binaries (gem, rake ...) and learn to launch ruby script from Java
Get compass and dependancies gems into a local directory, using following command line
gem install -i ./compass compass
=> So I get a directory ./compass/ containing bin, cache,doc, gems & specifications directories.
Put gems in a jar using following command line (think to use a jar name which is not the same as the gems, to avoid JRuby "require" the jar instead of the gems)
jar cf compass-lib.jar -C compass .
Write a test script test.rb in local directory to test my jar. It contains :
require 'compass'
Compass.add_configuration(
{
:project_path => '.',
:sass_path => 'styles/scss',
:css_path => 'styles/css'
},
'custom' # A name for the configuration, can be anything you want
)
Compass.compiler.compile('test.scss', 'test.css')
Execute this script with JRuby, with following command line :
jruby -I . -rcompass-lib.jar test.rb
And get this error ...
Unable to load Sass. Please install it with one of the following commands:
gem install sass --pre
LoadError: no such file to load -- jar:file:C:/jruby-1.7.3/lib/jruby.jar!/gems/s
ass-3.2.8/lib/sass/../sass
require at org/jruby/RubyKernel.java:1027
require at c:/jruby-1.7.3/lib/ruby/shared/rubygems/custom_require.rb:36
(root) at jar:file:C:/jruby-1.7.3/lib/jruby.jar!/gems/sass-3.2.8/lib/sass/ver
sion.rb:5
require at org/jruby/RubyKernel.java:1027
(root) at c:/jruby-1.7.3/lib/ruby/shared/rubygems/custom_require.rb:1
require at c:/jruby-1.7.3/lib/ruby/shared/rubygems/custom_require.rb:36
require at org/jruby/RubyKernel.java:1027
(root) at jar:file:C:/jruby-1.7.3/lib/jruby.jar!/gems/sass-3.2.8/lib/sass.rb:
9
(root) at c:/jruby-1.7.3/lib/ruby/shared/rubygems/custom_require.rb:1
require at org/jruby/RubyKernel.java:1027
require at c:/jruby-1.7.3/lib/ruby/shared/rubygems/custom_require.rb:60
(root) at jar:file:C:/jruby-1.7.3/lib/jruby.jar!/gems/compass-0.12.2/lib/comp
ass/dependencies.rb:6
each at org/jruby/RubyArray.java:1613
(root) at c:/jruby-1.7.3/lib/ruby/shared/rubygems/custom_require.rb:1
require at org/jruby/RubyKernel.java:1027
require at c:/jruby-1.7.3/lib/ruby/shared/rubygems/custom_require.rb:36
(root) at test.rb:1
An idea of the problem and, maybe, of solution ? ;) Thanks by advance.
[UPDATE #1]
After Jörg W Mittag obvious suggestion, the error disapear. Thanks ;) Now, it just don't find the scss file, so it's a "normal problem" ;)
[UPDATE #2]
Having used compass with success in IRB, it's time to transpose the test through Java. So, I wrote some lines in Java to execute my ruby script, using only absolute path to avoid problems in a first time.
InputStream myFile = ISRessources.getFile("C:/Path/To/My/test.rb");
new ScriptingContainer().runScriptlet(myFile, "test.rb");
But ... how to "load" my compass-lib.jar ? What's the equivalent of the -r in JRuby ? I've tried to includ gems into jruby.jar, to add compass-lib.jar in externals jars in java build path, but both don't work, I still have :
LoadError: no such file to load -- compass
require at org/jruby/RubyKernel.java:1027
(root) at test.rb:1
Any idea ?
The error message says:
Unable to load Sass. Please install it with one of the following commands:
gem install sass --pre

Executing Java program (NCBO Extraction Tool) from Windows command prompt not working ... User Guide uses Linux syntax

I'm trying to run a Java command line program from the Windows command prompt to extract and generate an ontology file from the BioPortal (http://bioportal.bioontology.org). It appears that it can't find the class, but perhaps my CLASSPATH parameter syntax is incorrect. Reference for setup (NCBO user guide and NCBO extraction tool zip file) can be found at the bottom of my question. The instructions are based on Linux syntax, but I'm running this in Windows.
Linux command (from user guide):
java -classpath endorsed_lib/*:genlib/i2b2Common-core.jar:lib/commons/*:lib/log4j/*:lib/jdbc/*:lib/spring/*:* edu.harvard.i2b2.ncbo.extraction.NCBOOntologyExtractAll -ont {5 digit ontology id} -apikey {API key from http://bioportal.bioontology.org/account} -outputFileName {output file path}
The Linux -classpath parameter includes these:
endorsed_lib/*
genlib/i2b2Common-core.jar or genlib/* (only 1 jar file)
lib/commons/*
lib/log4j/*
lib/jdbc/*
lib/spring/*
*
Windows command (that doesn't work):
java -cp ".\endorsed_lib;.\genlib;.\lib\commons;.\lib\jdbc;.\lib\log4j;.\lib\spring;." edu.harvard.i2b2.ncbo.extraction.NCBOOntologyExtractAll -ont 47178 -apikey 68775b88-c12f-472c-9192-71f9b282309c -outputFileName 47178_stagingFile.txt
Error from Windows command prompt:
Error: Could not find or load main class edu.harvard.i2b2.ncbo.extraction.NCBOOntologyExtractAll
The Windows -cp (CLASSPATH) parameter includes these paths:
\NCBOExtractionTools_1.1\Release_1_1\endorsed_lib\;
\NCBOExtractionTools_1.1\Release_1_1\genlib\;
\NCBOExtractionTools_1.1\Release_1_1\lib\commons\;
\NCBOExtractionTools_1.1\Release_1_1\lib\jdbc\;
\NCBOExtractionTools_1.1\Release_1_1\lib\log4j\;
\NCBOExtractionTools_1.1\Release_1_1\lib\spring\;
\NCBOExtractionTools_1.1\Release_1_1\;
=================
Guide:
https://community.i2b2.org/wiki/download/attachments/5670011/NCBO_Extraction_Users_Guide_1-1.pdf?version=2&modificationDate=1344357357000
Instructions start on page 8 of 16. I'm on page 9.
In the user guide, it references an NCBO utility. That can be downloaded here:
https://www.i2b2.org/software/download.html?d=310
click the blue hyperlink labeled "file download" or click link below (link as of 1/4/2013) > then click "I ACCEPT" > save file (NCBOExtractionTools_1.1.zip) to your local machine > extract zip file
Here is a list of the files extracted from the i2b2 NCBO utility so you can see what jar files we have available:
\NCBOExtractionTools_1.1\Release_1_1\endorsed_lib
\NCBOExtractionTools_1.1\Release_1_1\ExtractionApplicationContext.xml
\NCBOExtractionTools_1.1\Release_1_1\FileList.txt
\NCBOExtractionTools_1.1\Release_1_1\genlib
\NCBOExtractionTools_1.1\Release_1_1\hierarchy.log
\NCBOExtractionTools_1.1\Release_1_1\i2b2_license_2.1-1159.txt
\NCBOExtractionTools_1.1\Release_1_1\lib
\NCBOExtractionTools_1.1\Release_1_1\log4j.properties
\NCBOExtractionTools_1.1\Release_1_1\NCBOExtraction_1.1.jar
\NCBOExtractionTools_1.1\Release_1_1\STAGING_FILES
\NCBOExtractionTools_1.1\Release_1_1\endorsed_lib\jaxb-api.jar
\NCBOExtractionTools_1.1\Release_1_1\endorsed_lib\jaxb-LICENSE.txt
\NCBOExtractionTools_1.1\Release_1_1\endorsed_lib\stax-api-1.0.1.jar
\NCBOExtractionTools_1.1\Release_1_1\endorsed_lib\stax-api-LICENSE.txt
\NCBOExtractionTools_1.1\Release_1_1\endorsed_lib\wstx-asl-3.0.1.jar
\NCBOExtractionTools_1.1\Release_1_1\endorsed_lib\wstx-LICENSE.txt
\NCBOExtractionTools_1.1\Release_1_1\genlib\i2b2Common-core.jar
\NCBOExtractionTools_1.1\Release_1_1\lib\commons
\NCBOExtractionTools_1.1\Release_1_1\lib\jdbc
\NCBOExtractionTools_1.1\Release_1_1\lib\log4j
\NCBOExtractionTools_1.1\Release_1_1\lib\spring
\NCBOExtractionTools_1.1\Release_1_1\lib\commons\apache-2.0license.txt
\NCBOExtractionTools_1.1\Release_1_1\lib\commons\commons-codec-1.3.jar
\NCBOExtractionTools_1.1\Release_1_1\lib\commons\commons-collections-2.1.1.jar
\NCBOExtractionTools_1.1\Release_1_1\lib\commons\commons-dbcp-1.2.2.jar
\NCBOExtractionTools_1.1\Release_1_1\lib\commons\commons-exec-1.0.jar
\NCBOExtractionTools_1.1\Release_1_1\lib\commons\commons-httpclient-3.0.jar
\NCBOExtractionTools_1.1\Release_1_1\lib\commons\commons-logging-1.0.4.jar
\NCBOExtractionTools_1.1\Release_1_1\lib\commons\commons-pool-1.3.jar
\NCBOExtractionTools_1.1\Release_1_1\lib\jdbc\ojdbc14.jar
\NCBOExtractionTools_1.1\Release_1_1\lib\jdbc\sqlserver2005
\NCBOExtractionTools_1.1\Release_1_1\lib\jdbc\sqlserver_jTDS
\NCBOExtractionTools_1.1\Release_1_1\lib\jdbc\sqlserver2005\sqljdbc.jar
\NCBOExtractionTools_1.1\Release_1_1\lib\jdbc\sqlserver2005\sqlserver_licence.rtf
\NCBOExtractionTools_1.1\Release_1_1\lib\jdbc\sqlserver_jTDS\jtds-1.2.2.jar
\NCBOExtractionTools_1.1\Release_1_1\lib\jdbc\sqlserver_jTDS\LICENSE
\NCBOExtractionTools_1.1\Release_1_1\lib\log4j\log4j-1.2.8.jar
\NCBOExtractionTools_1.1\Release_1_1\lib\log4j\log4j-LICENSE.txt
\NCBOExtractionTools_1.1\Release_1_1\lib\spring\apachelicence-2.0.txt
\NCBOExtractionTools_1.1\Release_1_1\lib\spring\spring-2.0.jar
This worked per #Brian's comment:
java -cp ".\endorsed_lib\*;.\genlib\*;.\lib\commons\*;.\lib\jdbc\*;.\lib\log4j\*;.\lib\spring\*;.\*" edu.harvard.i2b2.ncbo.extraction.NCBOOntologyExtractAll -ont 47178 -apikey {key} -outputFileName 47178_stagingFile.txt

Categories