Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 8 of 8

Thread: How can I import my own packages?

  1. #1
    Junior Member
    Join Date
    Apr 2021
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Exclamation How can I import my own packages?

    Hello everybody, I'm new here so nice to meet you all
    I made a package in the following direction:
    C:\users\asada\desktop\myPackageName
    and I'm typing some codes in IntelliJ IDEA but when I type the following command at the top of my source code I get an error that says "package myPackageName does not exist"
    import myPackageName.*;
    I wonder if you could help me, thank you for your responses.

  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: How can I import my own packages?

    Does the classpath path for the javac command point to the folder that holds the myPackageName folder?


    javac -cp pathToFolderWithPackage;. TheClass.java
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Junior Member
    Join Date
    Apr 2021
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: How can I import my own packages?

    I don't even know what is classpath that you mentioned, anyway how can I set it up to the right directory?

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: How can I import my own packages?

    The classpath is a list of one or more directory paths that the javac and java commands will use to find java classes.
    In this command that is issued in the folder that holds the TheClass.java file:

    javac -cp pathToFolderWithPackage;. TheClass.java

    replace pathToFolderWithPackage with the directory path to the folder that holds the myPackageName folder.
    If you don't understand my answer, don't ignore it, ask a question.

  5. #5
    Junior Member
    Join Date
    Apr 2021
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: How can I import my own packages?

    Where do I have to type this command?
    I typed it in cmd but I got an error that says
    "no source files"

  6. #6
    Junior Member
    Join Date
    Apr 2021
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: How can I import my own packages?

    Yes you're right, I saw a video about creating a package on youtube and followed him. If that tutorial is correct so I did create a package.

  7. #7
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: How can I import my own packages?

    Has the problem been solved now?
    If you don't understand my answer, don't ignore it, ask a question.

  8. #8
    Junior Member
    Join Date
    Apr 2021
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Red face Re: How can I import my own packages?

    Yes, thank you

Similar Threads

  1. import TerminalIO.KeyboardReader ; to import java.util.*;
    By qwqw in forum What's Wrong With My Code?
    Replies: 1
    Last Post: March 13th, 2014, 08:22 AM
  2. Import if Import is Found, Else
    By blazedGinger in forum Java Theory & Questions
    Replies: 5
    Last Post: March 9th, 2013, 06:43 PM
  3. How do I import user defined packages to my java application.
    By kunalgaurav18 in forum Java Theory & Questions
    Replies: 6
    Last Post: October 11th, 2012, 01:41 PM
  4. packages
    By Spidey1980 in forum Java Theory & Questions
    Replies: 2
    Last Post: October 6th, 2011, 06:45 PM
  5. [SOLVED] Confuced when import packages...
    By Delmi in forum AWT / Java Swing
    Replies: 2
    Last Post: May 20th, 2010, 03:39 AM