Read files from another pc Using JAVA and apache tomcat - java

File[] files = new File("\\172.22.1.77\FolderName").listFiles();
I'm trying to read some files from another IP on my network from shared folder 'FolderName'.
It works locally from eclipse.
But when it deployed on apache tomcat, it doesn't work.
Any help about this ?

Check if the user under which Tomcat is running has permissions to access the folder

Related

Java accessing files and folders in classpath

I am developing an application in Spring-Boot with an embedded tomcat server.
My program downloads documents to the public class path inside the resources folder. Also I am accessing the files downloaded in Iframe tag in HTML, so the file should be in server for me to access it.
When I run the code from my eclipse IDE , it works fine, and I am able to access the files but when I run the war from the command prompt(Since it has an embedded tomcat server) I am unable to locate the folders. Please note that I opened the war and was able to find the folders but the program couldn`t access it.
Any Idea on how to access class resources folder from tomcat embedded war in java? Any help would be much appreciated.
TIA
Try:
ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
InputStream inputDataStream = classLoader.getResourceAsStream("some-file.txt");

Deploying war file on Vesta CP

I am doing this for the first time. I have a VPS server with Vesta CP installed on it. I did the following -
Created a new Web Domain.
It automatically created entries in DNS
I setup FTP user for myself.
I am able to connect to ftp using Fileszilla.
In filezilla, I can see public_html folder (but NOT .htaccess)
Created WAR file from eclipse for my application.
Uploaded my war inside public_html.
tried - http://myserver_ip/MenuBook/HomePageServlet - in browser. It
said 404 Page not found. (MenuBook is the ContextRoot of my web
application)
Can someone please explain what else do I have to do to make this work. I read that you have to modify .htaccess file too, here - https://documentation.cpanel.net/display/CKB/How+to+Deploy+Java+Applications
But I can not see any .htaccess file through ftp.
Please help. Any help will be greatly appreciated.
you must install web server that support java servlets like tomcat or glassfish ... vestacp by default has no just webservers you must install it your self
you can check this link it may help
https://forum.vestacp.com/viewtopic.php?f=11&t=6977

how to read geolitecity file path from linux server?

My development environment is windows, using JSP,Apache server 5.5. I developed an application with the help of geolitecity provided by MaxMind. I have uploaded geolitecity.dat into my server in the same folder of my website(I dont know its the correct procedure, I am doing it first time).And I used
String systemPath=new java.io.File(".").getCanonicalPath();
to get the current directory path, so that I can read from it. But I am not getting the full path. am only getting upto tomcat5.5.3\bin. Is it possible to read the file with this path? I dont have much knowledge in linux.
In Servlet/JSP:
String path = getServletContext().getRealPath("/yourfilename.txt");
This will give you complete path of given file name.
Note: It will work when you will deploy it in tomcat and run from out side eclipse. As eclipse has its own internal structure when it deploy the web application [if not changed].

Create folder in a mapped network drive using Java

I'm trying to create a folder to a mapped network drive Z: using Java
Unfortunately the file is not getting created. This is what I'm doing:
File file = new File("Z:/file1");
file.mkdir();
This code works when not using mapped network drive. This is on Windows environment.
Any ideas?
Ok I figured this out. Tomcat is running under Windows 2003 Server. According to what I found is that when Tomcat is started under the Windows Services, for some reason it doesn't have access to the mapped network drive.
Using UNC paths worked for me.
File myFile = new File("\\\\server\\shared\\input");
myFile.mkdir();
I was able to create a folder on the mapped network drive on that server.

How to deploy a Java Web Application (.war) on tomcat?

I have a .war file of a Java Web Application. Now I want to upload it to my ftp server so that I can execute it.
What steps I should perform to run it?
The context path of the webapp is /mywebapp
Edit
Actually, my ftp server name is ftp://bilgin.ath.cx/ and I have uploaded my TestWebApp.war file to this dir: ftp://bilgin.ath.cx/web
Then what should be the URL to access the index.html page of the webapplication
#2 Edit
Tomcat is listening on 8082
Apache access Tomcat with jk connector.
As others pointed out, the most straightforward way to deploy a WAR is to copy it to the webapps of the Tomcat install. Another option would be to use the manager application if it is installed (this is not always the case), if it's properly configured (i.e. if you have the credentials of a user assigned to the appropriate group) and if it you can access it over an insecure network like Internet (but this is very unlikely and you didn't mention any VPN access). So this leaves you with the webappdirectory.
Now, if Tomcat is installed and running on bilgin.ath.cx (as this is the machine where you uploaded the files), I noticed that Apache is listening to port 80 on that machien so I would bet that Tomcat is not directly exposed and that requests have to go through Apache. In that case, I think that deploying a new webapp and making it visible to the Internet will involve the edit of Apache configuration files (mod_jk?, mod_proxy?). You should either give us more details or discuss this with your hosting provider.
Update: As expected, the bilgin.ath.cx is using Apache Tomcat + Apache HTTPD + mod_jk. The configuration usually involves two files: the worker.properties file to configure the workers and the httpd.conf for Apache. Now, without seeing the current configuration, it's not easy to give a definitive answer but, basically, you may have to add a JkMount directive in Apache httpd.conf for your new webapp1. Refer to the mod_jk documentation, it has a simple configuration example. Note that modifying httpd.conf will require access to (obviously) and proper rights and that you'll have to restart Apache after the modifications.
1 I don't think you'll need to define a new worker if you are deploying to an already used Tomcat instance, especially if this sounds like Chinese for you :)
copy the .war file in the webapps folder
upload the file using the manager application - http://host:port/manager. You will have to setup some users beforehand.
(not recommended, but working) - manually extract the .war file as a .zip archive and place the extracted files in webapps/webappname
Sometimes administrators configure tomcat so that war files are deployed outside the tomcat folder. Even in that case:
After you have it deployed (check the /logs dir for any problems), it should be accessible via: http://host:port/yourwebappname/. So in your case, one of those:
http://bilgin.ath.cx/TestWebApp/
http://bilgin.ath.cx:8080/TestWebApp/
If you don't manage by doing the above and googling - turn to your support. There might be an alternative port, or there might be something wrong with the application (and therefore in the logs)
The tomcat manual says:
Copy the web application archive file into directory $CATALINA_HOME/webapps/. When Tomcat is started, it will automatically expand the web application archive file into its unpacked form, and execute the application that way.
Note that you can deploy remotely using HTTP.
http://localhost:8080/manager/deploy
Upload the web application archive
(WAR) file that is specified as the
request data in this HTTP PUT request,
install it into the appBase directory
of our corresponding virtual host, and
start it using the war file name
without the .war extension as the
path. The application can later be
undeployed (and the corresponding
application directory removed) by use
of the /undeploy. To deploy the ROOT
web application (the application with
a context path of "/"), name the war
ROOT.war.
and if you're using Ant you can do this using Tomcat Ant tasks (perhaps following a successful build).
To determine which path you then hit on your browser, you need to know the port Tomcat is running on, the context and your servlet path. See here for more details.
Log in :URL = "localhost:8080/"
Enter username and pass word
Click Manager App
Scroll Down and find "WAR file to deploy"
Chose file and click deploy
Done
Go to Webapp folder of you Apache tomcat you will see a folder name matching with your war file name.
Type link in your url address bar:: localhost:8080/HelloWorld/HelloWorld.html and press enter
Done

Categories