Importing a class in a project

Hi. I wrote a class I would like to use in many projects. I've never had such a need, so I don't know whether it is possible or not to import it or not. I would like to place this class in a directory, and leave it there. Then, when writing some other classes in which I need that one, is it possible to import it without having to place it in the same directory every time?
Thanks for any hint.

I can't understand what I'm doing wrong. I created the jar file. Every class inside the jar has a line with inside:
package os;in the dir where I have all the classes which are inside the jar file everything seems to compile ok:
javac *.javaThen, I created the jar, and tried this:
javac -jar jarfile.jar ClassName.javabut this parameter -jar doesn't exist. Then, from manual, I saw this parameter and tried:
javac -classpath jarfile.jar ClassName.javabut I get this error:
ClassName.java:1: package os does not exist
import os.*;
^
oslib.jar(Semaphore.java):15: class Semaphore is public, should be declared in a file named Semaphore.java
(source unavailable)
ClassName.java:7: cannot access Semaphore
bad class file: oslib.jar(Semaphore.java)
file does not contain class Semaphore
Please remove or make sure it appears in the correct subdirectory of the classpath.
      Semaphore s = null;
      ^
3 errorswhere oslib is jarfile, Semaphore is a class inside the jarfile and os is the package name I used.
Do you know what could I've been done wrong?
Many thanks for yuor help.

