Solved

how do i import files?

Posted on 2004-08-10
11
198 Views
Last Modified: 2013-11-23
Hi, I'm just starting to learn java.  But I want to be able to import files that are not in the original java library.  I have made a separate folder in which there are some files that I would like to import but I keep getting an error saying that it does not exist.  I'm using comand promt, and I guess I have to set it somehow, but I don't know how.  Please help
0
Comment
Question by:iamnamja
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
  • 2
  • +2
11 Comments
 
LVL 11

Expert Comment

by:bcladd
ID: 11768702
on both the java compiler (javac) and the java interpreter, you need to set the classpath.

javac -classpath directorypath MyClass.java

java -classpath directorypath MyClass

then your import statements should work.
0
 

Author Comment

by:iamnamja
ID: 11768747
Could i just add classpath to the eviornment variables?  So, for example... classpath c:\classes.  Would that work?  Because I have a couple in a different folders and I want to access all of them.  And I tried to do javac -classpath c:\classes, but that doesn't seem to work for some reason and i get errors.
0
 
LVL 11

Accepted Solution

by:
bcladd earned 25 total points
ID: 11768872
List of multiple directories are separated by semicolons.      

From Java's documentation:

The class path can be set using either the -classpath option when calling an SDK tool (the preferred method) or by setting the CLASSPATH environment variable. The -classpath option is preferred because you can set it individually for each application without affecting other applications and without other applications modifying its value.

    C:> sdkTool -classpath classpath1;classpath2...

    -or-

    C:> set CLASSPATH=classpath1;classpath2...

    where:

    sdkTool
        A command-line tool, such as java, javac, or javadoc. For a listing, see SDK Tools.

    classpath1;classpath2
        Class paths to the .jar, .zip or .class files. Each classpath should end with a filename or directory depending on what you are setting the class path to:

            * For a .jar or .zip file that contains .class files, the class path ends with the name of the .zip or .jar file.
            * For .class files in an unnamed package, the class path ends with the directory that contains the .class files.
            * For .class files in a named package, the class path ends with the directory that contains the "root" package (the first package in the full package name).

        Multiple path entries are separated by semi-colons. With the set command, it's important to omit spaces from around the equals sign (=).

        The default class path is the current directory. Setting the CLASSPATH variable or using the -classpath command-line option overrides that default, so if you want to include the current directory in the search path, you must include "." in the new settings.

        Classpath entries that are neither a directory nor an archive (.zip or .jar file) are ignored.

0
The Ultimate Checklist to Optimize Your Website

Websites are getting bigger and complicated by the day. Video, images, custom fonts are all great for showcasing your product/service. But the price to pay in terms of reduced page load times and ultimately, decreased sales, can lead to some difficult decisions about what to cut.

 
LVL 35

Expert Comment

by:girionis
ID: 11770074
Where are the class files you are trying to import and what is your CLASSPATH variable?
0
 
LVL 30

Expert Comment

by:Mayank S
ID: 11770451
0
 

Author Comment

by:iamnamja
ID: 11775156
Well, in c:, i have a folder called j and in there i have many folders some which have more folders, or which have different files that i would like to import.
0
 
LVL 30

Expert Comment

by:Mayank S
ID: 11780650
Example: if your folder C:\FOLDER1 contains a file called File1.class which you would like to use in your program, use:

set CLASSPATH=%CLASSPATH%;C:\FOLDER1

Do you have those files in a package? Or are they in the default package? Did you read the link I posted?
0
 
LVL 3

Expert Comment

by:JohnnyAffa
ID: 11781709
iamnamja,

to save you time from setting classpath everytime you run an app, edit autoexec.bat
to include

set classpath=%CLASSPATH%;C:\classes

that will set your existing class path as well as c:\classes you can add additional classes delimtered by the semi colon ;

by editing autoexec.bat you set you clasapath at bootup. alot less hassle :)
0

Featured Post

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
Viewers learn about the “while” loop and how to utilize it correctly in Java. Additionally, viewers begin exploring how to include conditional statements within a while loop and avoid an endless loop. Define While Loop: Basic Example: Explanatio…

691 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question