Deployed GWT web application can't find path specified in properties file - java

I have a properties file placed in glassfish3\glassfish\domains\domain1\config, the application can read the values specified but It can't find the specified path on the same server deployed, ex:
Props.properties content is:
FilePath=//192.xxx.xxx.xxx/glassfish3/FolderName
My app throws an error that says file or folder does not exist even it is there.
What is the proper way to do this?

Welp, I solved it by:
FilePath=/root/glassfish3/FolderName

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.

IgniteException : Spring XML configuration path is invalid

Getting the following exception in intelliJ.
Caused by: class org.apache.ignite.IgniteException:
Spring XML configuration path is invalid: example-ignite.xml.
Note that this path should be either absolute or a relative local file system path, relative to META-INF in classpath or valid URL to IGNITE_HOME.
How can i fix it?
Thanks
If your configuration bean's definition has abstract=true parameter, try removing it if it does.
I think, the problem is that example-ignite.xml file has only abstract IgniteConfiguration. This is the case in the default configuration file in examples.
I had this problem. my issue was due existing error in config.xml file. for test, i ignore config.xml from environment variable (-v) and run ignite without it and after i saw that it worked, i figured out that issue is cause that.
i worked with ignite in docker in linux.
I had this problem and fixed with fake solution, , i used config file by internet path and not local file system path. i set config.xml on one domain path (https://example.net/config.xml) and then i set this path for spring xml configuration path.

How to retrieve web application root path in Java

I am coding my Spring MVC based web application (which was deployed with a war file) and trying to get the value of
String rootDir = request.getSession().getServletContext().getRealPath("/");
I am expecting to get
"C:\user\projects\MyApp"
but the actual value is
"C:\user\projects\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\wtpwebapps\MyApp\"
I tried to change Source Folder Output Location in Eclipse, but after that all my jsp files, web.xml and folder \WEB-INF are gone. How can I restore them?
The reason I am asking this is that I want my uploaded images to be saved in "MyApp\webapp\WEB-INF\resources\images\" folder.
Why are you expecting the path to be "C:\user\projects\MyApp"?
Your are running your application using Eclipse and Eclipse is deploying it to C:\user\projects\.metadata\.plugins\org.eclipse.wst.server.core and not running it from project source folder that is why you get "C:\user\projects\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\wtpwebapps\MyApp\" from getRealPath() call.
From ServletContext#getRealPath()
Gets the real path corresponding to the given virtual path. For
example, if path is equal to /index.html, this method will return the
absolute file path on the server's filesystem to which a request of
the form http://://index.html would be
mapped, where corresponds to the context path of this
ServletContext.
The real path returned will be in a form appropriate to the computer
and operating system on which the servlet container is running,
including the proper path separators.
Resources inside the /META-INF/resources directories of JAR files
bundled in the application's /WEB-INF/lib directory must be considered
only if the container has unpacked them from their containing JAR
file, in which case the path to the unpacked location must be
returned.
This method returns null if the servlet container is unable to
translate the given virtual path to a real path.

Tomcat 8 error: invalid character ':' in value part of property

I just started learning Java EE and came across this error when attempting to deploy a WAR file on my tomcat server.
This error happens every time I use the manager application to deploy a WAR. When I select the file located at C:\Users\julex_000\workspace\application\target\application-0.0.1-SNAPSHOT, Tomcat sets it's name as /C:Usersjulex_000workspaceapplicationtargetapplication-0.0.1-SNAPSHOT. It then creates a file called C in the Tomcat8.0\webapps folder and when I try to start the application it fails every time.
The invalid ':' seems to be the colon after C in the path C:\Users\...
I also get an IOException about this:
This error only occurs when using the manager application. When I copy and paste the WAR into the webapps directory it works just fine.
It is simply not allowed to have a : in the context path.
At the deployment you have to pass a valid context path.
For example if you are using the tomcat manager ui:
You have to set the field Context Path and the WAR or Directory URL (the lokal path on the application server where tomcat can find the war file; If you tomcat is not on your localhost you have to move the war file manually and use the path on the server).
If you are using the form with the upload field in the ui, there is no input field where you can pass the context path, but tomcat will use the filename of the war (not the complete path) as context path.
At last but not least if you are using the non-ui-api you can just send your war file with a http put request and pass the url parameter path. You can find more information about this in the Documentation.

Servlet/Tomcat relative file path

Where to put files in a Tomcat Servlet application, such that they are relatively visible to the page??
More detail:
I am developing a servlet page while using an external library. That library depends massively on external loaded XML files (relative file paths). So I need to put these XML files in the running directory of the servlet.
Is there a way in Tomcat server, where files can be accessible relatively?
When a web application is deployed to Tomcat, the root of the web application ends up being $CATALINA_HOME/webapps/YOUR_WEB_APP/
As such, if using a servlet to access an XML file located on a path within the root of your web application, you can just use the following:
request.getServletContext().getResourceAsStream("PATH/TO/YOUR/XML_FILE.xml")
This will load the XML file as an InputStream. Of course, if you want access to the file itself, you can always use the getResource(String resource) method to obtain a URL, from which a File object can be obtained like so (alternative methods included):
File f;
try {
f = new File(url.toURI());
} catch(URISyntaxException e) {
f = new File(url.getPath());
}
EDIT: To make them relatively visible to a web browser, simply keep them out of the ./WEB-INF and ./META-INF directories.
If this library you are talking about is going to search for the file on the classpath (like Hibernate or Log4J would do), you will have to put your XML file in WEB-INF. However, I suggest you do not do this manually. You can put the file in a source directory of you application, which will make sure the file gets deployed on the right spot.
This is an old question. I'm working on Tomcat 9. I've been quite successful with taking the Tomcat installation directory as the base. (CATALINA_HOME) The relative path to a file in ROOT for example is then, "webapps/ROOT/someDir/fileName"
The place to complain about repeated answers is to deal with repeated questions.

Categories

Resources