I haven't found in the documentation on how to do this with the Embedded server code. It recommended to use a json settings file however the documentation is clear where to put the json file or if it will work with the embedded version.
Configuration in RavenDB (also embedded) can be set by settings file, environment variables, and command line arguments.
Command line arguments will override the settings file and those will override environment variables.
The default location of the settings file is inside the binaries folder.
You can change that by command line argument -c="{PATH_TO_SETTINGS_FILE}".
To pass command line arguments to embedded you can use its options:
EmbeddedServer.Instance.StartServer(new ServerOptions
{
CommandLineArgs = new List<string>
{
"-c=\"{PATH_TO_CONFIGURATION_FILE}\"",
"LogMode=\"Information\""
}
});
Console.WriteLine("started");
Note: All the configurations passed by Raven.Embedded.ServerOptions are passed by the command line arguments and so will override other configuration sources for the same properties.
https://ravendb.net/docs/article-page/5.4/csharp/server/configuration/configuration-options
https://ravendb.net/docs/article-page/5.4/csharp/server/configuration/command-line-arguments
https://ravendb.net/docs/article-page/5.4/csharp/server/configuration/core-configuration
Related
After running IntelliJ's command line code formatter on a set of Java source files the German characters in the source are replaced with "garbage".
How can I configure the input and output encoding of the formatter?
I tried adding -encoding iso-8859-15 -docencoding iso-8859-15 as an option to the formatter command line but those options are not recognized.
I also tried creating an idea.properties file with the following content:
-Dfile.encoding=ISO-8859-15
And running the formatter with the environment variable IDEA_PROPERTIES set pointing to this file:
C:\>set IDEA_PROPERTIES="E:\project\config-files\idea.properties"
I also tried inserting the option -Dfile.encoding=ISO-8859-15 directly in the idea.bat file (which is called by the format.bat.
None of these worked.
How can I ensure that the formatter respects the encoding of these source files?
Command line used now is like
C:\>"C:\Program Files\JetBrains\IntelliJ IDEA Community Edition 2018.2.4\bin\format.bat" -r E:\project\java style -m *.java -s e:\project\config-files\CodeStyleSettings.xml
Note: If I convert the source file to UTF-8 before running the formatter the formatting works as expected (the German characters are preserved).
Another note: If the format code is run within the IDE GUI it is possible to set the file encoding in the project options. The command line formatter does not make use of a project so these settings are not respected.
The goal is to turn this into a step in our automated process that can be run by any of a number of users. So I'd like to avoid changes to config files in a user's specific directory like the IDE configuration directory.
I need to pass some command line properties that could be read by a plugin. I looked around and did not see anything.
I would rather do it this way that in the admin console. It would be a single property.
Or, .... If I can pass a configuration file that I might customize that could be available to a plugin.
So is there a way?
I'm developing an application in Dropwizard 0.9, using IntelliJ Idea as my IDE. I have a run configuration configured, and it passes the command line arguments "server ./path/to/config.yml" to specify the configuration file to run with.
When I try to run my unit tests, however, I cannot determine how to pass this config file path to the server. The Run/Debug Configuration dialog has a "Program Arguments" field, but it is permanently disabled (and the edit button adjacent to it does nothing).
How can I enable program arguments, or, alternatively, is there another way to specify the config file for tests?
if your config.yml is in the project's root folder, just set server config.yml in the IDE. Take a look at this video.
If you would like to access the config.yml from the project's root folder, just pass the name of the file to the rule.
#ClassRule
public static final DropwizardAppRule<DWGettingStartedConfiguration> RULE
= new DropwizardAppRule<>(DWGettingStartedApplication.class,
"config.yml");
Also, it is possible to store the configuration file for integration tests in the src/test/resources folder. In this case, the file can be accessed using the following code:
/**
* A path to test configuration file.
*/
private static final String CONFIG_PATH
= ResourceHelpers.resourceFilePath("test-config.yml");
/**
* Start the application before all test methods.
*/
#ClassRule
public static final DropwizardAppRule<DropBookmarksConfiguration> RULE
= new DropwizardAppRule<>(
DropBookmarksApplication.class,
CONFIG_PATH);
In addition, please take a look at my example projects here, here and here.
I have a property file placed in the root of the web project in Java. I am using Struts 2.
My code is unable to read properties file. Where should I keep my properties file?
I have checked default path , it is where my Eclipse in installed. But I want that system should read file from project folder itself.
Usually you should put the properties file to the src folder so your application is able to read the properties file when you do run your application the properties file is copied from the src folder to the classes folder. As far as you know the classes folder should be the project output folder, so it will be used as a classpath folder and application is able to load the properties file if it is on the classpath.
An example to get properties from the classpath:
Properties prop = new Properties();
try {
//load properties from the class path
prop.load(this.getClass().getClassLoader().getResourceAsStream("myproperties.properties"));
//get the property
System.out.println(prop.getProperty("mykey"));
} catch (IOException ex) {
ex.printStackTrace();
throw ex;
}
However, you can load properties if you know the path to the file on the filesystem, in this case use
prop.load(new FileInputStream("/path/to/myproperties.properties"));
If you are talking about struts.properties
The framework uses a number of properties that can be changed to fit
your needs. To change any of these properties, specify the property
key and value in an struts.properties file. The properties file can be
locate anywhere on the classpath, but it is typically found under
/WEB-INF/classes.
If you are looking for Message Resource properties it could be configured in the struts.properties or struts.xml the later is proffered.
<constant name="struts.custom.i18n.resources" value="path/to/resources/MessageResources"/>
the value is a filepath src/path/to/resources/MessageResources.properties
If you are looking for the proper way to configure your application consider the choice to use EasyConf.
Property files will generally either go:
on the the classpath, e.g., for opening as a resource, or
at a location inaccessible to clients, e.g., under /WEB-INF
Which is more appropriate depends on your needs. Classpath-based files allow bundled default property files without configuration. For example, Log4J will look for log4j.properties at the root of the classpath as its default configuration file.
This can occasionally lead to issues, however, depending on class loading order: sometimes the system can pick up a "stray" config file. Configuring it yourself may still be preferable; I still tend towards the classpath, but config files are also commonly found in WEB-INF. Either method works, and both styles can be configured using JNDI, init params, environment variables, or system variables (e.g., -D).
Keep your myPropertyFile.properties file in src folder (after build project you will find it in WEB-INF/classes) and access them using this code:
Properties prop = new Properties();
ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
prop.load(classLoader.getResourceAsStream("/myPropertyFile.properties"));
Ideally, you can save properties files in:
/src/com/cft/web/bundle/.
like,
/src/com/cft/web/bundle/LabelResources.properties
OR
/src/com/cft/web/bundle/Applicationresources.properties.
in fact its up to you to give whatever the path you like.
Just remember to add the correct complete path in web.xml/struts-config.xml
for ex=g.
1. in web.xml :
<description>Application Resources</description>
<env-entry-name>ApplicationResources</env-entry-name>
<env-entry-value>com.cft.web.bundle.ApplicationResources</env-entry-value>
<env-entry-type>java.lang.String</env-entry-type>
In Struts-config.xml
<message-resources parameter="com.cft.web.bundle.LabelResources" key="yourPropertiesFileName"/>
I'm looking for the best way to use an external properties file with an application that is going to be deployed on Weblogic 10.3 server. I read a number of articles on the site but I don't want to hard-code the path to the properties file or put the file in the domains/mydomain folder.
Is there a dynamic way of doing this so when the application is deployed the properties file is also installed for example under the deployments folder and read from there?
Many thanks
Another alternative that does not require putting the file in a place other applications will read it is to use the Generic File Loading Overrides:
http://download.oracle.com/docs/cd/E21764_01/web.1111/e13702/config.htm#i1066493
This involves creating a directory that will be the root directory of your deployment, let's call it FooApplication that has FooApplication.ear and FooWeb.war. This is called the Application Installation Directory. Your application goes in the FooApplication/app sub-directory whether it is an archive (like .ear, .war, jar) or whether it is an exploded version of one of those archives. Your optional deployment plan (you must have one to use this feature, it could be a plan that does not do much beyond specifying a config-root element and values as described in the documentation) goes in the FooApplication/plan. You can put your properties that you want to override ones in the application in FooApplication/plan/AppFileOverrides directory structure.
http://download.oracle.com/docs/cd/E21764_01/web.1111/e13702/deployunits.htm#sthref9
Once that style of deployment is done, you write code like this from your application and the contents of myApp.properties get read from the FooApplication/plan/AppFileOverrides/FooWeb.war/myApp.properties will be the actual file that is read in.
Properties myAppProps = new Properties();
InputStream iostream =
Thread.currentThread().getContextClassLoader().getResourceAsStream("myCfg/myApp.properties");
myAppProps.load(iostream);
This is accomplished by adding a classloader to your application as explained in the docs. It might seem tedious to initially configure, but it is a feature that directly satisfies the original question and only for that particular application.
You can set a directory on the classpath and Place your custom properties file in that folder/directory. So that, the entire directory along with property file will be on classpath.
To set the directory on the classpath in weblogic 10.3.x
Create a folder in %DOMAIN_HOME%\config\ folder. example appConfig.
Place your custom property file (Let's say config.properties) in appConfig directory/folder.
Modify the setDomainEnv.cmd (Windows) to include appConfig in the classpath by setting %DOMAIN_HOME%\config\appConfig as value to EXT_POST_CLASSPATH(this variable is already defined in the setDomainEnv.cmd file) variable as below:
set EXT_POST_CLASSPATH=%EXT_POST_CLASSPATH%;%DOMAIN_HOME%\config\appConfig
You can access that file in you java code as below:
InputStream inputStream = Thread.currentThread ().getContextClassLoader().getResourceAsStream ("config.properties");
Properties prop = new Properties();
prop.load(inputStream);
String value = prop.getProperty("key");
Hope this helps.
Approach #2
Use Weblogic shared library
http://download.oracle.com/docs/cd/E12840_01/wls/docs103/programming/libraries.html
Follow below steps
Package all your configuration as separate JAR during the build process
Deploy configuration JAR as shared library
Reference above shared library from your EAR/WAR
Deploy EAR/WAR (Configurations will be available in classpath)
When you say " I read a number of articles on the site but I don't want to hard-code the path to the properties file" I assume you are saying you don't want to hard code it in your Java code. If that is so, then please see below
Answered here:
There are ways to read properties file in Java from weblogic classpath
One (Properties file located in the weblogic domain): Drop the properties file inside the Domain directory. This way the properties file is added to the weblogic classpath automatically and we can read from Java using resourceAsStream.
Two (Properties file from a User defined location):The advantage with this approach is that the property file can reside outside the JAR or EAR file and can be modified conveniently.
package com.test;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;
public class PropertyFileExample {
private static Properties prop;
public static void myMethod() {
InputStream is = null;
try {
prop = new Properties();
String propFilePath = System.getProperty(“propFileLocation“);
InputStream iStream = PropertyFileExample.class.getClassLoader().getResourceAsStream(propFilePath);
prop.load(iStream);
prop.getProperty(“dbuser”);
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
}
In the weblogic setDomainEnv(under bin) we need to pass the location of the property file as a -D argument to JAVA_OPTIONS
set JAVA_OPTIONS=%JAVA_OPTIONS% -DpropFileLocation =/dev/file/properties/some.properties
Hope it helps!
Approach #1
Update your server startup script to pass below system variable to JVM (below is example on Windows OS)
call "%DOMAIN_HOME%\bin\startWebLogic.cmd" "-Dcom.mycompany.myapp.EXTERNAL_CONFIG_PATH=/mycompany/myapp/config" %*
Using this variable which points to your configuration directories, read configurations from there. You will need to make this setting on each server where you want to deploy your application.