I have a Spring Configuration java file in my project (i.e. with #Configuration annotation). Now I'm creating a bean of SpringLiquibase in this class. The main file of changelogs i.e. db.changelog.xml file is in resources folder. So directly it's accessible from resources folder if I use springLiquibaseObj.setChangeLog("classpath:db.changelog.xml"); method. But when I try to access other xml files from db.changelog.xml file with <include file="src/main/config/db/db.changelog-main.xml" /> I get error that folder and file is not found.
Here, I want to keep db.changelog.xml file in resources folder and all other new changelog files in config folder which should be at same level as resources. The reason for this is, in resources folder, packages are there so folder structure config/1.0.0 is considered as config/1/0/0 which I don't want.
Is there any way to achieve this structure (shown below) with the current set up in my project?
config
1.0.0
db.changelog.201412120101.xml
1.1.0
2.0.0
resources
db.changelog.xml
or
config
1.0.0
db.changelog.201412120101.xml
1.1.0
2.0.0
db.changelog.xml
resources
I found the solution for this. Before this, I had copied the folder src/main/config into src/main/resouces in netbeans so it took that folder as package. So the folder name - config/db/1.0.0 got changed to config/db/1/0/0, but when I created new folder in resources folder, it worked and all the files in folder 1.0.0 are accessible correctly. Now, my folder structure is like this:
resources
config
db
1.0.0
db.changelog.201412120101.xml
1.1.0
2.0.0
db.changelog.xml
I can access db.changelog.xml file from my Spring class as,springLiquibaseObj.setChangeLog("classpath:db.changelog.xml"); and other changelog files from db.changelog.xml file as, <include file="classpath:config/db/1.0.0/db.changelog-201412120101.xml" relativeToChangelogFile="false" />.
Liquibase uses the application classpath, so as long as config is in your classpath you should be able to load them as well.
They would have a path relative to config, so something like "src="1.0.0/db.changelog.201312120101.xml" in your example.
If config isn't in the classpath, you can use the relativeToChangeLog="true" attribute with a src="../../config/1.0.0/db.changelog.201412120101.xml" but having config directly accessible by liquibase is the cleaner option.
Related
I want to deploy (create myapp.jar and from this .jar create myapp.exe file for installer) a java swing application.
I have a some packages:
resource package (net.myapp.ui.resource) inside i have .png, .wav, ... files)
output report package (net.myapp.ui.jasper.output.report) inside i have exported files (report1.pdf, report2.pdf, etc.)
config package (ne.myapp.ui.config) which contain config.properties file which can by updated after app have been installed because this file contain **persistence.xml** properties to create an EntityManagerFactory dynamically depending on the database server info.
From NetBeans IDE i can run app and it's work without problem; but when I build app, a .jar file is created: in dist directory i only have :
--> myapp.jar
--> lib folder
So i'm unable to access config.properties to setup database server IP and other parameters to be used in persistence.xml at runtime.
The question is : How do not put resources, output report, config ... in the classes package tree, but outside and access every resource from code using getResources() or getResourceAsStream() or ClassLoader ?
I want this strucure (after netbeans project build):
dist (folder)
/myApp.jar
/lib/lots-of-jar’s
/config/config.properties
/resources/my_cat.jpg
/output/report/report1.pdf, ...
....
Thank you for your help.
My mysql-data-input.xml looks like:
<dataSource type="JdbcDataSource" driver="com.mysql.jdbc.Driver"
url="jdbc:mysql://localhost/dbname" user="db_username" password="db_password"/>
obviously, it need mysql jar, but I don't know in which directory should I put mysql.jar.
The solr config directory is /aparts/solr-5.5.0/server/solr/configsets/basic_configs/conf, also mysql-data-input.xml is there.
Technically, you can put the dependencies files/Jars any where. As long as you make sure in solrconfig.xml, you added the dependencies to the lib tag so Solr knows where it is.
Here is the solrconfig.xml from techproducts which is one of the built in example project.
Here is a screenshot where I dump mysql connector into the dist folder of solr home and how my solrconfig looks like:
It should be added in the application server's lib folder.
I have been using apache-tomcat and added the same in tomcat's lib folder.
apache-tomcat-5.5.26/common/lib
I use this line :
context:property-placeholder location="classpath*:resources/BLLresources/MQ.properties"
in a spring.xml file to look for MQ.properties which is inside the jar where the xml file is (in config folder at the root level).
I got error :
Caused by: org.apache.camel.ResolveEndpointFailedException: Failed to resolve endpoint: {{uriMesarimReadQueue}} due to: Properties file classpath*:resources/BLLresources/MQ.properties not found in classpath
If I put the properties file outside the jar it works fine.
the jar is in the classpath.
any advice ?
I think your have your references setup incorrectly. In a normal java project the resources folder would be located in src/main/resources, this folder gets mapped to the root of the generated jar file. Therefore, if you had a file src/main/resources/BLLresources/MQ.properties, the mapping would be classpath*:BLLresources/MQ.properties
I created sigleton ApplicationConfig for settigs, that reads xml config file. But every time it fails on path to file.
hierarchy:
META-INF
src
--application
----config.xml
--engine
----ApplicationConfig
web
--WEB-INF
----web.xml
I've tried File f = new File("../application/config.xml"); but it gives C:\WebLogic\application\config.xml
It's usually a bad idea to store your configs in 'src'. It's better to separate your code and configuration. I suggest you to read about maven (or gradle).
Basic maven app has pretty simple structure:
src
--main
----java
----resources
where in 'java' folder you store your code, and in the 'resource' folder you store your configs. And now you have problem, because jvm is trying to find your file relatively WebLogic base folder.
And if you use maven, you could just write:
ApplicationConfig.class.getResourceAsStream("/config.xml")
Of course, in this case you should put your config into 'resources' folder.
I have a openJPA based project that I need to deploy it in format of aar into the following folder under Tomcat.
tomcat\webapps\axis2\WEB-INF\services
But it seems that the service cannot load the persistence.xml file in the META-INF folder within the aar file. I found a solution to rename the aar file into jar, like DummySerivce.aar -> DummySerivce.jar and then put the DummySerivce.jar into the lib folder, to be exactly
tomcat\webapps\axis2\WEB-INF\lib
This time, the persistence.xml could be loaded and the service worked well. But this unnecessarily imported a jar file which was not included in the specification.
So my question is, is there any way to load the persistence.xml from a aar file? is it possible to overload the path of persistence.xml file in code?
btw, only entity information are left in the persistence.xml, database connection parameters are already define in code, and I'm using Axis2.
Thanks!
I have found a solution.
By adding the following line into the services.xml, persistence.xml packed in aar file could be successfully loaded.
<parameter name="ServiceTCCL">composite</parameter>
for detailed info. please refer to http://wso2.org/node/1131
Now checking if there's any side effect.
TCCL - Thread context class loader
default - Status quo, normal behavior
composite - TCCL contains all
jars from environment (say webapp) and those specified in the
service
archive (aar) file under /lib service - TCCL contains all jars from
service archive (aar)