Hi Yann,

I don't know if it works, I try it quickly but I had some dependencies 
problem...

So I have corrected the bug in version 1.7.2. There was only two little problem,
the binary directory was "/conf" instead of "/bin", and we need to get the 
absolute path for the command to run.

That's all :)

I put the ExecRunner.java who works in this email.

Regards



----- Mail original -----
De: "Yann BLAZART" <[email protected]>
À: [email protected]
Envoyé: Mardi 27 Octobre 2015 09:49:18
Objet: RE: Problem with tomee-maven-plugin/tomee:exec

Just a suggestion.

Perhaps you can use the tomee-maven-plugin 7.0.0-SNAPSHOT while specifying the 
tome version to package to 1.7.2 ?

It sould work.

-----Original Message-----
From: Edouard LAMOTTE [mailto:[email protected]]
Sent: lundi 26 octobre 2015 19:10
To: [email protected]
Subject: Re: Problem with tomee-maven-plugin/tomee:exec

all right thanks

----- Mail original -----
De: "Romain Manni-Bucau" <[email protected]>
À: [email protected]
Envoyé: Lundi 26 Octobre 2015 18:48:05
Objet: Re: Problem with tomee-maven-plugin/tomee:exec

Hi

2015-10-26 18:36 GMT+01:00 Edouard LAMOTTE <[email protected]>:

> Hi Romain,
>
> i tried to run my executable jar with a maven command "mvn exec:exec",
> it works.
>
> But the idea was to run the application on a laptop who don't have the
> maven project and don't have a TomEE installed.
> And our application is in production with TomEE 1.7.2.
>
> Do you think it will be fixed on TomEE 1.7.x?
>
>
java command has been fixed in 1.7.x. catalina.bat fix has not been backported 
yet.


> Thanks for your help
>
>
> ----- Mail original -----
> De: "Edouard LAMOTTE" <[email protected]>
> À: [email protected]
> Envoyé: Lundi 26 Octobre 2015 17:45:50
> Objet: Re: Problem with tomee-maven-plugin/tomee:exec
>
> ok Romain, i understand,
>
> i will test it
>
> Thanks again
>
> ----- Mail original -----
> De: "Edouard LAMOTTE" <[email protected]>
> À: [email protected]
> Envoyé: Lundi 26 Octobre 2015 17:34:07
> Objet: Re: Problem with tomee-maven-plugin/tomee:exec
>
> Hi romain,
>
> thanks for the quick response.
>
> I'm sorry but i don't understand what do you mean by use java as
> script in mvn config?
>
> Best Regards
>
> ----- Mail original -----
> De: "Romain Manni-Bucau" <[email protected]>
> À: [email protected]
> Envoyé: Lundi 26 Octobre 2015 17:10:12
> Objet: Re: Problem with tomee-maven-plugin/tomee:exec
>
> Hi
>
> For win use java as script in mvn config for tomee 1.7.2.
>
> Has been fixed for 7.0.0 m2.
> Le 26 oct. 2015 16:51, "Edouard LAMOTTE" <[email protected]> a écrit :
>
> > Hi,
> >
> >
> > I'm working with TomEE 1.7.2 on Windows 2007.
> >
> >
> > I want to build a an executable jar with the maven command "mvn
> > tomee:exec".
> >
> >
> > But when i try to test my ***-exec-jar with the java command "java
> > -jar ***-exec.jar"
> >
> >
> > I have an exception :
> >
> > ***-web\target>java -jar ***-web-0.0.1-SNAPSHOT-exec.jar
> >
> >
> > Extracting tomee to ***-web\target\.distribution Exception in thread
> > "main" java.io.IOException: Cannot run program
> > "bin\catalina[.sh|.bat]" (in directory ".distribution"):
> > CreateProcess error=2, Le fichier spécifié est introuvable at
> > java.lang.ProcessBuilder.start(ProcessBuilder.java:1042)
> > at
> >
> org.apache.openejb.maven.plugin.runner.ExecRunner.main(ExecRunner.java
> :165)
> > Caused by: java.io.IOException: CreateProcess error=2, Le fichier
> spécifié
> > est introuvable
> > at java.lang.ProcessImpl.create(Native Method) at
> > java.lang.ProcessImpl.<init>(ProcessImpl.java:386)
> > at java.lang.ProcessImpl.start(ProcessImpl.java:137)
> > at java.lang.ProcessBuilder.start(ProcessBuilder.java:1023)
> > ... 1 more
> >
> >
> > This error occurs in the ProcessBuilder called by the ExecRunner
> > from the tomee-maven-plugin1.7.2.
> >
> >
> > Any idea about this problem?
> >
> >
> > Thanks in advance.
> >
> >
> > Sincerely
>


