File access in a Java project under XCode

Hello again,
I have had another issue: I'm trying to have one of my classes read information from an XML file, whose location is in the same folder as the classes and, indeed, the project (and the .xcodeproj file).
So I give the file's name to the method, but it cannot seem to find the file where I put it; instead, it looks for it in (Project folder)/Build/Debug/.
What should I do? I do not feel it wise to put it into Build/Debug as it is a file that should be deployed along with the rest of the application (when I learn how to make one, that is), but after a little searching around I'm a bit at a loss about that.
Thanks in advance,

This option is normally used for storing preference
files. If you have a number of files then you can
create a folder to hold them. If you have a look
around at the files which are already there (for
other applications) you'll get the idea.
Well, preference files are fine but I don't view them as useful for data.
This folder
is strictly OS X only, but I'll explain there's a way
around that later on.
I failed to catch that explanation, but you might want to leave it at that. No high priority as far as I'm concerned. (Of course, it could be of interest to anyone who finds this discussion - why else are we using a forum, right?)
You can create a bundle from a Java program using
Macintosh HD/Developer/Applications/Java Tools/Jar
Bunder. Again, this is OS X only.
Again, good to know, but not usable now by this developer.
If your program relies on a number files (for example
jpg files for graphics and wav files for sounds) then
these can be added to the jar file. Xcode will do
this for you if you add the file to the project, then
drag it onto the Build Java Resources build phase.
This form of words will extract the file called
stars.jpg from the jar file:
URL f = getClass ().getResource ("stars.jpg");
image = ImageIO.read (f);
Interesting, but the software I'm using as a model of sorts (as far as general design goes from a user point of view) seems to have little in the jar file besides classes. I'd like sufficiently advanced users to be able to access the data files directly (I'll make them nice XML files) but not get into the .jar. Tell you what, I just stumbled on the XML reading class and it seems to be using File.getAbsolutePath(). I must try this.
This works on all Java platforms and so is often
used. There is a standard Unix/Terminal command
called jar which gives you fine control over a jar
file. Type man jar in Terminal for details and more
info about jar files.
Thanks.
6) You think you never mentioned a sixth option?
Well, you did - in that other topic you answered.
You
gave me the idea of fiddling with project
settings.
Be aflaid, be vely aflaid! I have tried to use
$(PROJECT_DIR) instead of $(inherited) in "Build
Products Path" and "Per-configuration Build
Products
Path", but so far to no avail: running throws a
"LaunchRunner Error" = "The main class
"Main_Class"
could not be found."
These are Xcode options and probably won't be of much
value to you.
Well, they are. But I suddenly realize it may work fine and well while in debug, but not so well once everything is compiled and set into a nice application. I'll try this.
BTW. Did you know that a Java program can find out
which platform it's running on? Just call String
opSys = System.getProperty ("os.name");
This enables you to use different solutions for each
different platform.
Actually, I knew about System.getProperty. I've been trying to use it to imitate the Application.Path property from Visual Basic (the language I use most at work), that returns the current location of the application. Does there exist something like that in Java? I've tried System.getProperty with "user.dir", "java.home" and "java.class.path", to no avail: the first gives me Build/Debug (or Build/Release, depending on the build configuration), the second returns the place where you can find Java, in the System/Library structure, and the third yields a looooong path list.
(Still, might be onto something with that File.getAbsolutePath() thingie. I really have to try it.)
Thanks again for the elaboration, helpful as usual and rightly clicked so.
iMac Mac OS X (10.4.8)

