1

I am using appassembler from mojo. What I need to do is I have to add a perticular path of the project (say %BASEDIR%\resources) to class path, currently it is adding only %REPO% to the classpath. What changes should I do in my pom.xml. I have already provided below code.

<configurationDirectory>/some/path</configurationDirectory>
<includeConfigurationDirectoryInClasspath>true</includeConfigurationDirectoryInClasspath>

And the output batch file contains

set CLASSPATH=%BASEDIR%\\..\SOME\PATH;%REPO%\abc.jar

What I my final outcome should be...

set CLASSPATH=%BASEDIR%\\..\SOME\PATH;%REPO%\abc.jar;%BASEDIR%\resources

What changes should incorporate in my pom.xml for achieving above outcome?

gahlot.jaggs
  • 1,083
  • 3
  • 11
  • 21
  • Duplicate of http://stackoverflow.com/questions/19443377/how-can-i-add-classpath-location-by-using-mojo-appassembler-plugin-while-creatin – khmarbaise Oct 18 '13 at 07:39
  • yea it is duplicate but no one was responding so created a new thread. sorry for that. – gahlot.jaggs Oct 18 '13 at 07:45

1 Answers1

0

This question is really useful im many cases such as allowing different jdbc drivers or user plugins. In my case I wanted to have a jrebel build and therefore I had to change the classpath and switch the jar by the build directory. But I think it is not very difficult to modify the script to fit your needs. Note that you need maven >= 3.0.3 because since maven 3.0.3 all your plugins are executed in the very same order as they are in your pom.xml. So put this plugin right after your appassembler plugin call.

  <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-enforcer-plugin</artifactId>
    <version>1.3.1</version>
    <executions>
      <execution>
        <id>enforce-beanshell</id>
        <phase>package</phase>
        <goals>
          <goal>enforce</goal>
        </goals>
        <configuration>
          <rules>
            <evaluateBeanshell>
              <condition>
                  import java.io.File;
                  import java.nio.file.*;
                  import java.nio.charset.Charset;
                  import java.nio.charset.StandardCharsets;

                  print("replace jrebel classpath in ${basedir}/dist/bin/rebelServer");
                  Path path = Paths.get("${basedir}/dist/bin/rebelServer", new String[]{});
                  Charset charset = StandardCharsets.UTF_8;

                  String content = new String(Files.readAllBytes(path), charset);
                  content = content.replaceAll(
                    "\"\\$REPO\"/kic/engine/CoreEngine/[^/]+/CoreEngine\\-[^;:/]+\\.jar", 
                    "${basedir}/build/classes");

                  Files.write(
                    path, 
                    content.getBytes(charset),
                    new OpenOption[]{StandardOpenOption.CREATE,StandardOpenOption.TRUNCATE_EXISTING,StandardOpenOption.WRITE}
                  );

                  true;
              </condition>
            </evaluateBeanshell>
          </rules>
          <fail>false</fail>
        </configuration>
      </execution>
    </executions>  
  </plugin>
KIC
  • 5,887
  • 7
  • 58
  • 98