Answer the question
In order to leave comments, you need to log in
Link to a file outside the JAR?
My situation:
There is software that is planned to be delivered in one JAR file. There is log4j, which needs a log4j.properties file.
It is planned that such a file will be located somewhere outside the JAR (somewhere in the FS of the server where the software is launched).
Question:
How to implement a link to an external resource in the application code?
UPD:
I've found a way so far to pass it through a property on application startup.
But I really do not want to produce a bunch of parameters by running this JAR.
Is there another more elegant way to pass an external resource to a JAR?
Answer the question
In order to leave comments, you need to log in
The problem is not very clear, but if I understand correctly, then just put log4j.properties in any path contained in the CLASSPATH.
Nothing is invented except as arguments at startup (if a separate application), or put inside a jar file with a setting, for example, in a properties file.
And you name the server simply the machine, or an application server? In the latter case, you could set a JNDI name on the server with string content and use it.
tsegorah , server - I call the physical machine on which the JVM runs.
If we consider the option: put inside the jar file with the setting. Then what about modifying these settings when deploying the application on the server (do not unpack the jar).
Currently implemented via properties and run like this: java -jar -Dlog.config=/path/to/log/log4j.properties application.jar
Which is not an inherently elegant solution.
If it's a standalone application, why not put all application settings (including log4j.properties) in standard (i.e. predefined) places? Like the /etc/yourapp and/or /home/.config/yourapp directory. Look at the XDG specification, or at least the Java system properties .
Well, if the application is launched inside the application server, then there are their own possibilities. JNDI has already been mentioned.
lorus : also an exit. But there is a question of cross-platform.
In Windows, there is no place at all similar to /etc
In freebsd, settings should be stored in /usr/local/etc
And the feature of Java is just in cross-platform
While I strongly oppose this practice, many applications have recently begun to persist in creating their personal directories in the user directory. Perhaps this option will work for you too.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question