[
Date Prev][
Date Next][
Thread Prev][
Thread Next][
Date Index][
Thread Index]
[
List Home]
Re: [jetty-users] How to pass property files not in start.d to start.jar ?
|
It would be great if start.jar would accept a properties file external
to jetty.home and jetty.base. Our application will ship with a single
properties file and we would like to not duplicate it to the
container.
Attached is a patch for jetty-start 9.1.5.v20140505 (not sure if this
list accepts attachments). I understand that this project does not
accept patches via email, but before I spend more time and create a
bugzilla issue I thought I would ask if the patch seems reasonable. I
basically copied StartArgs#resolveExtraXmls() and created
StartArgs#resolvePropertyFiles(). I did not write a test, but I did
verify that start.jar passed a property file external to
jetty.home|base to XmlConfiguration.
I can create a bugzilla issue, let me know.
Thanks,
Tom
On Wed, May 7, 2014 at 8:59 AM, Joakim Erdfelt <joakim@xxxxxxxxxxx> wrote:
> that command line is invalid.
> how about ...
>
>> java -jar start.jar myapp.property=foo
>
> if you want a list of properties managed in a file, create a
> ${jetty.base}/start.ini and put your properties in there. (skip the
> start.d/*.ini use entirely)
>
>
> --
> Joakim Erdfelt <joakim@xxxxxxxxxxx>
> webtide.com - intalio.com/jetty
> Expert advice, services and support from from the Jetty & CometD experts
> eclipse.org/jetty - cometd.org
>
>
> On Tue, May 6, 2014 at 4:27 PM, Tom Zeller <tzeller@xxxxxxxxxxxxxx> wrote:
>>
>> Hi,
>>
>> According to the documentation [1], it should be possible to pass a
>> properties file located at an arbitrary path to start.jar, but this
>> does not seem to be the case :
>>
>> > java -jar start.jar app.properties
>> Unrecognized argument: "app.properties" in <command-line>
>>
>> It looks like command line args are not passed in totality from
>> StartArgs to XmlConfiguration.
>>
>> Is there a way to source properties for use in <Property /> elements
>> from a properties file at an arbitrary path (not in start.d) ?
>>
>> Thanks,
>> Tom
>>
>> [1]
>> http://www.eclipse.org/jetty/documentation/9.1.2.v20140210/jetty-xml-usage.html
>> (Setting Parameters in Configuration Files)
>> _______________________________________________
>> jetty-users mailing list
>> jetty-users@xxxxxxxxxxx
>> https://dev.eclipse.org/mailman/listinfo/jetty-users
>
>
>
> _______________________________________________
> jetty-users mailing list
> jetty-users@xxxxxxxxxxx
> https://dev.eclipse.org/mailman/listinfo/jetty-users
>
diff --git a/jetty-start/src/main/java/org/eclipse/jetty/start/FS.java b/jetty-start/src/main/java/org/eclipse/jetty/start/FS.java
index 5fd41b9..9c04297 100644
--- a/jetty-start/src/main/java/org/eclipse/jetty/start/FS.java
+++ b/jetty-start/src/main/java/org/eclipse/jetty/start/FS.java
@@ -195,6 +195,11 @@
return filename.toLowerCase(Locale.ENGLISH).endsWith(".xml");
}
+ public static boolean isPropertyFile(String filename)
+ {
+ return filename.toLowerCase(Locale.ENGLISH).endsWith(".properties");
+ }
+
public static String toRelativePath(File baseDir, File path)
{
return baseDir.toURI().relativize(path.toURI()).toASCIIString();
diff --git a/jetty-start/src/main/java/org/eclipse/jetty/start/Main.java b/jetty-start/src/main/java/org/eclipse/jetty/start/Main.java
index c196aff..acea4b8 100644
--- a/jetty-start/src/main/java/org/eclipse/jetty/start/Main.java
+++ b/jetty-start/src/main/java/org/eclipse/jetty/start/Main.java
@@ -578,6 +578,9 @@
// 8) Resolve Extra XMLs
args.resolveExtraXmls(baseHome);
+
+ // 9) Resolve Property Files
+ args.resolvePropertyFiles(baseHome);
return args;
}
diff --git a/jetty-start/src/main/java/org/eclipse/jetty/start/StartArgs.java b/jetty-start/src/main/java/org/eclipse/jetty/start/StartArgs.java
index 93ca76d..8e0ec3d 100644
--- a/jetty-start/src/main/java/org/eclipse/jetty/start/StartArgs.java
+++ b/jetty-start/src/main/java/org/eclipse/jetty/start/StartArgs.java
@@ -74,6 +74,8 @@
private Classpath classpath;
private List<String> xmlRefs = new ArrayList<>();
private List<File> xmls = new ArrayList<>();
+ private List<String> propertyFileRefs = new ArrayList<>();
+ private List<File> propertyFiles = new ArrayList<>();
private Props properties = new Props();
private Set<String> systemPropertyKeys = new HashSet<>();
private List<String> jvmArgs = new ArrayList<>();
@@ -127,6 +129,19 @@
if (!xmls.contains(xmlfile))
{
xmls.add(xmlfile);
+ }
+ }
+
+ private void addUniquePropertyFile(String propertyFileRef, File propertyFile) throws IOException
+ {
+ if (!FS.canReadFile(propertyFile))
+ {
+ throw new IOException("Cannot read file: " + propertyFileRef);
+ }
+ propertyFile = propertyFile.getCanonicalFile();
+ if (!propertyFiles.contains(propertyFile))
+ {
+ propertyFiles.add(propertyFile);
}
}
@@ -481,6 +496,11 @@
for (File xml : xmls)
{
cmd.addRawArg(xml.getAbsolutePath());
+ }
+
+ for (File propertyFile : propertyFiles)
+ {
+ cmd.addRawArg(propertyFile.getAbsolutePath());
}
return cmd;
@@ -896,6 +916,16 @@
}
return;
}
+
+ if (FS.isPropertyFile(arg))
+ {
+ // only add non-duplicates
+ if (!propertyFileRefs.contains(arg))
+ {
+ propertyFileRefs.add(arg);
+ }
+ return;
+ }
// Anything else is unrecognized
throw new UsageException(ERR_BAD_ARG,"Unrecognized argument: \"%s\" in %s",arg,source);
@@ -925,6 +955,21 @@
addUniqueXmlFile(xmlRef,xmlfile);
}
}
+
+ public void resolvePropertyFiles(BaseHome baseHome) throws IOException
+ {
+ // Find and Expand property files
+ for (String propertyFileRef : propertyFileRefs)
+ {
+ // Straight Reference
+ File propertyFile = baseHome.getFile(propertyFileRef);
+ if (!propertyFile.exists())
+ {
+ propertyFile = baseHome.getFile("etc/" + propertyFileRef);
+ }
+ addUniquePropertyFile(propertyFileRef,propertyFile);
+ }
+ }
public void setAllModules(Modules allModules)
{