I wrote a small python script to take several java source files and create a single one with correct imports.
There is the link, juste place it in the folder which contains your src folder (or modify the variable srcFolder) and run it. This will create (or replace) a file named packed.java (or modify the variable dstName)
just add tag in your children class to remove import with replacel goal, otherwise it will throws errorsin the resulting class :
/begin import/
import java.*;
/end import/
After you just have to execute mvn yuicompressor:compress; mvn replacer:replace;
<build>
<plugins>
<plugin>
<groupId>net.alchim31.maven</groupId>
<artifactId>yuicompressor-maven-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>compress</goal>
</goals>
</execution>
</executions>
<configuration>
<nosuffix>true</nosuffix>
<aggregations>
<aggregation>
<!-- remove files after aggregation (default: false)
<removeIncluded>true</removeIncluded>
-->
<!-- insert new line after each concatenation (default: false) -->
<insertNewLine>true</insertNewLine>
<output>${basedir}/src/main/final/Player_v${version}.java</output>
<!-- files to include, path relative to output's directory or absolute path-->
<!--inputDir>base directory for non absolute includes, default to parent dir of output</inputDir-->
<includes>
<!-- include your class -->
<include>${basedir}/src/main/java/YourClass.java</include>
</includes>
<!-- files to exclude, path relative to output's directory
<excludes>
<exclude>**/*.pack.js</exclude>
<exclude>**/compressed.css</exclude>
</excludes>
-->
</aggregation>
</aggregations>
</configuration>
</plugin>
<plugin>
<!-- remove your import -->
<groupId>com.google.code.maven-replacer-plugin</groupId>
<artifactId>replacer</artifactId>
<version>1.5.3</version>
<executions>
<execution>
<goals>
<goal>replace</goal>
</goals>
</execution>
</executions>
<configuration>
<ignoreMissingFile>true</ignoreMissingFile>
<file>${basedir}/src/main/final/Player_v${version}.java</file>
<outputFile>
${basedir}/src/main/final/Player_v${version}.java
</outputFile>
<regex>true</regex>
<regexFlags>
<regexFlag>DOTALL</regexFlag>
<regexFlag>MULTILINE</regexFlag>
</regexFlags>
<!-- this the token i am using to remove import, you can add your own -->
<token>\/\*\*begin import\*\*\/.*?\/\*\*end import\*\*\/</token>
<value></value>
</configuration>
</plugin>
</plugins>
</build>
Thanks, this is very useful
Not sure why it was not in the original script but I found it necessary to replace âpublic classâ with âclassâ
sorry for my bad Python:
elif ligne.startswith(âpublic classâ):
tabCode.append(ligne.replace(âpublic classâ, âclassâ))