Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Execute the package goal before exec. #221

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@
*/
package com.kumuluz.ee.maven.plugin;

import org.apache.maven.execution.MavenSession;
import org.apache.maven.plugin.BuildPluginManager;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugins.annotations.*;
import org.apache.maven.project.MavenProject;
Expand All @@ -42,29 +40,63 @@
requiresDependencyResolution = ResolutionScope.COMPILE_PLUS_RUNTIME,
requiresDependencyCollection = ResolutionScope.COMPILE_PLUS_RUNTIME
)
@Execute(phase = LifecyclePhase.PACKAGE)
public class RunExplodedMojo extends AbstractCopyDependenciesMojo {

private static final String CLASSPATH_FORMAT = "target%1$sclasses%2$starget%1$sdependency%1$s*";

@Override
public void execute() throws MojoExecutionException {

final String CLASSPATH_FORMAT = "target%1$sclasses%2$starget%1$sdependency%1$s*";

copyDependencies();

executeMojo(
plugin(
groupId("org.codehaus.mojo"),
artifactId("exec-maven-plugin"),
version("1.6.0")
version("3.1.0")
),
goal("java"),
goal("exec"),
configuration(
element(name("mainClass"), "com.kumuluz.ee.EeApplication"),
element(name("executable"), javaCmd()),
element(name("inheritIo"), "true"),
element(name("arguments"),
element(name("argument"), "-classpath"),
element(name("argument"), String.format(CLASSPATH_FORMAT, File.separator, File.pathSeparator)))
element(name("argument"), "-cp"),
element(name("argument"), String.format(CLASSPATH_FORMAT, File.separator, File.pathSeparator)),
element(name("argument"), "com.kumuluz.ee.EeApplication"))
),
executionEnvironment(project, session, buildPluginManager)
);
}
}

public static String javaCmd() {
File javaCmd = fileForEnv("JAVACMD");

if (javaCmd != null) {
return javaCmd.getAbsolutePath();
}

File javaHome = fileForEnv("JAVA_HOME");
if (javaHome != null) {

String[] paths = {"jre/sh/java", "bin/java", "bin/java.exe"};

for( String path : paths ) {
File f = new File(javaHome, path);
if (f.isFile() && f.canExecute()) {
return f.getAbsolutePath();
}
}
}
return "java";
}

private static File fileForEnv(String env) {
String s = System.getenv(env);
if (s == null || s.isEmpty()) {
return null;
} else {
return new File(s);
}
}
}