Similar Messages

  • How to import classes into labview project?

    Hi everyone 
    I start objected oriented program with labview, I have two sample project and I want to import their classes into my new project? is it possible to do that ? how can I import them ?
    thanks 

    You can simply add them like you would any other VI or library. I would recommend creating a virtual folder for your classes so you can keep your project organized.
    Mark Yedinak
    "Does anyone know where the love of God goes when the waves turn the minutes to hours?"
    Wreck of the Edmund Fitzgerald - Gordon Lightfoot

  • Importing a class from another context?

    Hi JSP techies,
    Im using RESIN and having a simple problem of figuring out how to import classes from another context, if Im using the right word.
    ie.
    My .jsp files are under $home/resin/doc/test dir. And in the jsp file, I would like to import a servlet class or a plain java class. But the servlet classes and all other classes are located under $home/resin/webapps/project/WEB-INF/classes/a/b/c
    Hence when I say
    <% page import="a.b.c.*" %>
    I get an error saying "a" not found.
    1. When I say "servlet classes are in a different CONTEXT", is that right? or is it just another directory?
    2. How can I make the jsp file import the classes from the servlets class path?
    Note: Ofcourse, when I copy the package to the
    $home/resin/doc/WEB-INF/classes dir, everything works fine. But thats simply not an efficient way to get around. Could anyone clear my doubts on this regd.?
    Thanks in advance.
    Arun

    Oh... I get it now. I'm sorry, I had you poorly misunderstood. You are trying to import servlets from another web app or servlet context. I would suggest you put servlets that are common to all web apps in the system classpath and not tie them to any particular web app. In other words create a package directory structure from the system's root directory or any where outside of any web apps and point the system classpath to the beginning of that directory structure. I have a similar thing going with Tomcat. I have a folder in my root called Java_Class which is in my classpath. I build all common utilities in this directory. So I have a com/craig/web structure that holds my AppServlet which is in package com.craig.web. This servlet is visible to all web apps via the Windows classpath. Servlets particular to an application like say an MusicOrderProcess servlet would reside in a package under the webserverhome/webapps/MusicStore/WEB-INF/classes directory where webserver home is the home directory of the webserver you are using. I've tested this across webservers as well (orionserver and Tomcat) and it works.
    From the prompt you include in your posts I am guessing that you are running on UNIX. Move your common servlets out of their respective web apps and into a common directory structure. Configure the UNIX $CLASSPATH (or is it $classpath?) environment variable to point to this sturcture and you'll be on your way!
    Post again if you have more questions!

  • Importing a .class file into my package?

    Hi. I'm making a java program but I need to use an external .class file to get variables and use methods from. Is it possible to "import" a class file into my package to be able to do so?
    Thanks

    Basically, for our last project we created a class
    that held the information about a year: how many days
    were in a month, how many months were in a year, etc.
    etc. For this project, we'll be having to use that
    same class to make a GUI calendar. Our teacher
    provided a class which he compiled for us to use in
    our projects incase our previous class had some flaws
    in it, which mine did. Unfortunately, it's in .class
    format and I don't know how to use it in my package!That's going to be a problem then. I would assume that it is going to have an API like your old one did. Same name and same methods etc. So do you know what the name and method signatures of your class were supposed to be?

  • Classpath problems when importing my classes

    I'm using a tutorial with sample programs dealing with bank accounts.
    I get this error:
    InterestBearingAccount.java [9:1] '.' expected
    import Account;
    ^
    1 error
    Errors compiling InterestBearingAccount.
    The Account class already exists in the current directory. I've tried everything as far as setting the classpath variable (nothing, just a period, period & slash, the actual complete path for the current directory, nothing works!!!!!). I also tried using -classpath (.) and the end of my javac command and that seemed to not work at all.
    The Java Coffee Break tutorial have some already compiled (*.class) files and they run fine. My *.java files are identical. In fact, I cut and pasted them so I know it's not a typo.
    My path is set to include the jdk1.4.0\bin directory and I've only begun to have problems now that I need to import existing classes into the programs.
    I should mention that I get the same error using Forte environment or doing it at the command prompt window. Please help.

    Thanks ATMGUY. I commented out the import statements in both InterestBearingAccount and AccountDemo and it worked fine. I guess the author of that tutorial was obviously not working with jdk 1.4.
    As far as using packages, com.kusek.bank would make a good package name then??
    The statement:
    package com.kusek.bank; OR a shorter version package kusek.bank;
    should be added to all three classes and no import statements would then be necessary, right??
    I just remember reading that it should be something unique as a good habit to get into.
    I'm trying to learn enough to make a useful GUI program for a special project so I probably should be using packages anyway when I get to that point.
    My programming backround is limited to procredural languages Basic, QBasic, Pascal, and Fortran and I find myself still wanting to think in those terms. I have read several web sites and worked through some basic examples but I still have much to learn. I once I can grasp how to write OOP style it would be nice to look at code for a somewhat detailed application (like a store checkout app) and have every line explained as to why it's there. I can see where it makes sense to have your GUI classes predefined (Swing), File I/O, serial port communications, and even things like this InterestBearingAccount example that extends from the Account class utilizing its basic attributes but overriding the constructors for the additional parameters (interest calculation) that are passed. How to take a common problem and go about creating a solution is what I need to see being done to help me.
    My telemetry project uses VHF radios with packet radio modems to monitor two diesel engines and turn one off if the other turns off. The modems have built in A/D data gathering and can also output control signals, they just need to be told what to do. I can manually use a Windows Hyperterminal session and type in "connect Engine1" and use commands to determine the A/D inputs "analog". The modems have built in end-to-end acknowledgement so the only think I need is an application than can be setup to run in the Startup folder to handle this. It would use a timer class to "poll" engine1 every 5-10 minutes and if it has stopped (based on the response of the "analog" command) I would "disconnect" from engine1 and "connect" to engine2 and send a "ctrl B off" or something similar. The standard responses from the modem should allow me just to send and recieve STRING data to and from the serial port and parse them as needed. I need at least this much but it shouldn't be too much harder to develop a way to reset the system(reverse of this) when that is required. I could also read a water pressure value at one of the locations and display that on the screen along with the current status of the engines (using values obtained from the "analog" command on the modems).
    The hardest part of OOP programming seems to be knowing what classes are already out there and knowing how to find them or apply them. I hope Swing has classes that provide for displaying values on the Windows taskbar (my motherboard monitor freeware displays temperature readings down on the taskbar). I appreciate all the help given here. It's almost like having a private tutor.
    randy

  • How to import a .class in eclipse?

    I have a .class file w/ out the source, and im tiring to import that into my project.
    So I go to import->File System and check the .class file. It shows up in my project but when I try to instantiate it I get a "can not be instantiated to a type" error.
    any thoughts?
    this is happening to a lot of people in my course.
    thanks!

    Hi,
    i tried that what you sad, but my eclipse can't import that class.
    So: I have eclipse 3.1, and i would like to import a class (without source). I develop at the moment a J2ME project with eclipse.
    The class what i want to import is in a package, so i must to import like this: import net.jscience.math.kvm.MathFP;
    Can you tell me how in the hell can i this class to import?
    (I tried about 6 hours long, and i got some result, but not the really perfect.)
    When i make this subdirectory structure (what is in the import line) into my project, then in eclipse work the auto completing, 'till the class name. :-/. But the class is there. Egal i add an external class folder, i got always the same result.
    Please help me, because my brain at the moment wants to explode.
    Thanks a lot.

  • Cannot import AppModuleImpl class

    Hi experts,
    I'm developing Jdeveloper 11.1.2.2.0
    Suddenly I got this error.
    I had created Manage bean and import pakagename.AppModuleImpl and few other Impl classes there.
    Suddenly it was prompted error that ,cannot import AppModuleImpl class.
    I was wonder about this error because it worked fine before.
    Could u pls advise me to solve this problem.
    Charith

    Hi,
    what you try to do is accomplished by creating a dependency between the modle and the viewController project (see view controller project properties). As mentioned in the previous post, crossing boundaries between the model layer and the view controller layer is not good practices. If you need to access an AM method, expose it on the client interface and create a method binding so it can be accessed from and through the ADF binding layer.
    Frank

  • Importing existing classes loses package identity in 9.0.2

    I have tried several ways, but everytime I import existing classes, they all go to Miscellaneous Files and won't display under their packages. This is from disk or from source code control (CVS). This works fine with the same exact classes and directories under JDeveloper 3.1.1. It seems simple, but it is frustrating. Any suggestions?

    Hi,
    This is normally because the Source Path setting (under Common->Input Paths in project settings) is not set to the correct directory. You should get a prompt asking if you want to add the correct path to the source path when adding files to a project.
    Thanks,
    Brian

  • Eclipse plugin error (import java class)

    Hello, I am actually developing a complex interface program in JavaFx, the main component is a Swing component with a universe 3D inside (a map of a buildign). So in some javafx classes I have to import java classes and I obtain an import error. I have in the same package a java class and a javafx class with the same import and I only have the error in the javafx one.
    Does somebody have the same error? or know how can I fix it?
    Thanks and Regards

    Thanks for your suggestion, in fact I'm actually developing in Netbeans. My application is really complex I have a java3D universe in a swing component and the javaFx nodes are drawn on it. When I load some nodes and move them over the 3D I obtain a JVM error, I've read that it could be solved in some cases compiling the project in eclipse so I'm trying to do it.
    I tried to solve the JVM error hardly, at first it was thrown every time I load a new module in my scene an moved it, I improve the performance of my application and I've decreased the error a lot. In fact, the error only appear if I load the 3D universe and I'm sure that is because of the rendering. I've tried all I can imagine so now I'm trying that kind of stupid thing.
    Thanks and Regards

  • Importing existing classes to Eclipse?

    Suppose i just created a new Eclipse project. Is it possible for me then to import an EXISTING class as the
    main class for this project? I have tried to do it and can't see a way. It seems to only want new classes added
    to its projects. I know i can just cut and paste, but that is a pain so i want to know if i can just bring them in.
    Any ideas? Thanks

    i tried that, and i get these options:
    select import source:
    existing project into workspace
    external features
    external plug ins and fragments
    file system
    team project set
    zip file
    none of those looks like what i need. Any advice?use import>fileSystem

  • "importing java classes" through forms9i

    hi
    i can't import any java class which i have written
    they are not visible on the "java classes list"
    when i try to import it manually typing, it gives "java.lang.ClassNotFoundException".
    what can i do?

    Hi,
    I am having the same problem.
    I can't import java class in the form.
    I read through most of the forum and this is what I tried.
    I follow the instruction and follow the sample form from OTN.
    Ok, this is what I did and tell me what I did wrong.
    1. I copy my co-worker jar files into c:\project.
    In it there are a bunch of jar files he uses jdk.1.4
    (i am not sure if this might cause the problem).
    2. on the CLASSPATH in CONTROL PANEL -- System icon,
    i have following:
    c:\project\security.jar;c:\program files\java\jre1.4.0_01\bin;C:\oracle\orads9i\jlib\bigraphbean.jar;C:\oracle\orads9i\jlib\LW_PfjBean.jar;C:\oracle\orads9i\jlib\bigraphbean-nls.zip
    BTW, my form version is 9.0.2.11.0, in windows environment.
    thank you soo much for your help.
    3. then I launched the forms, and tried to import java classes, it took about 2 minutes to pop up the window and it gives me an error:
    PDE-PER001 Internal error (depjv1).
    4. then I closed it and tried to import java classes again, and this second time didn't give me any error, but it gives me a blank selection.
    Can anyone tell me what I did wrong? please?
    and also can anyone tell me what's the different between the CLASSPATH in control panel and in regedit, under ORACLE, i also have a classpath set.
    This is what I have set under regedit.
    c:\program files\java\j2re1.4.0_01;c:\security.jar;C:\oracle\orads9i\jlib\bigraphbean.jar;C:\oracle\orads9i\jlib\LW_PfjBean.jar;C:\oracle\orads9i\jlib\bigraphbean-nls.zip
    Is this key supposed to be under my oracle registry?

  • I don't found "used model" after I imported proxy class from CAF

    Dear Everyone,
    I built up CAF knowledge skill by do follow the document in SDN and I've tried connect CAF and web dynpro together. This's document that I learned.
    https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/504540a4-fd0d-2a10-7c8e-c88289cf6457
    and I found some problem. as you see in Page 22. after I import proxy classes. I have to found something in used model popup as same as Page 23 , but I don't found anything in "selected model" popup and I check in "Used DCs". It has classes that same in Page 21.
    Can someone help me? Thank you in advance.
    Amnart.

    Dear Ayyapparaj and Everyone,
    Yes, I did. and I saw something will be my mistake.when I create new project. Do the domain has to be "SAP xApps" because I usually doesn't change it ( default is "Basis" )?
    I follow this document 3 times, but it still doesn't have classes in "used model" popup.
    Can you help me?Thank you in advance.
    Amnart.

  • Import  a class

    Hi all,
    i previuosly work with jbuilder 6 and i import a class (that locate in the project root directory and not include in any package) in the following way:
    import ClassName;
    and its compiled fine.
    when i start to work with Jbuilder2005 and also with netbeans,
    it refused to accept this kind of statment and im getting a compilation error.
    is any can suggest how can i import a class that has not include in any package.
    Thanks
    Gabi

    You can build classes without packages (in the default package). What you're seeing is a change in the definition of the import statement between 1.3 and 1.4. It's no longer permissable to have an import statement refering to a class without a package. The effect of this is that you can no longer refer to a class in the default package from a class in another package, because just giving the class name assumes a reference to the same package the reference is in.
    There's no problem when one class in the default package refers to another, you simply don't need the import statement.

  • How to add a class in a project?

    Hello!
    i'm a beginner in developing and i don't know how to add a class in a project in Sun Java Wireless toolkit 2.5.2...
    The name of my project is essai2 and i already put a class, LogoMIDlet and now i want to put my new class ComBasique, how can i do that?
    and do you know if there is a program for bluetooth in order to connect my Nokia 6680 to another device that have a bluetooth?
    thanks a lot for your answer!
    Sophie

    how to change the class name after the project is created.In NetBeans, right click the class name either in the declaration or constructor, select Refactor --> Rename... and follow the dialog.
    You can refactor --> rename anything that is not in a guarded block. For those, there are options via the properties window.
    db

  • Can you import one TOC from one project to another? (RH9)

    I have been working on a complicated project in RH9. (all work done in RH)
    I made all the modifications to the htm files that I needed.
    I went to rename the .htt file and upon entry, RH 9 CRASHED!
    When I reopened, my TOC was entirely GONE!
    Luckily, I made a backup of the entire directory a few hours ago.
    Options:
    A.) Revert to backup and redo hours of work (not what I want to do).
    B.) Somehow import the TOC from the backup to the new project.
    I hope this is a dumb question and very easy to do. It is a VERY complex TOC (prints out to 11 pages) so I do not want to redo from scratch.
    I await all of your expert advice.
    Thank you so much!
    DianaJ

    Hi,
    To import a TOC into existing project you may follow the steps as below:
    1. Go to Project Manager POD and expand the TOC folder
    2. Click New TOC in the Right Click Menu
    3. Give the desired name to the TOC you want
    4. Check the checkbox "Copy existing Table of Contents" and browse to the TOC file that you want to import
    5. Click OK and all contents of the TOC should be imported.
    I hope it works
    Thanks

