Reputation: 186
My program has a RMI folder in SRC catalogue. I want to pack the program to JAR. How to obtain the folder path in this catalogue?
Upvotes: 3
Views: 844
Reputation: 186
I found a resolution by obtaining the relative path of System.getProperty("user.dir")
Upvotes: 0
Reputation: 562
get file path under class path: for example,there is a file in jar a\a.log you can get absolute path through the following ways:
Thread.currentThread().getContextClassLoader().getResource("a\a.log");
if get flow:
Thread.currentThread().getContextClassLoader().getResourceAsStream("a\a.log");
other several ways
1、get the resources of current class
MyServlet.class.getResourceAsStream(name)
2、get Classpath resource
Thread.currentThread().getContextClassLoader().getResourceAsStream(name)
3、how visit in Servle?t access web application of resources
ServletContext context = this.getServletContext();
String catalogFileName = context.getInitParameter(“catalogFileName”);
InputStream is = null;
BufferedReader catReader = null;
try {
is = context.getResourceAsStream(catalogFileName);
catReader = new BufferedReader(new InputStreamReader(is));
Upvotes: 2
Reputation: 735
If you are using eclipse then right click on the desired file then click Export..Once clicked you will get option to export as JAR file..Hope this helps..
Upvotes: 2