Class-Path line too long - java

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

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.

cobertura-instrument.sh fails to instrument jar file with java.lang.NoClassDefFoundError: net.sourceforge.cobertura.instrument.InstrumentMain

I'm trying to instrument jar file (from Spacewalk project) so I can measure code coverage of mine testing, but it is failing:
# /opt/cobertura-2.1.1/cobertura-instrument.sh --datafile /tmp/out /usr/share/rhn/lib/rhn.jar
Exception in thread "main" java.lang.NoClassDefFoundError: net.sourceforge.cobertura.instrument.InstrumentMain
Caused by: java.lang.ClassNotFoundException: net.sourceforge.cobertura.instrument.InstrumentMain
at java.net.URLClassLoader.findClass(URLClassLoader.java:432)
at java.lang.ClassLoader.loadClass(ClassLoader.java:676)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:358)
at java.lang.ClassLoader.loadClass(ClassLoader.java:642)
Could not find the main class: net.sourceforge.cobertura.instrument.InstrumentMain. Program will exit.
I have tried to provide one random class (in the ideal state I want to instrument all of them) from that jar as well, but with same result:
# jar tf rhn.jar | tail
org/cobbler/CobblerConnection.class
[...]
# /opt/cobertura-2.1.1/cobertura-instrument.sh --datafile /tmp/out /usr/share/rhn/lib/rhn.jar org.cobbler.CobblerConnection
I'm pretty sure I'm just missing something what it is trying to tell me.
I'm using cobertura-2.1.1 downloaded from SourceForge and extracted into /opt, running on Red Hat Enterprise Linux 6.
OK, this was simple:
# dos2unix /opt/cobertura-2.1.1/cobertura-instrument.sh
also it is missing bash shebang (#!/bin/bash), so you might need to add it to the beginning of the file (I do not know why it worked for me even without that).

Amazon Web Services Java classpath

I am trying to run an application that reads and writes to the amazon dynamo DB. I downloaded the Eclipse toolkit and AWS SDK and if I run the application from my local PC it works perfectly. Next, I exported it to a jar file and uploaded it to my EC2 instance. However, when I run it there I get an error.
/home/apps/java/database/bin$ java -jar myJar.jar
Exception in thread "main" java.lang.NoClassDefFoundError: com/amazonaws/auth/AW SCredentials
Caused by: java.lang.ClassNotFoundException: com.amazonaws.auth.AWSCredentials
at java.net.URLClassLoader$1.run(URLClassLoader.java:217)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:205)
at java.lang.ClassLoader.loadClass(ClassLoader.java:321)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:294)
at java.lang.ClassLoader.loadClass(ClassLoader.java:266)
Could not find the main class: DynamoDB. Program will exit.
I assume it has to do with the classpath, but in /home/ubuntu/.bashrc I have set it as such:
CLASSPATH="./:/home/apps/java/database/bin/*:/home/apps/java/database/bin/aws-java-sdk-1.3.12.jar"
export CLASSPATH
/home/apps/java/database/bin contains all the .jar files that are in the AWS SDK:
aspectjrt.jar
aspectjweaver.jar
aws-java-sdk-1.3.12.jar
aws-java-sdk-1.3.12-javadoc.jar
aws-java-sdk-1.3.12-sources.jar
aws-java-sdk-flow-build-tools-1.3.12.jar
commons-codec-1.3.jar
commons-logging-1.1.1.jar
freemarker-2.3.18.jar
httpclient-4.1.1.jar
httpcore-4.1.jar
jackson-core-asl-1.8.7.jar
jackson-mapper-asl-1.8.7.jar
mail-1.4.3.jar
myJar.jar
spring-beans-3.0.7.jar
spring-context-3.0.7.jar
spring-core-3.0.7.jar
stax-1.2.0.jar
stax-api-1.0.1.jar
What am I missing?? I have been looking at this for a day and a half. Thank you in advance!!
The classpath entry of "/directory/*" may be messing things up. Classpaths are separated with colons, but asterisk expansion gives spaces. Try this little shell script to start it.
#!/bin/sh
JAVA_OPTS="-Xms256M -Xmx4G"
CP=`find /home/apps/java/database/bin/*jar -exec echo -n "{}:" \;`
java -cp ${CP%?} -jar yourjar.jar
A couple of notes:
the JAVA_OPTS is only there as a reminder that you may need more memory than the default.
the crazy syntax for CP on the final line strips the last character, since the "find" line is leaving a colon on the end.
You may want to include your jar and launch the correct class if it isn't an executable jar.
Hope this helps!
This list of libs works for me
aws-java-sdk-1.11.285-javadoc.jar
aws-java-sdk-1.11.285-sources.jar
aws-java-sdk-1.11.285.jar
aws-java-sdk.jar
aspectjrt-1.8.2.jar
aspectjweaver.jar
aws-swf-build-tools-1.1.jar
commons-codec-1.9.jar
commons-logging-1.1.3.jar
freemarker-2.3.9.jar
httpclient-4.5.2.jar
httpcore-4.4.4.jar
ion-java-1.0.2.jar
jackson-annotations-2.6.0.jarÃ…
jackson-core-2.6.7.jar
jackson-databind-2.6.7.1.jar
jackson-dataformat-cbor-2.6.7.jar
javax.mail-api-1.4.6.jar
jmespath-java-1.11.285.jar
joda-time-2.8.1.jar
netty-buffer-4.1.17.Final.jar
netty-codec-4.1.17.Final.jar
netty-codec-http-4.1.17.Final.jar
netty-common-4.1.17.Final.jar
netty-handler-4.1.17.Final.jar
netty-resolver-4.1.17.Final.jar
netty-transport-4.1.17.Final.jar
spring-beans-3.0.7.RELEASE.jar
spring-context-3.0.7.RELEASE.jar
spring-core-3.0.7.RELEASE.jar
spring-test-3.0.7.RELEASE.jar

