META_INF contents different in jar and war? - java

I'm trying to use the appassember plugin to create an embedded tomcat using the heroku howto, with tomcat7 and oracle-java-7.
I've used these instructions a number of times to convert a working war file with no problems.
The current project is a spring-batch-admin console with a single runner underneath. I'm not the code owner, and not-so-familiar with spring-batch, but it seems happy to be dropped into a 'normal' /var/lib/tomcat7/webapps.
When launched with the auto-generated shell scripts (sh ./target/bin/webapp), I get the following error:
ERROR - DispatcherServlet - Context initialization failed
org.springframework.beans.factory.parsing.BeanDefinitionParsingException: Configuration problem: Failed to import bean definitions from URL location [classpath*:/META-INF/servlet/*.xml]
Offending resource: URL [jar:file:/vagrant/pairbulkdata_app/downloadjob_batch/target/repo/org/springframework/batch/spring-batch-admin-resources/1.0.0.M1/spring-batch-admin-resources- 1.0.0.M1.jar!/org/springframework/batch/admin/web/resources/servlet-config.xml]; nested exception is org.springframework.beans.factory.parsing.BeanDefinitionParsingException: Configuration problem: Failed to import bean definitions from relative location [../batch/module-context.xml]
Offending resource: URL [jar:file:/vagrant/pairbulkdata_app/downloadjob_batch/target/repo/org/springframework/batch/pbdDownloadXmlConfig/1.0.0.M1/pbdDownloadXmlConfig-1.0.0.M1.jar!/META-INF/servlet/service-context.xml]; nested exception is org.springframework.beans.factory.BeanDefinitionStoreException: IOException parsing XML document from URL [jar:file:/vagrant/pairbulkdata_app/downloadjob_batch/target/repo/org/springframework/batch/pbdDownloadXmlConfig/1.0.0.M1/pbdDownloadXmlConfig-1.0.0.M1.jar!/META-INF/servlet/../batch/module-context.xml]; nested exception is java.io.FileNotFoundException: JAR entry META-INF/servlet/../batch/module-context.xml not found in /vagrant/pairbulkdata_app/downloadjob_batch/target/repo/org/springframework/batch/pbdDownloadXmlConfig/1.0.0.M1/pbdDownloadXmlConfig-1.0.0.M1.jar
at org.springframework.beans.factory.parsing.FailFastProblemReporter.error(FailFastProblemReporter.java:68)
Which seems to imply that it isn't finding the servlet-config.xml file.
The interesting thing, when I go peek into the new myApp.jar vs the old myApp.war files, the contents of the META_INF file have been moved around.
The relevent parts of the original war is:
\META-INF\maven
\WEB-INF\classes\META-INF\stuff-to-launch-the-servlet
In the fat jar, I'm getting:
\META-INF
|-----> maven
|-----> stff-to-launch-the-servlet
and WEB-INF doesn't seem to be baked in at all.
Since the class it can't find is in the stuff that got moved around, I'm heading down that rabbit hole.
Why does the jar file include the META-INF at a different path? The original configuration is on the filesystem, because this isn't a onejar, and should get picked up from the CLASSPATH, correct?

Related

RabbitMQ JAVA Spring Configurations - spring.rabbitmq.ssl.key-store

I am trying to connect my Spring application to a RabbitMQ server.
I have in my src/main/resources folder an application.properties file containing the following properties:
spring.rabbitmq.port=port
spring.rabbitmq.username=user
spring.rabbitmq.password=pass
spring.rabbitmq.host=hostname
spring.rabbitmq.ssl.verify-hostname=true
spring.rabbitmq.virtual-host=virtualHost
spring.rabbitmq.ssl.enabled=true
spring.rabbitmq.ssl.algorithm=TLSv1.2
spring.rabbitmq.ssl.key-store=client-file
spring.rabbitmq.ssl.key-store-password=client
The "client-file" is also in the same directory - src/main/resources. However, when I build the application - I recieve the following error:
Factory method 'rabbitConnectionFactory' threw exception;
nested exception is org.springframework.amqp.AmqpIOException: java.io.FileNotFoundException:
class path resource [client-file] cannot be opened because it does not exist
My file is not being recognized... I might need to have some full path, but am not sure what it should look like. Any help would be greatly appreciated!
Try like this:
...
spring.rabbitmq.ssl.key-store=classpath:/client-file
spring.rabbitmq.ssl.key-store-password=client
I did put mine in the resource folder '..\src\main\resources'.
use file:file_path if you are placing the file on a directory location(or a mounted drive) outside your app.

Where should I put the application.properties file when deploying an app in Apache Tomcat?

I am currently deploying a .war file on Apache Tomcat.
I have already finished setting up the database, and the ROOT.war file is already deployed on /opt/tomcat/webapps/.
The ROOT.war file that I have been assigned to deploy also came with an application.properties file.
What I did was put the application.properties file on the root of the ROOT folder. Like this:
Now, it's currently not running.
And when I try to start it, the Tomcat Web Application Manager throws this error:
FAIL - Application at context path / could not be started FAIL -
Encountered exception org.apache.catalina.LifecycleException: Failed
to start component
[StandardEngine[Catalina].StandardHost[localhost].StandardContext[]]
What I did next was check the logs located in /opt/tomcat/logs/catalina.out
This one line made me hunch that the problem is that the location of my application.properties file.
2020-03-06 11:42:15.978 WARN 4219 --- [io-8080-exec-27]
ConfigServletWebServerApplicationContext : Exception encountered
during context initialization - cancelling refresh attempt:
org.springframework.beans.factory.BeanDefinitionStoreException: Failed
to parse configuration class [asia.edusuite.sample.Application];
nested exception is java.lang.IllegalArgumentException: Could not
resolve placeholder 'property.location' in value
"file:${property.location}/application.properties"
Where do you think I should put the application.properties file?
Thank you very much!
-JeremyC
The locations Spring will look for application.properties are defined in the docs.
Files in WEB-INF/classes are in the root classpath and should be discoverable unless your code is specifically looking somewhere else. If you don't have the source, why not decompile the class to see what's going on? (There are lots of them out there including one that comes with Intellij - you can just open the .class file.)

Spring can't load xml configuration file

This error blows my brain. All the junit tests is fine but when my application loads as plugin for another application I have an errors. The beans.xml is 100% at root of jar file but for some reason the main application, that loads my plugin can't find the file. Why?
In my application's boot method I call
new ClassPathXmlApplicationContext("beans.xml"); throws
org.springframework.beans.factory.BeanDefinitionStoreException: IOException parsing XML document from class path resource [beans.xml]; nested exception is java.io.FileNotFoundException: class path resource [beans.xml] cannot be opened because it does not exist
or
new FileSystemXmlApplicationContext(getClass().getClassLoader().getResource("beans.xml").getPath()); throws
org.springframework.beans.factory.BeanDefinitionStoreException: IOException parsing XML document from URL [file:/C:/path/to/my.jar!/beans.xml]; nested exception is java.io.FileNotFoundException: C:\path\to\my.jar!\beans.xml (The system cannot find the path specified)
UPD: The problem was the application uses custom classloader that does not load resource files in root, META-INF and etc. but only classes
The FileNotFoundException that you get really points out that the beans.xml file is not in your jar at the place where you think it is. I would have a look inside that jar. You can for example open the jar with the 7-zip tool. I find that this provides useful insight when you get errors like the one you report.
If you're getting the FileNotFoundException it is because the file is not located where you're looking for it. The beans.xml file must be located in src/main/resources

Eclipse not able to find Spring configuration file

I am wetting my hands in Spring and using Eclipse along with Spring. I have written a very simple Spring application with eclipse to inject a property in a bean. However, when I am running my application, Spring is throwing exception and it seems that the Spring is not able to find the Spring configuration file. Below is the stacktrace --
INFO: Loading XML bean definitions from class path resource [Beans.xml]
Exception in thread "main" org.springframework.beans.factory.BeanDefinitionStoreException: IOException parsing XML document from class path resource [Beans.xml]; nested exception is java.io.FileNotFoundException: class path resource [Beans.xml] cannot be opened because it does not exist
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:341)
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:302)
I have tried the following -- Give the full path in the ClassPathXmlApplicationContext method like --
ApplicationContext context = new ClassPathXmlApplicationContext("C:/Users/devshankhasharm/workspace/FinalPowerShell/src/src/main/Beans.xml");
I have also updated the ClassPath variable in windows to add the path for my spring configuration file. But nothing worked. Any idea would be highly appreciated.
Try this
ApplicationContext context = new ClassPathXmlApplicationContext("classpath*:Beans.xml");
And of course your Beans.xml must be in classpath.
Update or maybe
ApplicationContext context = new ClassPathXmlApplicationContext("file:src/main/Beans.xml");
Beans.xml should be in classpath. You cannot give full physical path of xml file for ClassPathXmlApplicationContext . Please check if Beans.xml is there in build path of eclipse.
As you are using a full filepath for your Beans.xml example, use
ApplicationContext context = new GenericXmlApplicationContext("C:/Users/devshankhasharm/workspace/FinalPowerShell/src/src/main/Beans.xml");
BUT it is not recommended to do this. Use the ClassPathXmlApplicationContext for this instead.
Then move Beans.xml into the classpath. The simplest way to do this is to move it to the root of your java source if not using Maven or src/main/resources if using Maven
If it's not much of a bother then try using Spring Tool Suite. It's a Spring friendly IDE based on Eclipse, so that you don't have to depend on spring/maven plugin configurations. All you have to do is go and create a Spring Project instead of Java project and rest all the settings will be handled for you.
If you are using Spring Tool Suite (STS), it may be the case that when you create a Maven project the src/main/resources directory was configured with "Excluded: .". In other words, STS sets your src/main/resources directory to have all its contents excluded from output by default.
How to fix it:
Project properties (Alt+Enter) -> Java Build Path -> Source
On src/main/resources, you may see "Excluded: ."
Select this item and click on Edit...
Remove the . exclusion pattern
Click OK. Voila!

Where to put a local xsd file in Jboss 4.05

I am working on Jboss 4.05 , I have an xsd file that was on jboss.com and want to have it locally on my system, I can not find the right location to put this file, when starting the jboss I get this error:
Offending resource: class path resource [spring/my-context.xml]; nested exception is org.springframework.beans.factory.xml.XmlBeanDefinitionStoreException: Line 75 in XML document from class path resource [spring/my-ranking-context.xml] is invalid; nested exception is org.xml.sax.SAXParseException: cvc-complex-type.2.4.c: The matching wildcard is strict, but no declaration can be found for element 'seam:instance'.
the problem started when jboss.com went down, i located the relevant xsd and downloaded it. i have tried putting it in the bin directory of jboss and also on the lib directory under the server to no avail.
thanks in advance,
Dov
I think the xsd needs to be in the class path.
It's the server that needs it then make sure the path to the file is in the Jboss start up classpath. You can change the startup classpath in the run.bat or run.sh file.
If the probem is with a deployment then the file needs to go in that deployment's classpath.
ex: for my axis deployment the xsd would be in the classes directoy.
jboss-4.0.2\server\default\deploy\axis.war\WEB-INF\classes

Categories

Resources