How to set a long Java classpath in Windows?
The Windows command line is very limiting in this regard. A workaround is to create a "pathing jar". This is a jar containing only a Manifest.mf
file, whose Class-Path
specifies the disk paths of your long list of jars, etc. Now just add this pathing jar to your command line classpath. This is usually more convenient than packaging the actual resources together.
As I recall, the disk paths can be relative to the pathing jar itself. So the Manifest.mf
might look something like this:
Class-Path: this.jar that.jar ../lib/other.jar
If your pathing jar contains mainly foundational resources, then it won't change too frequently, but you will probably still want to generate it somewhere in your build. For example:
<jar destfile="pathing.jar">
<manifest>
<attribute name="Class-Path" value="this.jar that.jar ../lib/other.jar"/>
</manifest>
</jar>
Class-Path line too long
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
How to set multiple classpath entries in java at runtime?
In addition to @Szmeby answer, if you don't know how to use file with classpath inside, you may try to create a "pathing jar".
"Pathing jar" contains only Manifest.mf file which includes next entry:
Class-Path: some.jar another.jar others.jar
You can also use wildcards to reduce length.
How should I set CLASSPATH?
Since you are using JDK6, you can use classpath wildcards: CLASSPATH=".:/home/phoenies/jdk1.6.0_17/lib/*" will match all JARS inside lib/
Check out http://java.sun.com/javase/6/docs/technotes/tools/windows/classpath.html there's a section called "Understanding class path wildcards"
Shorten classpath (-cp) for command line
The maven-jdeps-plugin is using plexus-utils to fork out a child process to run the jdeps executable. plexus-utils implements this by building up a command-line and passing it to cmd.exe. This is the wrong approach as it will be subject to the 8192 char limit imposed by cmd.exe. The correct approach would be to use the Java ProcessBuilder API. This itself uses ProcessImpl.create API method, which, on Windows, is implemented by a Win32 API call to CreateProcess. The latter API has a 32k char limit, which should be enough for most use cases.
There is a plexus-utils bug report for this. You may want to raise one with maven-jdeps-plugin as well - the Java ProcessBuilder API is quite usable, so there's no need to use plexus-utils just to run jdeps.
Related Topics
How to Stop a Thread Created by Implementing Runnable Interface
Locally Declared Variables Can Not Be Inspected
Hashmap to Return Default Value for Non-Found Keys
Import Sun.Misc.Base64Encoder Results in Error Compiled in Eclipse
How to Decode a String Encoded with Openssl Aes-128-Cbc Using Java
Why Is My Jlabel Not Showing Up
How Much Memory Does a String Use in Java 8
Matrix Multiplication in Apache Spark
Found Shared References to a Collection Org.Hibernate.Hibernateexception
How to Configure Hibernate Config File for SQL Server
Declaring Floats, Why Default Type Double
Chat Client Emoticons Window Java
How to Achieve Conditional Resource Import in a Spring Xml Context
Block()/Blockfirst()/Blocklast() Are Blocking Error When Calling Bodytomono After Exchange()
How to Hide a Jframe in System Tray of Taskbar
Java Getting an Error for Implementing Interface Method with Weaker Access