Solved

how do i import files?

Posted on 2004-08-10
11
195 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
  • 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
NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

 
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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

803 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