Maybe you are looking for

  • 2nd gen shuffle wouldn't sync - fixed it (for me)

    With 2nd gen shuffle, changed computers, downloaded ITunes 9, created new playlists, got all ready... and shuffle won't sync. Would start syncing, then quit after trying a couple songs, then some kind of error - folder not found or something like tha

  • How to access Excel PROTECTED spreadsheet in SharePoint Web Access Web Part in SharePoint2013?

    I have excel file which is protected by password. I need to access Sheet 1 on SharePoint Web Part Page on Dashboard. While I add protected I can not able to Excel Sheet is corrupted as per below image.! While I add simple Excel Spreadsheet, it works

  • Displaying BLOB image in an item

    I have a table with a BLOB column holding an image. I can set up a report region with a query on the column like this (the whole sql query is omitted for simplicity, I am just showing relevant column): dbms_lob.getlength(a.product_logo) and then put

  • Error popping up in Photoshop CS6

    I am having a program error pop up when I attempt to use my tools in Photoshop CS6. I have encountered this problem quite a few times over the past few months and each time it happens I have uninstalled and reinstalled the Adobe Creative Suite. But t

  • Mac Book Pro 13 inch Power up Issue

    Hi my machine wont turned up. can someone can help me? i have made same verification. 1.the power adapter is fine ,i have checked on other similar machine and when i plugged to mine i can see the green light. 2.the batery was full wen the problem ape