This message and any attachments (the "message") is
intended solely for the intended addressees and is confidential.
If you receive this message in error,or are not the intended recipient(s), 
please delete it and any copies from your systems and immediately notify
the sender. Any unauthorized view, use that does not comply with its purpose,
dissemination or disclosure, either whole or partial, is prohibited. Since the 
internet
cannot guarantee the integrity of this message which may not be reliable, BNP 
PARIBAS
(and its subsidiaries) shall not be liable for the message if modified, changed 
or falsified.
Do not print this message unless it is necessary,consider the environment.

----------------------------------------------------------------------------------------------------------------------------------

Ce message et toutes les pieces jointes (ci-apres le "message")
sont etablis a l'intention exclusive de ses destinataires et sont confidentiels.
Si vous recevez ce message par erreur ou s'il ne vous est pas destine,
merci de le detruire ainsi que toute copie de votre systeme et d'en avertir
immediatement l'expediteur. Toute lecture non autorisee, toute utilisation de
ce message qui n'est pas conforme a sa destination, toute diffusion ou toute
publication, totale ou partielle, est interdite. L'Internet ne permettant pas 
d'assurer
l'integrite de ce message electronique susceptible d'alteration, BNP Paribas
(et ses filiales) decline(nt) toute responsabilite au titre de ce message dans 
l'hypothese
ou il aurait ete modifie, deforme ou falsifie.
N'imprimez ce message que si necessaire, pensez a l'environnement.
/*
 * Licensed to the Apache Software Foundation (ASF) under one or more
 *  contributor license agreements.  See the NOTICE file distributed with
 *  this work for additional information regarding copyright ownership.
 *  The ASF licenses this file to You under the Apache License, Version 2.0
 *  (the "License"); you may not use this file except in compliance with
 *  the License.  You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 *   Unless required by applicable law or agreed to in writing, software
 *   distributed under the License is distributed on an "AS IS" BASIS,
 *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *   See the License for the specific language governing permissions and
 *   limitations under the License.
 */
package org.apache.openejb.maven.plugin.runner;

import org.apache.openejb.config.RemoteServer;
import org.apache.openejb.loader.Files;
import org.apache.openejb.loader.IO;
import org.apache.openejb.loader.Zips;
import org.apache.openejb.util.Pipe;
import org.apache.tomee.util.QuickServerXmlParser;

import java.io.File;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.LinkedList;
import java.util.List;
import java.util.Locale;
import java.util.Properties;

import static java.util.Arrays.asList;

public class ExecRunner {
	private static final String SH_BAT_AUTO = "[.sh|.bat]";