Problem running pdf2text jar. File not found exception

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..

Javassist failure in hibernate: invalid constant type: 60

I'm creating a cli tool to manage an existing application. Both the application and the tests build fine and run fine but despite that I receive a javassist failure when running my cli tool that exists within the jar:
INFO: Bytecode provider name : javassist
...
INFO: Hibernate EntityManager 3.5.1-Final
Exception in thread "main" javax.persistence.PersistenceException: Unable to configure EntityManagerFactory
at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:371)
at org.hibernate.ejb.HibernatePersistence.createEntityManagerFactory(HibernatePersistence.java:55)
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:48)
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:32)
...
at com.sophware.flexipol.admin.AdminTool.<init>(AdminTool.java:40)
at com.sophware.flexipol.admin.AdminTool.main(AdminTool.java:69)
Caused by: java.lang.RuntimeException: Error while reading file:flexipol-jar-with-dependencies.jar
at org.hibernate.ejb.packaging.NativeScanner.getClassesInJar(NativeScanner.java:131)
at org.hibernate.ejb.Ejb3Configuration.addScannedEntries(Ejb3Configuration.java:467)
at org.hibernate.ejb.Ejb3Configuration.addMetadataFromScan(Ejb3Configuration.java:457)
at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:347)
... 11 more
Caused by: java.io.IOException: invalid constant type: 60
at javassist.bytecode.ConstPool.readOne(ConstPool.java:1027)
at javassist.bytecode.ConstPool.read(ConstPool.java:970)
at javassist.bytecode.ConstPool.<init>(ConstPool.java:127)
at javassist.bytecode.ClassFile.read(ClassFile.java:693)
at javassist.bytecode.ClassFile.<init>(ClassFile.java:85)
at org.hibernate.ejb.packaging.AbstractJarVisitor.checkAnnotationMatching(AbstractJarVisitor.java:243)
at org.hibernate.ejb.packaging.AbstractJarVisitor.executeJavaElementFilter(AbstractJarVisitor.java:209)
at org.hibernate.ejb.packaging.AbstractJarVisitor.addElement(AbstractJarVisitor.java:170)
at org.hibernate.ejb.packaging.FileZippedJarVisitor.doProcessElements(FileZippedJarVisitor.java:119)
at org.hibernate.ejb.packaging.AbstractJarVisitor.getMatchingEntries(AbstractJarVisitor.java:146)
at org.hibernate.ejb.packaging.NativeScanner.getClassesInJar(NativeScanner.java:128)
... 14 more
Since I know the jar is fine as the unit and integration tests run against it, I thought it might be a problem with javassist, so I tried cglib. The bytecode provider then shows as cglib but I still get the exact same stack trace with javassist present in it.
cglib is definitely in the classpath:
$ unzip -l flexipol-jar-with-dependencies.jar | grep cglib | wc -l
383
I've tried with both hibernate 3.4 and 3.5 and get the exact same error. Is this a problem with javassist?
UPDATE: I can run the application successfully within Eclipse (Right click->Run As->Java Application), but using the maven-generated jar-with-dependencies fails. I presume the difference is that with Eclipse javassist isn't inspecting the containing jar, rather, it's inspecting all of the class files (and perhaps a few dependent 3rd-party jars).
The problem is ultimately caused by an invalid class in icu4j-2.6.1 as can be seen in this post. Specifically, this file is invalid:
com/ibm/icu/impl/data/LocaleElements_zh__PINYIN.class
Here's a simple way to identify a corrupt file:
for x in PATH_TO_EXTRACTED_JAR/**/*.class; do
java -cp PATH_TO/javassist.jar javassist.tools.Dump $x >/dev/null 2>&1 || echo "$x is invalid"
done
This file is being included by indirectly by maven through its transitive dependencies which is why I didn't recognize that page as referencing the error and a file contained within the jar as being the culprit and cause of the problem. Here's how it ended up included in my jar-with-dependencies bundle:
jaxen-1.1.1 -> xom-1.0 -> icu4j-2.6.1
After adding the following exclusion to the jaxen dependency, everything worked correctly for me (but be careful if you need its localization pieces):
<exclusions>
<exclusion>
<groupId>com.ibm.icu</groupId>
<artifactId>icu4j</artifactId>
</exclusion>
</exclusions>
Another option would be to remove the offending file(s) from the jar file:
#!/bin/sh
shopt -s extglob
shopt -s globstar
for x in **/*.jar ; do
zip -d $x 'com/ibm/icu/impl/data/*_zh*' >/dev/null 2>&1 && echo "Removed corrupted files from $x"
done

Categories