[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

how do i import files?

Posted on 2004-08-10
11
Medium Priority
?
200 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 100 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

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…
Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
Suggested Courses

656 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