	public static void main(final String[] rawArgs) throws Exception {
		final String[] args;
		if (rawArgs == null || rawArgs.length == 0) {
			args = new String[] { "run" };
		} else {
			args = rawArgs;
		}

		final Properties config = new Properties();

		final ClassLoader contextClassLoader = Thread.currentThread()
				.getContextClassLoader();
		final InputStream is = contextClassLoader
				.getResourceAsStream("configuration.properties");
		if (is != null) {
			config.load(new InputStreamReader(is, "UTF-8"));
			is.close();
		} else {
			throw new IllegalArgumentException("Config not found");
		}

		final String distrib = config.getProperty("distribution");
		final String workingDir = config.getProperty("workingDir");
		final InputStream distribIs = contextClassLoader
				.getResourceAsStream(distrib);
		File distribOutput = new File(workingDir);
		final File timestampFile = new File(distribOutput, "timestamp.txt");
		final boolean forceDelete = Boolean
				.getBoolean("tomee.runner.force-delete");
		if (forceDelete
				|| !timestampFile.exists()
				|| Long.parseLong(IO.slurp(timestampFile).replace(
						System.getProperty("line.separator"), "")) < Long
						.parseLong(config.getProperty("timestamp"))) {
			if (forceDelete || timestampFile.exists()) {
				System.out.println("Deleting "
						+ distribOutput.getAbsolutePath());
				Files.delete(distribOutput);
			}
			System.out.println("Extracting tomee to "
					+ distribOutput.getAbsolutePath());
			Zips.unzip(distribIs, distribOutput, false);
			IO.writeString(
					timestampFile,
					config.getProperty("timestamp",
							Long.toString(System.currentTimeMillis())));
		}

		final File[] extracted = distribOutput.listFiles();
		if (extracted != null && extracted.length == 1) {
			distribOutput = extracted[0];
		}
		final File[] scripts = new File(distribOutput, "bin").listFiles();
		if (scripts != null) { // dont use filefilter to avoid dependency issue
			for (final File f : scripts) {
				if (f.getName().endsWith(".sh") && !f.canExecute()) {
					if (!f.setExecutable(true, true)) {
						System.err.println("Failed make file executable: " + f);
					}
				}
			}
		}

		String cmd = config.getProperty("command");
		if (cmd.endsWith(SH_BAT_AUTO)) {
			final int lastSlash = cmd.lastIndexOf('/');
			if (lastSlash > 0) {
				final String dir = cmd.substring(0, lastSlash);
				final String script = cmd.substring(lastSlash + 1, cmd.length()
						- SH_BAT_AUTO.length())
						+ (System.getProperty("os.name")
								.toLowerCase(Locale.ENGLISH).contains("win") ? ".bat"
								: ".sh");
				cmd = dir + '/' + script;
				final File scriptFile = new File(distribOutput, cmd);
				if (!scriptFile.exists()) {
					throw new IllegalArgumentException("Can't find  " + cmd);
				}
				cmd = scriptFile.getAbsolutePath();
				if (cmd.endsWith(".sh")) {
					if (!scriptFile.setExecutable(true)) {
						System.err
								.println("Failed make script file executable: "
										+ scriptFile);
					}
				}
			}
		}

		final String additionalArgs = System
				.getProperty("additionalSystemProperties");

		final Collection<String> params = new ArrayList<String>();
		if ("java".equals(cmd)) {
			final QuickServerXmlParser parser = QuickServerXmlParser
					.parse(new File(distribOutput, "conf/server.xml"));

			System.setProperty("openejb.home", distribOutput.getAbsolutePath());
			System.setProperty("server.shutdown.port", parser.stop());
			System.setProperty("server.shutdown.command",
					config.getProperty("shutdownCommand"));

			final RemoteServer server = new RemoteServer();
			server.setPortStartup(Integer.parseInt(parser.http()));

			if (config.containsKey("additionalClasspath")) {
				server.setAdditionalClasspath(config
						.getProperty("additionalClasspath"));
			}

			final List<String> jvmArgs = new LinkedList<String>();
			if (additionalArgs != null) {
				Collections.addAll(jvmArgs, additionalArgs.split(" "));
			}
			for (final String k : config.stringPropertyNames()) {
				if (k.startsWith("jvmArg.")) {
					jvmArgs.add(config.getProperty(k));
				}
			}

			if ("run".equals(args[0])) {
				args[0] = "start";
			}
			server.start(jvmArgs, args[0], true);
			server.getServer().waitFor();
		} else {
			params.add(cmd);
			params.addAll(asList(args));

			final ProcessBuilder builder = new ProcessBuilder(
					params.toArray(new String[params.size()]))
					.directory(distribOutput);

			final String existingOpts = System.getenv("CATALINA_OPTS");
			final String catalinaOpts = config.getProperty("catalinaOpts");
			if (catalinaOpts != null || existingOpts != null
					|| additionalArgs != null) { // inherit from existing env
				builder.environment().put(
						"CATALINA_OPTS",
						identityOrEmpty(catalinaOpts) + " "
								+ identityOrEmpty(existingOpts) + " "
								+ identityOrEmpty(additionalArgs));
			}

			boolean redirectOut = false;
			try { // java >= 7
				ProcessBuilder.class.getDeclaredMethod("inheritIO").invoke(
						builder);
			} catch (final Throwable th) { // java 6
				redirectOut = true;
			}

			final Process process = builder.start();
			if (redirectOut) {
				Pipe.pipe(process);
			}

			process.waitFor();
		}

		System.out.flush();
		System.err.flush();
		System.out.println("Exited Successfully!");
	}

	private static String identityOrEmpty(final String value) {
		return (value != null ? value : "");
	}

	private ExecRunner() {
		// no-op
	}
}

Reply via email to