private File createJar( List<String> classPath, String mainClass )
        throws IOException
    {
        File file = File.createTempFile( "maven-exec", ".jar" );
        file.deleteOnExit();
        FileOutputStream fos = new FileOutputStream( file );
        JarOutputStream jos = new JarOutputStream( fos );
        jos.setLevel( JarOutputStream.STORED );
        JarEntry je = new JarEntry( "META-INF/MANIFEST.MF" );
        jos.putNextEntry( je );

        Manifest man = new Manifest();

        // we can't use StringUtils.join here since we need to add a '/' to
        // the end of directory entries - otherwise the jvm will ignore them.
        StringBuilder cp = new StringBuilder();
        for ( String el : classPath )
        {
            // NOTE: if File points to a directory, this entry MUST end in '/'.
            cp.append( new URL( new File( el ).toURI().toASCIIString() ).toExternalForm() + " " );
        }

        man.getMainAttributes().putValue( "Manifest-Version", "1.0" );
        man.getMainAttributes().putValue( "Class-Path", cp.toString().trim() );
        man.getMainAttributes().putValue( "Main-Class", mainClass );

        man.write( jos );
        jos.close();

        return file;
    }
private File createJar( List<String> classPath, String mainClass )
        throws IOException
    {
        File file = File.createTempFile( "maven-exec", ".jar" );
        file.deleteOnExit();
        FileOutputStream fos = new FileOutputStream( file );
        JarOutputStream jos = new JarOutputStream( fos );
        jos.setLevel( JarOutputStream.STORED );
        JarEntry je = new JarEntry( "META-INF/MANIFEST.MF" );
        jos.putNextEntry( je );

        Manifest man = new Manifest();

        
        
        StringBuilder cp = new StringBuilder();
        for ( String el : classPath )
        {
            
            cp.append( new URL( new File( el ).toURI().toASCIIString() ).toExternalForm() + " " );
        }

        man.getMainAttributes().putValue( "Manifest-Version", "1.0" );
        man.getMainAttributes().putValue( "Class-Path", cp.toString().trim() );
        man.getMainAttributes().putValue( "Main-Class", mainClass );

        man.write( jos );
        jos.close();

        return file;
    }
private File createJar ( List < String > classPath , String mainClass ) throws IOException { File file = File . createTempFile ( "maven-exec" , ".jar" ) ; file . deleteOnExit ( ) ; FileOutputStream fos = new FileOutputStream ( file ) ; JarOutputStream jos = new JarOutputStream ( fos ) ; jos . setLevel ( JarOutputStream . STORED ) ; JarEntry je = new JarEntry ( "META-INF/MANIFEST.MF" ) ; jos . putNextEntry ( je ) ; Manifest man = new Manifest ( ) ; // we can't use StringUtils.join here since we need to add a '/' to // the end of directory entries - otherwise the jvm will ignore them. StringBuilder cp = new StringBuilder ( ) ; for ( String el : classPath ) { // NOTE: if File points to a directory, this entry MUST end in '/'. cp . append ( new URL ( new File ( el ) . toURI ( ) . toASCIIString ( ) ) . toExternalForm ( ) + " " ) ; } man . getMainAttributes ( ) . putValue ( "Manifest-Version" , "1.0" ) ; man . getMainAttributes ( ) . putValue ( "Class-Path" , cp . toString ( ) . trim ( ) ) ; man . getMainAttributes ( ) . putValue ( "Main-Class" , mainClass ) ; man . write ( jos ) ; jos . close ( ) ; return file ; }
Create a jar with just a manifest containing a Main-Class entry for SurefireBooter and a Class-Path entry for all
classpath elements. Copied from surefire (ForkConfiguration#createJar())

@param classPath List&lt;String> of all classpath elements.
@return
@throws IOException
Create a jar with just a manifest containing a Main - Class entry for SurefireBooter and a Class - Path entry for all classpath elements . Copied from surefire ( ForkConfiguration#createJar () )