How to upload resources files with app to cloud foundry - java

My project needs to read several files as resource (krb5.conf, truststore, keytab). they are in project directory. e.g. C:\Users\WorkSpace\MyProject\krb5.conf.
However, when I upload my project to cloud foundry, the app cannot find my resource files when running.
This is my first time deploy app on cloud foundry. Is there anyway to upload resources files like text file, image jpg to cloud foundry with project? so app can read those files when running on cloud foundry

When you cf push an application, the cli will upload all files under the specified path. By default, the path is the current directory. You can set a custom path with --path or -p.
The --path and -p argument may also point to zip files or jar files, for Java apps. In that case, the contents of the archive are uploaded.
The only exceptions:
Files listed here.
.cfignore
_darcs
.DS_Store
.git
.gitignore
.hg
manifest.yml
.svn
If you have a .cfignore file (same syntax as .gitignore), anything matched is not uploaded.
To troubleshoot issues:
Check your path. Make sure it's correct and includes your files.
Make sure the files are not being ignored.
Run cf ssh to your app and check if the files exist.
Ensure you're using the correct path to files in the container, use $HOME or /home/vcap/app which are the root for your application files.

Related

Upload file to payara5 docroot

I've installed payara5 on ubuntu and going to upload file to docroot.i need to know if there is such a capability in payara
Payara doesn't support uploading individual files. It's an application server and supports only uploading whole application packages.
But you can upload files to the docroot manually, e.g. using FTP or SFTP. If you place your files to glassfish/domains/domain1/docroot, they will be served from the root context. E.g., if you upload a file image.jpg to that directory, it will be accessible at http://host:8080/image.jpg

what's the ideal way to store files in spring boot application?

I am working with one spring boot maven application, so here on registration form customer has to upload two documents.
License
PAN card.
so these documents i am storing on physical location and path i am keeping in DB.
So to store License i have created one folder customerLicense under proejct root folder parellet to POM and for PAN card also i created customerPANcard folder on same location parellel to POM.
and in yml file i have made entry for path, so in code i am reading folder location and storing documents.
application:
customerLicensePath: /customerLicense
customerPANPath: /customerPANcard
So to build the project i run command mvn clean install under the root folder where POM is there. then target folder generated and to run the war i run command java -jar ./target jarName.war that command also i run from root folder.
i don't go inside target because those folder where i am keeping documents that are under project root folder, if i run war file from target folder then will not be able to access those folders.
Here my question is :- Now if i give this war file to client , so first client has to create two folder manually to store documents otherwise he will get error in file upload.
Do we have option like that client don't have to do anything he will only run war file and automatically these folder should get created ?
A few things.
You don't want to put things 'parallel' to the pom.xml. Do this instead:
projectRoot/src/main/java/uniquePackageNameHere/ // all your code in here
/pom.xml
If you want the client to provide the files themselves, simply accept the path at runtime. Something like java -jar jarName.jar -license /path/to/license -pan /path/to/pan (use Apache Commons-cli or something)
If instead you want to provide the files, then include them in the resources folder of your project:
src/main/resources/customerLicense
src/main/resources/customerPANcard
then, in your code, refer to the files by calling:
Main.class.getClassLoader().getResourceAsStream("customerLicense")
Main.class.getClassLoader().getResourceAsStream("customerPANcard")
This will make it such that wherever the code is run from, your program will always go in resources to find them.

Java application with simple Web Server exported as JAR

I have created a simple Web Server application using Java APIs.
Web server is working as expected and I am able to get the HTML pages in the browser.
I am developing this Java App on a Windows Machine. For testing I am exporting my app as JAR and then testing it on Target Device which is a Linux Box. In my app I have created a "webroot" folder and I am storing all the HTML files, that web server needs to serve.
So when I create JAR file of the app then it has "webroot" folder with all the html files in it. When I run this application on Windows then I am able to get the html pages. But when I run this application on Linux box as a JAR then I am not able to retrieve html files. Also when I copy my "webroot" folder outside the JAR then it works and I am able to see the HTML pages getting delivered in the browser.
So is there any way I can access html pages which are in the jar file itself without copying them outside?
My Project Folder structure is as below:
/src
-com.myprj.server -> contains server Java files
/webroot -> all the html pages
/bin -> jar files as per the above package path
/myprj.jar -> Project jar file
So above jar file has the webroot folder. And from the code I am accessing it as "webroot/FileName.html". If I keep webroot as in the same folder as jar then it does work.
Without seeing how you're actually serving the content, it's hard to say what you're doing wrong, but you can always use Class.getResourceAsStream() to access the resources from the classpath. If you're running it as a jar file, then the contents of the jar file are included in the classpath too.
To serve content outside of the jar file, either include your "webroot" in the classpath, or create some kind of mechanism to first try the classpath and then an outside path.

What am I not understanding about hosting a Java web app?

I am new to Java and I am trying to host a Java web app using Firebase.
Problem
My problem appears to be that my index.html file does not exist in my Java file structure. Therefore, I can not "point to it" in my firebase.json file.
Question
What am I not understanding about how to host a Java web app?
Do java web apps have an index.html file when they are deployed (which, apparently, Firebase requires)?
What can I do to successfully host my Java web app?
Firebase hosting setup instructions:
SETUP & INSTALLATION
First Time Installation
You should have Node.js installed (you do not need to run Node, just have it installed)
$npm install -g firebase-tools or $sudo npm install -g firebase-tools
Updating Previously Installed Firebase Tools
$npm update -g firebase-tools or $sudo npm update -g firebase-tools
DEPLOY YOUR WEBSITE
$cd into your website directory and run $firebase init
Then deploy your website with $firebase deploy
My error message:
When I follow the hosting instructions and browse to https://my-example-firebase.firebaseio.com/ I get the following error message.
Page Not Found
This file does not exist and there was no index.html found in the current directory or 404.html in the root directory.
Why am I seeing this?
You may have deployed the wrong directory for your application. Check your firebase.json and make sure the public directory is pointing to a directory that contains an index.html file.
My firebase.json
{
"firebase": "my-example-firebase",
"public": ".",
"ignore": [
"firebase.json",
"**/.*",
"**/node_modules/**"
]
}
As you can see, my firebase.json file assumes my root directory is my public directory. However, that does not contain an index.html file. Therefore, this is what I think I am missing about the structure of a Java web app and file structure. There IS NO index.html file.
My file structure
(as scaffolded by Eclipse) (partially) looks like the following.
root
Deployment descriptor: myproject
JAX-WS Web Services
Java Resources
Javascript Resources
build
src
com.example.myproject
MyprojectUI.java
MyprojectUI
test
libraries
WebContent
ivy.xml
ivysettings.xml
I looked all through it and there is no index.html file. I'm wondering if I need to maybe compile something into HTML and Javascript? Then serve that file? I'm lost and confused. Please somebody help.
Firebase Hosting is for hosting static assets only, so HTML, JavaScript, CSS, images, etc.
Firebase Hosting cannot be used to run your Java web application.

How to download zip file from tomcat server web app location

I am working on ios project. One of the module in that project download *.zip files and extract them into app memory. on the server side I installed tomcat server, and uploaded all *.zip files and some *.txt files to the context path.
But when I call the *.txt file's it's working fine (I am getting text on app and browser) but when I call *.zip's file I got 404 (the requested resource is not available). the url is correct but it's only working for .txt files and some extension files.
I think it's blocking .zip files for security reasons. But I need zip file need to downloaded.
if the .zip files is outside the server webapps path its need to be added on context path (and dir path), and reload the server solves the problem.

Categories

Resources