NOTE: I cannot package them into an EAR. Some constraints here.
I have 2 war files.
help.war and helpConnect.war
Both are placed in the same domain of GlassFish server.
From the index page of help.war am accessing a page in helpConnect.war like this..
Help Internal
This isn't working because when I try to access on the server, the URL its trying to access is like this..
http://localhost:8080/help/helpConnect/HelpInternal/index.htm
However, since helpConnect is a totally different war file I need the URL like this
http://localhost:8080/helpConnect/HelpInternal/index.htm
Any idea how to get this around?
You're using a relative path. You need an absolute path:
Help Internal
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'm developing a web service using axis2 & tomcat . There I use a data.xml file to store some information. When I give the Absolute Path for the data.xml file, everything works fine. But I am looking for a way to give the file path in relative to the source file. To achive that I have tried several methods.
(the deployed aar file is located under C:/tomcat/webapps/axis2/WEB-INF/service.aar )
This is my folder structure.
+Project
|-src
|-data
|-data.xml
I have added the data folder to the build path.
I have tried to include the file as ./data/data.xml
But it failed. Can anyone suggest me a best/recommended way to do this?
-Regards
After a long research, I found that it is impossible to do it. It should be a absolute path for the xml file.
I'm developing a simple mail sender as Java EE application.
The project structure is shown as follows:
To properly setup email contents, I need to read the *.vm files placed inside the resource folder, that I supposed to have as path classpath:/templates/mail/*.vm (as with Spring)... But my supposition is wrong!
Which is the right path to use?
Should I have to use the META-INF folder? Is this solution more
java-ee-compliant? In that case, where have I to put the META-INF folder inside my project structure?
Update:
I packaged the project as .war, then I putted the files in:
/src/main/webapp/WEB-INF/classes/templates/mail/
Then:
org.apache.velocity.Template t = myVelocityEngine.getTemplate("classpath:/templates/mail/account_to_confirm.vm",
"UTF-8");
Nonetheless, the app returns an error at runtime:
Unable to find resource 'classpath:/templates/mail/account_to_confirm.vm'
What am I doing wrong?
Just to better understand:
Supposing that I'd like to deploy this app as jar (removing the servlet class, of course): in that case, should I have to edit the folder layout in order to still use the same path into the source code?
I think the problem is due to the prefix classpath:: where did you find that you have to use it?
You might find useful understanding how to initialize VelocityEngine reading Loading velocity template inside a jar file and how Configuring Resource Loaders in Velocity.
If you can, use Classloader.getResourceAsStream("templates/mail/*.vm"); or similar getResourceAsURL method.
If not, take a look at where files from resources are placed inside WAR. In your case, the file should be in /WEB-INF/classes/templates/mail .
I am working on web application.I invoke on my jsp request.getContextPath(), but strangely I got address /streetshop.
Then I am appending some path as request.getContextPath() + "abc" and create folder.
Then its creating folder in D:// instead of my webapplication folder.
Please, tell me, I want to upload an image in put it in my web-application root/images/images.gif.
You mix things up here. HttpServletRequest.getContextPath() returns your web application root path. In your example this is /streetshop, so your URL may look similar to www.myapp.com/streetshop. If you want to access the internal file system path, you must obtain it from the ServletContext using request.getServletContext().getRealPath("/"). This should return the location of your WAR files' WebContent folder.
Keep in mind that if you modify contents of this path during runtime, you're going to loose everything when redeploying your application.
I am trying to create a PDF file using struts 2.Action class location is as follows.
/home/Jagan/MATCH/Jagan/src/ActionClasses/PDFFile.java
Here workspace starts from
/MATCH
In PDFFile.java.I am writing as given below and it is working fine.
pdfwriter=PdfWriter.getInstance(document,new
FileOutputStream("/home/Jagan/xyz.pdf"));
But i have to create this under the folder
/home/Jagan/MATCH/Jagan/PDFs
I should not use /home/Jagan/ as it will become hardcode if i have to run this application in other system.
I tried
pdfwriter=PdfWriter.getInstance(document,new
FileOutputStream("../../../PDFs/xyz.pdf"));
But it is not creating file.Even if it works it is not feasible solution (because "../../../" does not work in windows ).
Please suggest me a good way to specify path for creating file.
Adding to the question.
I have to provide download option for downloading this created file in JSP page.Which struts tag should i use. Please provide me syntax for that
downloading files has 2 aproaches:
1. you can return it with outstream result like is explained here
2. as you are trying to save the file first at filesystem then access it from another url.
Answer to your question is you should get servletContext.getRealPath("/WEB-INF"), and after that everything is relative to WEB-INF.
I should not use /home/Jagan/ as it will become hardcode if i have to run this application in other system.
Correct, Use following instead
System.getProperty("user.home");///home/Jagan/, it will return you path to your home dir