1 package org.apache.maven.plugin.war.util;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import org.apache.maven.archiver.MavenArchiveConfiguration;
23 import org.apache.maven.archiver.MavenArchiver;
24 import org.apache.maven.artifact.DependencyResolutionRequiredException;
25 import org.apache.maven.execution.MavenSession;
26 import org.apache.maven.plugin.MojoExecutionException;
27 import org.apache.maven.plugin.war.packaging.AbstractWarPackagingTask;
28 import org.apache.maven.project.MavenProject;
29 import org.codehaus.plexus.archiver.ArchiverException;
30 import org.codehaus.plexus.archiver.jar.JarArchiver;
31 import org.codehaus.plexus.archiver.jar.ManifestException;
32
33 import java.io.File;
34 import java.io.IOException;
35
36
37
38
39
40
41
42 public class ClassesPackager
43 {
44
45
46
47
48 public ClassesPackager()
49 {
50 super();
51 }
52
53
54
55
56
57
58
59
60
61
62
63
64 public void packageClasses( File classesDirectory, File targetFile, JarArchiver jarArchiver, MavenSession session,
65 MavenProject project, MavenArchiveConfiguration archiveConfiguration )
66 throws MojoExecutionException
67 {
68
69 try
70 {
71 final MavenArchiver archiver = new MavenArchiver();
72 archiver.setArchiver( jarArchiver );
73 archiver.setOutputFile( targetFile );
74 archiver.getArchiver().addDirectory( classesDirectory );
75 archiver.createArchive( session, project, archiveConfiguration );
76 }
77 catch ( ArchiverException e )
78 {
79 throw new MojoExecutionException( "Could not create classes archive", e );
80 }
81 catch ( ManifestException e )
82 {
83 throw new MojoExecutionException( "Could not create classes archive", e );
84 }
85 catch ( IOException e )
86 {
87 throw new MojoExecutionException( "Could not create classes archive", e );
88 }
89 catch ( DependencyResolutionRequiredException e )
90 {
91 throw new MojoExecutionException( "Could not create classes archive", e );
92 }
93 }
94
95
96
97
98
99
100
101 public File getClassesDirectory( File webappDirectory )
102 {
103 return new File( webappDirectory, AbstractWarPackagingTask.CLASSES_PATH );
104 }
105 }