Similar Messages

  • Create a new Java project in xcode??

    I wanto kno if I need to install any additional stuff so I can create java projects in xcode, because when I create a new project java doesent appear in the window, the only types I can create are projects for iphone and Mac OS X but I cant find any java project or even compile a Java file when I open it with Xcode

    You should post your quesiton in the Developer forums:
    http://discussions.apple.com/category.jspa?categoryID=164

  • Can a unsigned jar file access the tmpdir (java.io.tmpdir)?

    Hello, according to the JNLP tutor, a signed jar file can access the local file system, but a unsigned one can not. My question is, can a unsigned jar file access the temp directory (the system property java.io.tmpdir)? I think the temp directory should be accessible even though it is part of the local file system.
    Thanks,
    LyLi

    no - unsigned application has no read/write access to the temp dir, but you can use the jnlp api to read and write files with the users permssion.
    see: http://java.sun.com/javase/6/docs/jre/api/javaws/jnlp/index.html for FileOpenService, FileSaveService, and ExtendedService.
    /Andy

  • File access Permissions in Java

    when the user select the file chooser button and browse through the directory in the local file system. If the user chooses any folder and that folder has readOnly access permission then the user can't copy the file into that folder as it has only Read access. So Please tell me how to give file and drive permissions in java on windows.

    File.setReadable() and friends, but "The operation will fail if the user does not have permission to change the access permissions of this abstract pathname." Check the return code.

  • I can't find Cocoa-Java Application after Xcode Version 3.2.1 install..

    Can anyone tell me what happened to all the different Java Applications and Applet selections when File/New Project is selected from Xcode version 3.2.1 64bit? I can't seem to find it. Prior to installing this new version of Xcode, I had full access to all the different Java suites, now I have nothing. Please help, coding seems to compile, I just want to have the choices there for learning purposes. For example:
    Ant-based Application jar
    Java AWT Applet
    Java AWT Application
    Java Swing Applet
    etc.
    Any help would be greatly appreciated.
    I had just read in the Iphone Developer section that:
    +Important: You will need to re-install the iPhone SDK or Snow Leopard if you plan on developing iPhone applications after upgrading your Mac to Snow Leopard and installing Xcode 3.2.+
    Would somebody be able to give me installation instructions on installing the http://developer.apple.com/iphone/download.action?path=%2Fiphone%2Fiphonesdk_3.1.2__final%2Fiphone_sdk_3.1.2_with_xcode_3.2.1__snow_leopard_10m2003.dmg.. It looks like at this point I should have kept the previous version I was using and should have done a custom install. Am I allowed to create a folder called /Developer2 and put an older archived version of Xcode in there? Any help would be greatly appreciated.
    Best Regards,

    ...now I have nothing. Please help, coding seems to compile, I just want to have the choices there for learning purposes. For example:
    Ant-based Application jar
    Java AWT Applet
    Java AWT Application
    Java Swing Applet
    Changed - Apple has this to say about that:
    "The Java templates in the Organizer (Window > Organizer Cmd-Ctrl-O) are still present, however all but one of the Java project templates have been removed.
    The JNI project template is the only Java project template that remains, because it builds a native library. The template has also been re-written to be a full graphical Swing application that calls into the native Mac OS X address book. I'd highly encourage anyone who is interested in JNI development on the Mac to check it out.
    The only additional developer content we ship for Java is the source and javadoc for the JDK itself, and does not include any templates."
    -=-=-=-
    To create Java projects w/Xcode 3.2.1 as an example, you must first open Organizer by choosing Window > Organizer. At the bottom of the Organizer window, you will see three buttons.
    OrganizerBottomBar
    Click the + button on the left and choose New From Template > Java Templates to create a Java project. Click the right button at the bottom of the Organizer to show the editor. Use the editor to write your code.

  • User prefs.Lock file access denied

    Hi,
    Under linux (RH 7.2, kernel 2.4.9-13) w/ JDK 1.4.1-01,
    when I run several of the Swing tutorials (e.g., ListDemo, MenuDemo) and close the window I get this
    error:
    java.lang.SecurityException: Could not lockUser prefs.Lock file access denied.
    at java.util.prefs.FileSystemPreferences.checkLockFile0ErrorCode(FileSystemPreferences.java:926)
    at java.util.prefs.FileSystemPreferences.lockFile(FileSystemPreferences.java:915)
    at java.util.prefs.FileSystemPreferences.sync(FileSystemPreferences.java:723)
    at java.util.prefs.FileSystemPreferences.flush(FileSystemPreferences.java:814)
    at java.util.prefs.FileSystemPreferences.syncWorld(FileSystemPreferences.java:469)
    at java.util.prefs.FileSystemPreferences.access$1200(FileSystemPreferences.java:33)
    at java.util.prefs.FileSystemPreferences$12.run(FileSystemPreferences.java:459)
    I suspect a problem w/ my environment, but am stuck as
    to what. Any advice would be welcome.
    -- marcia

    Every other major application running on your system uses
    the etc directory for it's Preferences... why can't
    Java... The problem isn't that Java shouldn't add requirements for the VM, the problem appears to be that Sun did add requirements, and never told anyone.
    I'm looking at the self-extracting installation instructions for Linux, http://java.sun.com/j2se/1.4/install-linux.html#self-extracting, and nowhere does it state that you must be root in order for the VM to install properly. There is a note about installing to /usr, which you need root access for, but there is no specific requirement that you must be root in order for certain directories to be created properly.
    What about applications that distribute a JVM? Did anyone tell these application developers that their users will have to install their software as root?
    Maybe I'm missing something. If I am, could someone please point me to it?

  • XCode Java project: can't add files

    Greetings all,
    I have a Java codebase which I developed in JBuilder. I now want to produce the final product, a Mac app. To do this I fired up my XCode 2.5. I went File->New Project and chose Java Application under the Java template group.
    Since I don't want the three .java files that the template helpfully puts into the project, I removed them. (The only way to do this seems to be to close the project, go to the Finder, and delete them there, then re-open the project...whatever...) My next task was obviously to add my java files and the three .jar files that they depend on.
    Which is where I ran into problems. It doesn't seem to matter what I do, I cannot get my files properly added to the project.
    I have tried dragging the files from the Finder into the XCode project window and dropping them on the src group icon; despite the fact that the disclosure triangle to the left of the group flashes a lovely shade of pink and then self-opens, when I drop the files there, they do NOT get put into the group; they become siblings of the group instead.
    I have tried right-clicking on the group and choosing Add->Existing Files; same result as above.
    I have tried single-clicking on the group and choosing Project->Add to Project from the menu bar; same result as above.
    I should mention that in all of these three, I do get asked whether I want to copy the file or just have a reference created to it; I always choose not to copy the file (since I want my files to live elsewhere). However, just to experiment, I have just tried Project->Add to Project and asked for the chosen file to be copied...same result as above. The file ends up a sibling of the src group.
    I have also tried removing the src group from the project window and then dragging in from the Finder the entire src folder which holds my Java codebase. It successfully arrives in the project window, but its colour is yellow (whereas the original one's colour was blue) and it never gets compiled. I can't seem to convince XCode that these files are source and should be compiled...despite the fact that if I get out the Info window on any of them, the FileType popup menu states that they are "sourcecode.java".
    I have even tried making an alias to the src folder which holds the codebase, and moving this alias into the XCode project directory in the Finder. This fails to build since XCode tells me that it can't create the directory "src" since one already exists with that name!
    The only way I have found which has any success at all is to actually copy the files and folders into the src and lib folders of the XCode project directory, in the Finder. However, this is not acceptable for either the java or the .jar files. The java files need to be in a certain location for JBuilder, and the .jar files are common files and I am not at all interested in having multiple copies of them floating around on my disk! Furthermore this sort of behaviour should not be necessary with a modern compilation system, especially not one created by Apple.
    Please, can some kind soul tell me, how on earth am I supposed to add existing files to an XCode Java application project, without putting them into the project directory on the disk?
    Thanks gratefully in advance!

    Hi SkiAddict1
    I can't speak for Xcode 2.5, only 3.1...
    The way to add new Java source files is to highlight one of the existing source files (in the src group) and then use File > New File...
    If you want to create a package hierarchy, then you need to use Finder to create the corresponding folders inside src. Once you've done this, then you can create a source file inside a package by highlighting any Java source file, then selecting File > New File... then using the Choose option to specify the correct location. At this point, the main project window doesn't show the newly created file in the folder hierarchy, however next time you restart Xcode it will appear in the right place.
    I think the issue is that the designers of Xcode didn't adequately cater for the Ant tool's use of a src folder and the requirement for nested folders to represent a package hierarchy. However, it's still possible to make do provided you create the folders yourself and always remember to highlight an existing source file before creating a new file.
    Bob
    PS: A neat trick which I find quite handy when porting an existing Java program is to use the boilerplate main class which Xcode creates and use it to call the main () method of the imported project. Eg:
    public class ProjectName {
    public static void main (String [] args) {
    // Call the main method of the imported project
    com.company.project.ProjectClass.main (args);
    }

  • Adding java projects in eclipse instead of jar files

    I have 2 java projects, one is in C:/test/ProjectA and another is C:/test/ProjectB
    Under projectA and ProjectB i have sub projects.
    I mainly work on ProjectB and import the jar of ProjectA in eclipse.
    Now I have removed jar file of ProjectA reference through eclipse and import projects to workspace, added projects under java build path. clean and build project. no compilation error in eclipse.
    when i do this, one of the class file is not getting loaded while server startup:
    07-Sep-2011 09:28:03 org.apache.catalina.loader.WebappClassLoader validateJarFile
        INFO: validateJarFile(C:\project\europa\NOS-OCT-TEST\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\wtpwebapps\ESW\WEB-INF\lib\javaee.jar) - jar not loaded. See Servlet Spec 2.3, section 9.7.2. Offending class: javax/servlet/Servlet.class
        NOS 0    [main] ERROR org.apache.catalina.core.ContainerBase.[Catalina].[localhost].[/ESW]  - Error configuring application listener of class com.bgc.ecm.core.web.listener.Log4jRemappingListener
        java.lang.ClassNotFoundException: com.bgc.ecm.core.web.listener.Log4jRemappingListener
             at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1386)
             at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1232)
    when i add relevant jar file to the project and do a clean build server is getting started as expected.
    But my changes are not reflecting since it is referring old jar file.
    I am using Tomcat server as development environment.
    What i want is instead of refering jar file in eclipse, add projects so that the new changes should reflect the changes without ant build for creating jar file and instead only with eclipse build with source code of the dependent project and run the application.

    847389 wrote:
    I have 2 java projects, one is in C:/test/ProjectA and another is C:/test/ProjectB
    Under projectA and ProjectB i have sub projects.
    I mainly work on ProjectB and import the jar of ProjectA in eclipse.
    Now I have removed jar file of ProjectA reference through eclipse and import projects to workspace, added projects under java build path. clean and build project. no compilation error in eclipse.If you have imported the depended jar, and if its a java project. the eclipse by default refer these while compiling. I mean before using either of the ant script the or build project option in eclipse. And because of this it is not giving error.
    >
    when i do this, one of the class file is not getting loaded while server startup:
    07-Sep-2011 09:28:03 org.apache.catalina.loader.WebappClassLoader validateJarFile
    INFO: validateJarFile(C:\project\europa\NOS-OCT-TEST\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\wtpwebapps\ESW\WEB-INF\lib\javaee.jar) - jar not loaded. See Servlet Spec 2.3, section 9.7.2. Offending class: javax/servlet/Servlet.class
    NOS 0    [main] ERROR org.apache.catalina.core.ContainerBase.[Catalina].[localhost].[/ESW]  - Error configuring application listener of class com.bgc.ecm.core.web.listener.Log4jRemappingListener
    java.lang.ClassNotFoundException: com.bgc.ecm.core.web.listener.Log4jRemappingListener
         at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1386)
         at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1232)
    And when you deploy the build app in tomcat it looks for the dependent jar/classes in lib or classses folder, and as it is not there the error is thrown.
    If you are using ant script then please specify which jar files to load in lib folder.
    when i add relevant jar file to the project and do a clean build server is getting started as expected.
    But my changes are not reflecting since it is referring old jar file.
    I am using Tomcat server as development environment.
    What i want is instead of refering jar file in eclipse, add projects so that the new changes should reflect the changes without ant build for creating jar file and instead only with eclipse build with source code of the dependent project and run the application.If you want this, then write ant script compatible of loading both the jar's.
    Or you can make the ant to prompt the user which jars to be loaded, while building (I suggest this option, rather than loading all the jar's of project A and project B).

  • I m not able to create xml file in Java Project

    hi all,
    I have created one java project just to try with Ant Builder. I have created one class inside it. and now i m creating an XML file inside that project.
    But as soon as i try to create the File -> New -> File and give the .xml extention of the file this gives error into the project.
    Will you suggest me the solution for that?
    Thanks in advance.

    Assuming that you are facing this problem in NDS, here is the solution.
    Go to Windows--> Preferences --> WorkBench -->File Associations
    In the File Types list select *.xml
    This will display the default associated XML editor as
    XML Editor(default) in the bottom list box.
    Click on add button near the bottom list box and select Text Editor, click Ok.You will see one more entry in the list box as "Text Editor".
    Select this entry and click on the default button.
    Click Ok and close the preferences dialogue.
    Now create a new xml file.You wont see the error this time.
    Please note that this will treat all simple xml files you will create as TEXT Files and always open with Text Editor.You can override this behaviour with right click on the file and select appropriate editor from the "Open With" context menu.
    The error you are talking about is because the XML editor tries to check well-formedness and basic syntax rules for the file that you newly created, actually is a noce feature of the IDE.
    Rgds,
    Amol

  • How to create the exe file for java project.

    How to create the exe file for java project.
    am done the project in java swing , i like to create the project in exe format, so any one help for me,
    send the procedure for that.
    thanking u.

    How to create the exe file for java project.Have you ever heard of google? I pasted your exact "question" into a google search:
    http://www.google.com/search?q=How+to+create+the+exe+file+for+java+project.
    and got several useful links.
    Better search terms might yield even better results.
    Sheesh.

  • How to open java files in a java project

    hi ,
    i have to implement a java program analyzer and now i have implement a java parser using javaCC. My parser parse a java file at a time and i have to read and parse all java files in a java project. my idea is to enter
    java project name *.jpx as an input and search java files in project and parse them one by one, or , to enter the folder path of java source files of project and parse them.
    i am a beginer of java language and i don't know where to start to do it.
    is there someone tell me which way is easier and better for my case and some ways to implement it. i search sample files that is similar to my case but i cannot find any.
    thanks in advance.
    ami

    if u don't mind , can u tell me which tutorial i
    should read for that? http://java.sun.com/docs/books/tutorial/essential/io/
    This... for example.
    xH4x0r

  • How can i import dll files in java project in eclipse?

    Hi All,
    How can i import or link dll files in java project in eclipse?....
    dll files contains
    import com.ms.com.ComLib;
    import com.ms.com.Variant;
    import com.ms.com.ComFailException;
    import com.ms.wfc.data.AdoException;
    import com.ms.wfc.data.AdoEnums;
    Any idea of this please tell me.....
    I am using eclipse 3.4 and JRE 1.4
    Is this possible?
    Please tell me!!!!!!!!!!!!!
    Voddapally

    iMovie cannot edit mpg files, unles they come directly from a supported camera.
    I would suggest that you use a free third party app to convert it.
    Get MPEG Streamclip from Squared 5, which is free.
    Drag you mpg clip into MPEG Streamclip.
    Then, FILE/EXPORT USING QUICKTIME
    Choose Apple Intermediate Codec, and save it where you can find it. You should be able to import this file into iMovie, using the FILE/IMPORT/MOVIE command.
    Note: If your file is an MPEG2 clip, you may need to purchase the Apple QuickTime MPEG2 Playback Component from Apple. MPEG Streamclip will tell you if you need this. Don't buy it unless you have to. It costs about $20. You just have to install the component. MPEG Streamclip will use it in the background.

  • Problem accessing variables from java file to JSP page

    Hello Everyone,
    I have small problem accessing my method variables from my java bean file to a JSP page. can some please take a look and tell me why I can't populate my JSP page, I've been trying all day to get this done!!!
    This is my Java file
    package dev;
    import java.io.*;
    import java.util.*;
    public class RoundDetail2
    public String string_gameID;
    public int string_card1;
    public String readDetail_topLayer;
    public static final String SUITS[] = {" ", "Clubs", "Hearts", "Spades", "Diamonds", "Joker", "FaceDown"};
    public static final String VALUES[] = {"Joker ","Ace", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine", "Ten", "Jack", "Queen", "King"};
    public static final String SuitVALUES[] = {" ","1","2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14"};
    public RoundDetail2() throws FileNotFoundException
    DataInputStream inFile=
                 new DataInputStream(
                    new BufferedInputStream(
                   new FileInputStream("C:/apps/jakarta-tomcat-4.0.6/webapps/ROOT/WEB-INF/classes/dev/Data_452SY2.txt")));
    try { 
                 while((readDetail_topLayer = inFile.readLine()) != null)
              StringTokenizer tokenizer_topLayer = new StringTokenizer(readDetail_topLayer,"\t", true);
                   while  (tokenizer_topLayer.hasMoreTokens())
                        string_gameID = tokenizer_topLayer.nextToken();
         catch(IOException e)
                    System.out.println(e.getMessage());
         Thanks KT

    ......How are you declaring the class in your JSP? ... are you instantiating it as a bean using the useBean tag, or just instantiating it in your code like normal.
    Maybe you could post the relevant JSP code too?
    Hello again,
    Only the last string is populating after the file has be tokenized. What I'll like to accomplish is passing the very first string in the file. I did not get too far in the JSP file setup because the code is still in it's testing stage, but any help will be highly appreciated.
    Here is the JSP code
    <%@page import="dev.*" %>
    <%@page session="true" language="java" import="java.io.*" %>
    <jsp:useBean id="wagerhist" scope="request" class="dev.RoundDetail2" />
    <html>
    <head>
    <title>Round Detail</title>
    <body>
      <table width="530" bordercolor="#000000" valign="top">
        <tr>
              <td align="left"  width="19%">Game ID<%=wagerhist.string_gameID%></td>
              <td align="left"  width="30%">  </td>
              <td align="left"  width="20%">card1</td>
              <td align="left"  width="31%">  </td>
            </tr>
      </table>
    </body>
    </html>

  • How to access database file on CDROM from Java Programe??

    Hello friends,
    I am making online exam application.
    I want my question database to be reside on CDROM.
    but i am not getting any idea how to make DSN or static path that resolute the path that i have mentioned for CDROM.
    basically i want to know how to access CDROM from Java Programe????
    Thanks in advance
    Navik Pathak

    Once you mounted the CDROM (something maybe as /media/cdrom) as a file system (or assigned a drive letter to it like D: or F: or whatever), the files are accessible normally.

  • Java - object file access

    how can I access randon to java object file
    thanks

    Can you clarify this question?
    I'm going to give an initial answer, based on a guess as to what you meant:
    BCEL lets you access the internals of a compiled Java class file (aka, the bytecode, aka the object code).

Maybe you are looking for

  • Bursting report error for BI Publisher

    hi all, Following is the error i am getting while bursting a report through the BI Publisher Console Scheduler. Please help. oracle.apps.xdo.servlet.scheduler.ProcessingException: java.lang.NullPointerException      at oracle.apps.xdo.servlet.schedul

  • Have iMatch and added many local mp3's to iTunes library on PC. My goal is to only have music in iCloud with no local copies stored on PC's/iPod/iPad/iPhone. Is this possible?

    After loading many mp3's from local PC to iTunes Libraries and enabling iMatch, iTunes indicates that the track data is being extracted from iTunes database to the cloud and some songs uploaded from my local network store to the cloud. When the song

  • WAD opening error

    Hi guys, "Run-time error 91: Object variable or with block variable not set" I am getting the above error and the WAD isnt opening, The query underneath has a variable processing type authorization, but no authorization for s_rs_bcs, thanks

  • Compatibility with multiple inputs

    i've been thinking about buying a firewire 1814 (made by m-audio), but i'm curious as to whether it will work with LE 7. especially with an intel-based macbook pro. (i've heard bad stories of people buying these devices but they are not intel compati

  • How to fetech n number of rows at one time

    Hi, In my production there is 3 million records data.So its taking long time to diplay the record.So i am thinking of display 100 records at a time.the query is SELECT MDN_NUMBER,STATUS,CUSTOMER_TYPE,PHONE_TYPE,CIRCLE,FIRST_NAME, LAST_NAME,ADDRESS,CI