I have one .jar file with only MANIFEST/MANIFEST.MF file inside it. I want to extend classpath in this file. Already googled on how to do this and found this:
Extract MANIFEST/MANIFEST.MF - jar xf myfile.jar
MANIFEST/MANIFEST.MF
Edit manifest file
Update it inside .jar - jar umf myfile.jar MANIFEST/MANIFEST.MF
The problem is that I get this error:
java.io.IOException: line too long
at java.util.jar.Attributes.read(Attributes.java:379)
at java.util.jar.Manifest.read(Manifest.java:199)
at java.util.jar.Manifest.<init>(Manifest.java:69)
at sun.tools.jar.Main.update(Main.java:652)
at sun.tools.jar.Main.run(Main.java:271)
at sun.tools.jar.Main.main(Main.java:1288)
Google says that maximum line length of manifest is 72 - OK. Tried not to edit extracted manifest file. When I try to import the same file I just extracted I get the same error. Maybe there's a tool that formats manifest files in order to make them "valid"?
Thank you in advance.
The update command should be:
jar umf MANIFEST/MANIFEST.MF myfile.jar
Use the below steps to avoid the issue
(1) use separate lines, to avoid too long a line for java package name lists
(2) (Space at the end of each line and one at the beginning) . Type a preceding space before each following lines, for example: Class-Path: ...jar ...jar ...jar
Related
I am trying to run a java jar file on a Windows 10 os in my bash terminal, and keep getting this error message:
Duplicate name in Manifest: Java-Bean. Ensure that the manifest does
not have duplicate entries, and that blank lines separate individual
sections in both your manifest and in the META-INF/MANIFEST.MF entry
in the jar file
I tried updating my java path variables, and looking for this META-INF folder, but I'm not sure where to find it.
Also, here is the command that I am entering:
java -jar ManualSentimentClassifier.jar train.csv test.csv positive.txt negative.txt
Any ideas?
Thanks!
Update:
I fixed this issue by opening the jar file archive (using 7zip). I navigated to the META-INF folder and edited the MANIFEST.MF file and removed the duplicated Java Bean information. After I did this, I no longer got the error
I have a jar that uses some of the apache tomcat library jars and thus has the following manifest.
Manifest-Version: 1.0
Main-Class: foo
Class-Path: foo.jar foo_utils.jar . /opt/apache-tomcat/
lib/websocket-api.jar /opt/apache-tomcat/lib/tomcat7-websocket.jar /o
pt/apache-tomcat/lib/tomcat-util.jar /opt/apache-tomcat/lib/tomcat-co
yote.jar /opt/apache-tomcat/bin/tomcat-juli.jar
The jar is able to find foo.jar and foo_utils.jar without a problem.
It can't find any of the jars in the /opt/apache-tomcat/lib folder. I have checked the path and made sure that it is a valid path to the jars I want and is.due to the ant build puts a new line at the end of the classpath last line and thus messes with the line being parsed properly.
How may I have ant not put a new line at the end of my manifest class path file?
The JAR File Specification says (emphasis mine):
Class-Path :
The value of this attribute specifies the relative URLs of the extensions or libraries that this application or extension needs.
The presence of a newline at the end of the MANIFEST.MF is not relevant.
Can you check if your manifest file is ending with a new line or carriage return? As per https://docs.oracle.com/javase/tutorial/deployment/jar/downman.html - the last line will not be parsed properly if it does not end with a new line or carriage return.
I'm not sure but that dot between foo_utils.jar and /opt/apache-tomcat/ seems strange to me. Is there a reason for this dot?
I am getting this strange error while excuting following commands..
cobertura-merge.bat --auxClasspath ./cobertura-2.0.3.jar --datafile cobertura.ser cobertura1.ser cobertura2.ser
cobertura-merge.bat --auxClasspath . --datafile cobertura.ser cobertura1.ser cobertura2.ser
Error -
Error: Could not find or load main class net.sourceforge.cobertura.merge.Main
PS -
I have JAVE HOME set.
Java bin dir is added to PATH.
CLASSPATH is defined with - %CLASSPATH%;.;.
I have added cobertura-2.0.3.jar in jdk lib and jre lib directory.
I ran in to the same problem. To fix this, you will need to edit the cobertura-merge.bat in a text editor. The last line looks something like this:
java -cp "%COBERTURA_HOME%cobertura.jar;%COBERTURA_HOME%lib\asm-3.3.1.jar;.....
The jar file names in this command most likely do not match the jar file names in your cobertura_home\lib.
Example:
In the command above, from the batch file, it references 'cobertura.jar'
If you look in the lib folder, the actual name of the file is 'cobertura-2.0.3.jar
The same goes for the other jar files. So you will have to change the bat file, or the file names, to make them match.
When I type jar cvfm file_name.jar manifest.txt *.class in command prompt I get this error:
java.io.IOException: invalid header field
at java.util.jar.Attributes.read(Attributes.java:410)
at java.util.jar.Manifest.read(Manifest.java:199)
at java.util.jar.Manifest.<init>(Manifest.java:69)
at sun.tools.jar.Main.run(Main.java:172)
at sun.tools.jar.Main.main(Main.java:1177)
I've never gotten this error before and I can't find anything on it, what does it mean?
Be careful about the order of the parameters:
1) jar cvmf manifest.txt some.jar package/*class
2) jar cvfm some.jar manifest.txt package/*class
Check the name of a header variable in the MANIFEST file. MANIFEST file is not correct.
This tutorial will help to identify the MANIFEST file format and related things, http://docs.oracle.com/javase/tutorial/deployment/jar/manifestindex.html
In case you land here and tried everything and still isn't getting rid of the problem, take a look if there are any accidental tabs instead of 4 spaces for indentation in the MANIFEST file.
I was using a maven pom.xml file to auto-generate the MANIFEST and the property line was too big, spanning multiple lines like this:
<Extension-List> item1 item2 item3 item4
item5 item6 item7 item8 <--- these lines are idented with tabs
item9 item10 item11 item12 </Extension-List>
this was corrupting the MANIFEST file in a very hard to see way.
Your Manifest file has to follow the required format. If you're generating the file yourself, then you should be able to figure out where you got the syntax wrong. If the manifest file was generated by some tool or process, however, you'll have to check the tool's documentation to see whether you ran into a bug in the tool.
Read carefully the first line of your manifest, for example :
Main-Class: main.HelloWorld
I had this error because I added a space like this "Main-Class :"
Maybe it is something similar.
My problem was that I had loads of dependencies on one line so I split it up using a simple Find and Replace where each JAR was on a separate line. It turns out that if you have something like:
Class-Path: dependencies/org.apache.commons.cli_1.4.jar (note the space at the end)
dependencies/org.apache.log4j_1.2.15.v201012070815.jar (note the space at the end)
You need to make sure that the line doesn't end with a space, and that the new line begins with a space, like so:
Class-Path: dependencies/org.apache.commons.cli_1.4.jar
dependencies/org.apache.log4j_1.2.15.v201012070815.jar
This problem can also occur if your MANIFEST.MF file begins with some non-printable characters. Tools like notepad and wordpad don't let you see them, so you'll swear you're file looks right and that all your headers are valid.
In my case I got the message:
java.io.IOException: invalid header field name: Built-By
The clue if you are having this situation are those characters occurring before the valid Built-By header. Those are non-printable characters that somehow got into your MANIFEST.MF file. The other clue is to open a command line, navigate to your MANIFEST.MF file and do
>cat MANIFEST.MF
□Build-BY: TSRUT
Bundle-Description: Fragment Controller.
Bundle-License: http://www.apache.org/licenses/LICENSE-2.0.txt
Notice that box character before your 1st header at the beginning of the file. If that's the case, this is the solution to your problem:
Open up your favorite editor, manual select the entire file (do not use the select-all command, as that will also select those hidden characters). Close the file. Open a new instance of your editor, paste your content, and save the new file back to your original MANIFEST.MF file. Select yes to overwrite. Then verify that those hidden character were removed from the beginning of the file.
if your manifest file is having some additional empty lines will also cause this error . Make sure to remove the additional lines.
When i use this cmd line :
jar cmf arshad.mf ars.jar *.class
i get this error :
invalid header field name:Manifest-version
This is my manifest file :
Manifest-Version: 1.0
Main-Class:t
i made the manifest file with notepad in UTF-8 encoding - is there any problem with the manifest ?
Add a space after the colons:
Manifest-Version: 1.0
Main-Class: t
Yes,it is true.
A common mistake people make when writing their manifest files for jar's is that they don't put spaces after their colons. I don't know, based on what you wrote here, if that's it or not but give it a try.
Example:
Main-Class:someClass //wrong
Main-Class: someClass //correct
Also, your manifest file must be saved as UTF-8. You're not necessarily safe writing it on MS Notepad and saving as UTF-8 encoding. This post has some good details:
Invalid Header Field Name when adding manifest to JAR using Eclipse
Notepad adds some bytes onto the front to broadcast the endian-ness of the data. This will break the jar command. A decent solution is to not use Notepad and download Notepad++. In Notepad++ you select 'encoding' from the top bar, and select 'UTF-8 Without BOM'. Saving your manifest file with this setting applied should solve the problem. If there are no others.