I have a situation where i need to Unpack a spring jar and replace a file in that package with my .class file and repackage it back as jar. I understood that this can be done in Maven. So i created a maven project and i added the .java(to be replace in the Spring jar) to it . Here is my Project structure.
here is my pom.xml
<project>
<modelVersion>4.0.0</modelVersion>
<name>repackage</name>
<groupId>org.springframework</groupId>
<artifactId>spring</artifactId>
<version>2.4.6</version>
<packaging>pom</packaging>
<build>
<plugins>
<!-- Unpacking -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.10</version>
<executions>
<execution>
<id>unpack</id>
<phase>package</phase>
<goals>
<goal>unpack</goal>
</goals>
<configuration>
<artifactItems>
<artifactItem>
<groupId>org.springframework</groupId>
<artifactId>spring</artifactId>
<version>2.5.6.SEC03</version>
<type>jar</type>
<overWrite>false</overWrite>
<outputDirectory>target</outputDirectory>
</artifactItem>
</artifactItems>
</configuration>
</execution>
</executions>
</plugin>
<!-- Packing -->
<!-- <plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.4</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>jar</goal>
</goals>
<configuration>
<classesDirectory>target</classesDirectory>
<classifier>sample</classifier>
</configuration>
</execution>
</executions>
</plugin>-->
</plugins>
</build>
</project>
I am able to unpack the spring jar using maven dependency plugin
and i figured out how to pack it back to a jar using maven-jar-plugin
. The part i am struggling to understand 1) how convert my .java file into a .class file. As the packaging is pom type <packaging>pom</packaging>
I am not able to compile the java file(JdkVersion.java
). if successful in creating the class file 2) How to replace this .class file into unpacked spring jar as the file i need to replace is inside the sub directory of /spring
package
You don't have to. Spring is an open source project just clone its source code https://github.com/spring-projects/spring-framework?files=1 and update the code and create a package using simple mvn package command