Maven appassembler plugin: How to deal with path too long issue in Windows

Posted by {"name"=>"Palash Ray", "email"=>"paawak@gmail.com", "url"=>"https://www.linkedin.com/in/palash-ray/"} on September 09, 2015 · 2 mins read

Windows sucks! We all know that. Recently, I had one more reason to crib. I am using the Maven appassembler plugin to create a deployable distribution for my Rmi Server. I added a couple of more dependencies. And suddenly, the windows .bat file that is generated by the appassembler, suddenly wont launch. It was complaining that the path was too long!
Well, I visited the plugin's home page and after struggling for 3 hrs, I was none the wiser.
Then, I chanced upon an article and with a little bit of tweaking, I was able to get it working. The trick is the following magic line:

 true


                                                org.codehaus.mojo
                                                appassembler-maven-plugin
                                                1.6
                                                
                                                        flat
                                                        libs
                                                        true
                                                        conf
                                                        true
                                                        true
                                                        
                                                                unix
                                                                windows
                                                        
                                                        
                                                                
                                                                        com.swayam.demo.rmi.server.core.SpringNonSecureRmiServer
                                                                        run_rmi_server
                                                                
                                                        
                                                
                                                
                                                        
                                                                package
                                                                
                                                                        assemble
                                                                
                                                        
                                                
                                        

Before the fix

The run_rmi_server.bat looked like:

     set CLASSPATH=”%BASEDIR%”etc;”%REPO%”rmi-api-1.0.jar;”%REPO%”log4j-1.2.14.jar;”%REPO%”slf4j-api-1.5.8.jar;”%REPO%”jcl-over-slf4j-1.5.8.jar;”%REPO%”slf4j-log4j12-1.5.8.jar;”%REPO%”spring-core-4.0.2.RELEASE.jar;”%REPO%”spring-context-4.0.2.RELEASE.jar;”%REPO%”spring-aop-4.0.2.RELEASE.jar;”%REPO%”aopalliance-1.0.jar;”%REPO%”spring-beans-4.0.2.RELEASE.jar;”%REPO%”spring-expression-4.0.2.RELEASE.jar;”%REPO%”jsk-platform-2.2.2.jar;”%REPO%”jsk-resources-2.2.2.jar;”%REPO%”jsk-lib-2.2.2.jar;”%REPO%”reggie-2.2.2.jar;”%REPO%”start-2.2.2.jar;”%REPO%”mysql-connector-java-5.1.27.jar;”%REPO%”rmi-server-1.0.jar
    set ENDORSED_DIR=
    if NOT “%ENDORSED_DIR%” == “” set CLASSPATH=”%BASEDIR%”%ENDORSED_DIR%*;%CLASSPATH%
    if NOT “%CLASSPATH_PREFIX%” == “” set CLASSPATH=%CLASSPATH_PREFIX%;%CLASSPATH%
    @REM Reaching here means variables are defined and arguments have been captured
    :endInit
    %JAVACMD% %JAVA_OPTS% -classpath %CLASSPATH% -Dapp.name=”run_rmi_server” -Dapp.repo=”%REPO%” -Dapp.home=”%BASEDIR%” -Dbasedir=”%BASEDIR%” com.swayam.demo.rmi.server.core.SpringNonSecureRmiServer %CMD_LINE_ARGS%
    if %ERRORLEVEL% NEQ 0 goto error
    goto end

After the fix

The run_rmi_server.bat looks like:

set CLASSPATH="%BASEDIR%"etc;"%REPO%"*
set ENDORSED_DIR=
if NOT "%ENDORSED_DIR%" == "" set CLASSPATH="%BASEDIR%"%ENDORSED_DIR%*;%CLASSPATH%
if NOT "%CLASSPATH_PREFIX%" == "" set CLASSPATH=%CLASSPATH_PREFIX%;%CLASSPATH%
@REM Reaching here means variables are defined and arguments have been captured
:endInit
%JAVACMD% %JAVA_OPTS%  -classpath %CLASSPATH% -Dapp.name="run_rmi_server" -Dapp.repo="%REPO%" -Dapp.home="%BASEDIR%" -Dbasedir="%BASEDIR%" com.swayam.demo.rmi.server.core.SpringNonSecureRmiServer %CMD_LINE_ARGS%
if %ERRORLEVEL% NEQ 0 goto error
goto end

Note that the path has been shortened by using *. This has been introduced in JDK 6: https://docs.oracle.com/javase/6/docs/technotes/tools/windows/classpath.html