aspose file tools*
The moose likes Java in General and the fly likes How to use io.File for building a plug-in application Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "How to use io.File for building a plug-in application" Watch "How to use io.File for building a plug-in application" New topic
Author

How to use io.File for building a plug-in application

buntha Choudhary
Ranch Hand

Joined: Jul 03, 2009
Posts: 136

I am building an eclipse plug-in and I am using File simply by File f = new File("some value") which on building eclipse plugin application is getting failed.
It is not able to find any file in that location after building but same is working for stand alone.
How to resolve this scenario.
Steve Luke
Bartender

Joined: Jan 28, 2003
Posts: 4181
    
  21

The most likely cause is an assumption on what the 'active directory' is. After you launch eclipse the active directory could be anything from the directory where the eclipse.exe resides, some /bin folder in the eclipse directory structure, or somewhere in you eclipse workspace. You should define the file as relative to some better known / constant location rather than relative to the current directory. What location to use as the reference point depends on a lot of different things (like where the file is, what variables you have access to which will give you that reference).


Steve
buntha Choudhary
Ranch Hand

Joined: Jul 03, 2009
Posts: 136

Steve Luke wrote:The most likely cause is an assumption on what the 'active directory' is. After you launch eclipse the active directory could be anything from the directory where the eclipse.exe resides, some /bin folder in the eclipse directory structure, or somewhere in you eclipse workspace. You should define the file as relative to some better known / constant location rather than relative to the current directory. What location to use as the reference point depends on a lot of different things (like where the file is, what variables you have access to which will give you that reference).


How can I verify the constant location. What are the steps I should take to resolve this.
I am getting the nullpointer exception because of no files in directory-

dir bundleresource:\2212.fwk5184781\com\lg\hemp\menu\requirement\menuFile\LG_BBTV_Spec.v1.0.7
Above is the directory recorded by the application
buntha Choudhary
Ranch Hand

Joined: Jul 03, 2009
Posts: 136

I've tried to use

ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
URL url = classLoader.getResource(dirName);
File file = null;
try {

file = new File(url.toURI());
} catch (URISyntaxException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}


But now on standalone application, it is working fine but on Run as Eclipse Application , it is throwing -

Exception in thread "AWT-EventQueue-0" java.lang.IllegalArgumentException: URI scheme is not "file"
at java.io.File.<init>(Unknown Source)

buntha Choudhary
Ranch Hand

Joined: Jul 03, 2009
Posts: 136

I tried the following ways-
Suppose , I have a package as -
Package - com.test.abhishek.file.java.TestWork.java
Directories - com.test.abhishek.file.java.Dir1
com.test.abhishek.file.java.Dir2

Now in TestWork.java-
InputStream is = LGHelpContentView.class.getResourceAsStream("/"+dirName);

The above line is getting failed.
How should I keep my directory and where so that it will run as an eclipse plug-in as well.
buntha Choudhary
Ranch Hand

Joined: Jul 03, 2009
Posts: 136

Tried to find the class path by
**TestWork.class.getClassLoader().getResource("").getPath()** and getting the output as **/**
So now where should I dump my directories to ressolve.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38818
    
  23
Too difficult a question for "beginning". Moving thread.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to use io.File for building a plug-in application