I have a Glassfish server running in which I configured a JDBC connection pool and a corresponding resource.
I configured them manually with the web interface, but I found that I could have configured them with an XML file as this one with the asadmin tool :
asadmin add-resource file.xml
Now that my resources are already configured, I want to extract this configuration to an XML file with something like :
asadmin get-resource-to-xml $resource_name $xml_filename
Is it possible to do this ? I looked in the list of asadmin subcommands but couldn't found one which would have this behavior ...
EDIT : I read that the information that I need may be in the following file :
glassfish/domains/domain1/config/domain.xml
Indeed, there's a <resources> category but it only contains the default pre-configured resources ...
Ok, even though I configured these resources from the web interface, the GlassFish server was always started by NetBeans, so the configuration information I need was in the NetBeans user directory, here :
$netbeans_directory/8.0/config/GF_4.0/domain1/config/domain.xml
I found the solution in the comments of this solution.
Related
I'm trying to run a java8 app using spring boot version 2.2.4. The app is then packed in a docker image.
The way I run my app as specified in a Dockerfile which ends liek this:
FROM openjdk:8
.....
CMD /usr/local/openjdk-8/bin/java -jar -Dspring.config.location=/opt/$APP/ /opt/$APP/$APP.jar
The problem I encounter is the loading of external properties files.
For example I have application.properties file similar to this, which is packaed inside the JAR:
spring.data.mongodb.host=localhost
spring.data.mongodb.port=27017
spring.data.mongodb.database=db1
application.queue.sqs.queue_name=somesqs
In addition, I also inject the docker image an addition application.properties file located at /opt/myapp/. This external file is similar to this:
spring.data.mongodb.uri=mongodb://username:password#MONGO_URL:27017/db_name
application.queue.sqs.queue_name=another_sqs
Expected Behavior: the app will load both new another_sqs location, and external mongo connection.
However, Actual Behavior: when reading the logs I can see that t the new sqs url (i.e. another_sqs) is loaded properly, although the new value for mongo connection is discarded and is therefore using the local embedded mongo engine.
I consulted the following post on stackoverflow to try and understand what I am experiencing:
Spring Boot and multiple external configuration files
But for my understanding, when using spring 2.X and above, the -Dspring.config.location should override all other properties file.
Here is where I started debugging:
TRY 1 : I attached into the docker container, cd into /opt/$APP/ where both my app.jar and application.properties are located, executed the following command java -jar app.jar and viola - it works! A connection to the external mongo source is established. This may be explained by the priority of spring loading properties files as specified in spring's docs.
TRY 2 : Attach the container, cd into $HOME/, execute java -jar /opt/$APP/app.jar -Dspring.config.location=/opt/$APP/ - Do not connect to external mongo, however does connects to the another_sqs. Strange thing - only part of the application.properties values are loaded? Isn't it the way spring 1.X works by adding value from multiple files?
TRY 3 : Attach the container, cd into $HOME/, execute java -jar /opt/$APP/app.jar -Dspring.config.location=file:/opt/$APP/applicartion.properties - same behavior.
Try 4: Edited Dockerfile to include the following execution:
CMD usr/local/openjdk-8/bin/java -jar -Dspring.config.location=classpath:/application.properties,file:/opt/$APP/application.properties /opt/$APP/$APP-$VER.jar
And it works again. Both another_sqs and external mongo are loaded properly on "Try 4".
My question is therefore:
Why should I explicitly specify the classpath:/application.proeprties? Isn't -Dspring.config.location=/opt/$APP/ or -Dspring.config.location=file:/opt/$APP/application.properties should be enough?
When you specify -Dspring.config.location=file:/opt/$APP/application.properties you're overriding the default value of config.location with your application.properties. If you want to use another application.properties, but still using the default properties without declaring them you should use
-Dspring.config.additional-location=file:/opt/$APP/application.properties
In this way, config.location will still have the default value and you will load the external properties as an additional-location.
From the Spring Documentation:
You can also refer to an explicit location by using the spring.config.location environment property (which is a comma-separated list of directory locations or file paths).
When custom config locations are configured by using spring.config.location, they replace the default locations
Alternatively, when custom config locations are configured by using spring.config.additional-location, they are used in addition to the default locations.
I created a Web Application using Java, JSP,Tomcat via Eclipse.
When running the Application on my Windows development Env, it works fine. database connection is fine (sqljdbc42.jar in Lib via Eclipse) The test db is on my Window development PC
Link: http://localhost:8080/App/
To test the db connection on Production is working right, I have a Java file (not related to my project, but using same db driver and url. It's just for test DB connection on production), it connects to db which is located on production correctly.
However, after I upload my war file (from local development environment) to Tomcat WebApps folder, I got the error in title, the db on production is not connected successfully.
I use the following drivers and url for db connection
drivers=com.microsoft.sqlserver.jdbc.SQLServerDriver
url=jdbc:sqlserver://localhost;databaseName=ABC;integratedSecurity=true
In the above url string, I have tried localhost as above, also tried production IP address, Server name, localhost:1433, localhost\\MSSQLSERVER, all get the same error
I have below in ClassPath in production site:
C:\sqljdbc42.jar;C:\microsoft-mssqlserver.jar;C:\Program Files\Java\jdk1.8.0_201\bin;C:\Program Files\Java\jre1.8.0_201\bin;.
Thank you in advance.
You should check the classloader paths for tomcat server. Regarding the docs, your server will hope finding sqlserver driver jar (sqljdbc42.jar) in the following places:
Bootstrap classes of your JVM ($JAVA_HOME/jre/lib/ext)
/WEB-INF/classes of your web application
/WEB-INF/lib/*.jar of your web application
System class loader classes (described through CLASSPATH environment variable)
Common class loader classes ($CATALINA_BASE/lib and $CATALINA_HOME/lib)
So, best options you can try are:
copying the jar to $JAVA_HOME/jre/lib/ext (#1)
or configuring your build so that, the jar is copied in /WEB-INF/lib/ (#3)
Number#2 is suitable for java classes; does not fit your case.
Number#4 and #5 are more likely for the use of tomcat's own structure, but still it is perfectly legal if you want to put the jar in.
Further Edit: For some reason, there are cases Tomcat may prevent sqlserver driver for the sake of preventing memory leaks. So, if you're sure the jar is on the classpath by applying the solutions mentioned in beforehand this post; you may also try to check with adding the following to server/.xml to disable that leak check:
<Listener className="org.apache.catalina.core.JreMemoryLeakPreventionListener" driverManagerProtection="false" />
We are migrating our application from WAS 6.1 to Liberty. Our application uses third party jars that read property files byInputStream is = ClassLoader.getSystemResource("myproperty.properties").
In WAS 6.1, we set server classpath to the location of myproperty.properties. We tried the below approaches to set classpath in Liberty, but nothing works
Approach 1: Set the below in jvm.options (D:\ConfigFiles\DEV\ - path containing myproperty.properties)
-Djava.class.path=D:\\ConfigFiles\\DEV\\
Approach 2: Setting the classloader in server.xml,
<library id="config">
<folder dir="${server.config.dir}/config/" includes="*.properties" scanInterval="5s"/>
</library>
<enterpriseApplication id="applicationEAR" location="application.ear" name="application">
<classloader privateLibraryRef="config"/>
</enterpriseApplication>
Please let us know if there is any other ways to override/set classpath in Liberty profile?
Try setting this property in jvm.options (instead of -Djava.class.path=path/to/propertyDir):
-Xbootclasspath/a:path/to/propertyDir
This will append the path of the property directory (containing your resource file) to the JVM's bootstrap classpath. Because this is an append, it should also work in Java 9+ (some related options have been removed in Java 9).
I suspect that the reason -Djava.class.path=... doesn't work is that the JVM gets the classpath from the WLP server script - so the system property is essentially applied too late in the startup of the server JVM.
You might also be able to put the properties file(s) in your JVM's lib/ext directory, but I haven't tested that. The -Xbootclasspath/a:path approach works for me on Mac - I assume it will also work on Windows.
HTH, Andy
If your end goal is to load a properties file, a more straightforward way to do this would be using a bootstrap/env/system property or <jndiEntry> in server.xml to store the location of the properties file, and then load it. For example, using an environment variable:
(in server.xml file)
<server>
<featureManager>
<feature>jndi-1.0</feature>
...
</featureManager>
<jndiEntry jndiName="configDir" value="D:\\ConfigFiles\\Dev"/>
</server>
Then, you can load the resource in your application like this:
#Resource(lookup = "configDir")
String configDir;
InputStream is = new FileInputStream(configDir + "/myproperty.properties");
Or, if you will always put your config property files somewhere under ${server.config.dir}, then you can utilize the built-in SERVER_CONFIG_DIR environment variable in Liberty:
String configDir = System.getenv("SERVER_CONFIG_DIR"); // equivalent to ${server.config.dir} in server.xml
InputStream is = new FileInputStream(configDir + "/myproperty.properties");
On the topic of managing configuration, check out MicroProfile Config (e.g. <feature>microProfile-1.2</feature>) which you may find useful: Configuring microservices with Liberty
Apologies if I am posting a duplicate , if so please point me to original question.
I am running a tomee instance. I am configuring my data sources in context.xml and that are being pickup fine. But tomee also creates a HSQLDB datasource by default. And for few transaction it is being picked up and gives me error.
I would like to remove/ disable it from configuration so that it doesn't gives me those false error like:
user lacks privilege or object not found.
And I would be able to see actual issue with my application.
As Gimby said, you should define it in tomee.xml
If you are using eclipse check that your server locations is set to
"use Tomcat installation (take control...)"
and not
"use workspace metadata"
usefull links:
how-to-define-mysql-data-source-in-tomee
MySQL datasource in TomEE
I have a dynamic web application using struts2 that works perfectly.
I have a JDBC application that works perfectly (all it does is print a table out in the console).
After I put the two together all that was left was to add authentication to the run configuration and I'd be done...
I've already put the sqljdbc_auth.dll to the WEB-INF/lib
I've tried to add this line to Tomcat v7.0 Server at localhost
-Djava.library.path="C:\Program Files (x86)\jdbc\sqljdbc_4.0\enu\auth\x86"
but it doesn't do anything
This driver is not configured for integrated authentication.
ClientConnectionId:6495...
It's the line that got my JDBC application working just fine.
Would there be some syntax error I'm missing or another method for me to pass an argument that I'm not aware of?
It looks like you are using the Microsoft SQL Server Driver which is pure java (type 4) so you dont need to mess with java.library.path. Set the Classpath as described here
Alternatively include the jdbc driver in WEB-INF/lib within your WAR file.