So we have a normal batching application that we decided to port over to dropwizard. We want to use dropwizard for lot of benefits that it gives us out of the box like HealthCheck, metrics etc.
We might add some REST admin end points later but right now we are just using DropWizard Managed Service to start our application in a separate thread. We created a sample config yml file but it's mostly just a skeleton.
This porting over is just mostly lift and shift and we want to avoid huge refactor in our code. The application is currently tied with two different properties file and we want to keep it that way.
We have figured a way out to deploy our app using a custom deployer that generates these property files "application.properties" and "system.properties"
For some reason the app can't read those files and is throwing NPE. This is a java application. All the jars are under lib directory and the config files are under config directory. It just doesn't seem to resolve those files. I have tried searching the dropwizard docs but didn't find anything useful.
The code just simply expects the file in a particular directory
private static final String APP_PROPERTIES_FILE = "/application.properties";
File file = new File(DataSourceFactory.class.getResource(filename)
.getFile());
The dropwizard version : 1.2.2
And this is how I'm running the app :
java -cp "deployed/App/lib/*:deployed/App/config/*" com.commercehub.app.MainClass server config.yml
Any comments are really appreciated!
The issue was with my classpath. I didn't need the trailing /* for the config folder.
java -cp "deployed/App/lib/*:deployed/App/config" com.commercehub.app.MainClass server config.yml
Related
I am writing a Quarkus application which reads data over http. In my application.properties file, I have this line:
my.resource=http://path/to/file
Every time I run the app, it has to download the file so I created a smaller version of the file locally for developing purpose. The problem is that I don't know how to put it in the properties file.
Ideally, I want something like this:
my.resource=http://path/to/file
%dev.my.resource=file://${project-dir}/sample_data/file
And I have to use the absolute path because I used new URI(resource).toURL() method which requires an absolute URI.
Thanks in advance.
Application properties is something that is used when your application is deployed to adopt your application to the target environment, does the user of the deployed application know anything about project directory? Project directory is something that makes sense when you are developing your application. having said that using project directory in that file does not make sense at all.
I would like to run a war file on a amazon server several times, each time with slightly different properties like server port or database schema. Right now I have to rebuild for each case... I.e. how can I feed a spring-boot properties file at runtime to a jhipster generated war file?
Edited to clarify:
all I want is to be able to run two or more copies of the same war-file by specifying parameters (port, db name,...) at run time.
The instances are supposed to run on an Amazon system (Linux)
They are started at boot by a service script in /etc/init.d that also is used to start and stop in case of software mods/parameter changes.
As it stands now the application developed using JHipster only reads the file propagated thru the JHipster flow building with Maven (uses the -prod profile)
-Using a separate properties file does not work, it is not read
-Setting properties using -D results in the same: not read
Does anybody have any advise? It looks like JHipster has its own property reader...
To start the application on a different port, you should launch it with additional parameter:
--server.port=8081
or add parameters using -D:
-Dspring.datasource.url=whatever.you.want
or when you need multiple parameters:
-Dserver.port=10000 -Dspring.datasource.url=whatever.you.want
I'm new to Java (around 2 months Java experience after coming from a .Net background). I've been asked to support a Java application which uses Spring, J2EE, and an Oracle database.
We have an issue with our deployment process which I'm struggling to understand.
The Java application in question has database connection details in an application.properties file. Its location appears to be configured from a Spring configuration file using the following line:
<context:property-placeholder location="classpath:config/application.properties,classpath:config/bookings.properties" ignore-resource-not-found="true" />
On our Development Tomcat server, the application (called Bookings) looks in this location for the application.properties file:
/usr/share/tomcat/webapps/Bookings/WEB-INF/classes/config
Which is what I would expect, looking at the Spring configuration.
However, on Production Tomcat, the application looks in a different location:
/usr/share/tomcat/lib/config
(In this directory, the file is called bookings.properties.
The original developer has left the company and I have no idea why it would look in a different location for the file (and a different filename).
Any ideas what I can look at, or where this could be configured? It should be noted that both files (application.properties and bookings.properties) are present on both Tomcat servers, so I don't understand the discrepancy?
We have re-deployed the same WAR file to both development and production, and the discrepancy still exists, i.e. the servers still look in different places.
classpath is a directory where you could put some resources (to make it simple, further details on the link).
that's a variable and it's added to the launch command, sometimes it's a bit hidden. But that's the way it works.
May be you can watch in $TOMCAT_DIR\bin\catalina.sh to see how the classpath is defined.
In your case, the folders contained in your classpath are different between development server and production server. That's totally normal.
However, you say that in production the file is named bookings.properties.
But with this line :
<context:property-placeholder location="classpath:config/application.properties,classpath:config/buyer-request.properties" ignore-resource-not-found="true" />
we see that you never try to load a file named booking.properties.
So ask yourself why the file is called booking.properties. And rename it application.properties to see what happen.
Hope this help
I am making a Java application that uses, Spring, Maven and the AWS-SDK-Java. In order to the AWS SDK to work I have to place the AWSCredentials.properties file inside the "MyProject/src/main/resources" folder.
So far so so good. Then I have to create a .war file. To do that I use mvn install command and voilá.
Now inside the .war created, the file I want to access is in the "/WEB-INF/classes/" folder and I need to read it.
How can I access this file inside the war so I can read its content? I have experimented with ServeltContext but so far nothing I try works!
It is generally not a good practice to keep credential in code package (war). Instead I would suggest you use IAM Roles.
This will make it easy for you to move your code from one AWS account to another (say dev environment to production). Since the code will be submitted to a version control system which will be accessed by many, it is also good from a security point of view to use IAM roles.
I found a way to do it. I can access the file by using:
InputStream inputStream =
getClass().getClassLoader().getResourceAsStream("/resources/email/file.txt");
As explained in this discusison:
Reading a text file in war archive
How can I load the configuration information for hibernate dynamically from a config file. Netbeans currently hard codes that information into an xml file that is then compiled into the jar. I'm a newbie to Java/Netbeans coming from PHP land and am use to a central bootstrap that pulls from a .ini or something similar, but netbeans tends to hardcode this information upon generation of the models,etc in an xml file that is then compiled in the jar. I'm looking for conventional methods of setting up configuration for various client machines using various database configurations. I don't want to have to compile the app on each machine it must be installed on.
The configuration file is read using the Configuration class. By default, it uses the hibernate.cfg.xml file found in the classpath, but you can use the configure method taking a file as parameter, and store the config file on the file system rather than in the jar.
You can also put the static mapping, which never changes between configs, in a file inside the jar, and put the varying config inside an external file. Look at the javadoc for Configuration to know how to add resources and config files to the configuration.