#16
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2005
    Location
    Chicago, Illinois, U.S.A.
    Posts
    93
    Rep Power
    0
    Originally Posted by NormR
    You need the java SDK
    Damn, the JavaSE I downloaded was a JDK.

    The JDK I downloaded was at http://www.oracle.com/technetwork/java/javase/downloads/index.html but I haven't downloaded anything else.

    Where do I download the Java SDK?

    Thanks.
  2. #17
  3. Contributing User
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Aug 2010
    Location
    Eastern Florida
    Posts
    3,696
    Rep Power
    347
    SDK and JDK are the same thing
  4. #18
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2005
    Location
    Chicago, Illinois, U.S.A.
    Posts
    93
    Rep Power
    0
    I installed jGRASP before the JDK, and could not build/compile or run.

    The error message was "javac" not found.

    I was told to install the JDK before the jGRASP.

    So I uninstalled jGRASP, then downloaded the JDK, then reinstalled jGRASP.

    Now at jGRASP I can build/compile and run just fine, there is no "javac" error when compiling, but yet I could not use javac in the command prompt for some reason, so I guess I must be having some registry issues.
  6. #19
  7. Contributing User
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Aug 2010
    Location
    Eastern Florida
    Posts
    3,696
    Rep Power
    347
    The OS needs a path to where a command is located to be able to find it to execute it. On windows the PATH environment variable has the paths to many commands so that the OS can find them. If the path to the JDK's bin folder is not in the PATH variable the OS can not find the javac and jar commands.

    Another solution is to use a batch file that has the full path to the command.
  8. #20
  9. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2005
    Location
    Chicago, Illinois, U.S.A.
    Posts
    93
    Rep Power
    0
    Originally Posted by NormR
    The OS needs a path to where a command is located to be able to find it to execute it. On windows the PATH environment variable has the paths to many commands so that the OS can find them. If the path to the JDK's bin folder is not in the PATH variable the OS can not find the javac and jar commands.
    Okay I'd like to locate the PATH variable and see what I have there.

    Currently I have found the javac and jar applications in the JDK folders, in bin.

    They are at.

    C:\Program Files\Java\jdk1.7.0_45\bin

    When I double click on javac and jar, a command prompt opens but immediately closes. So I don't know why I'm getting the error messages of "javac not found."

    Another solution is to use a batch file that has the full path to the command.
    I'd like to explore this too.
  10. #21
  11. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2005
    Location
    Chicago, Illinois, U.S.A.
    Posts
    93
    Rep Power
    0
    Hey, how do I add the bin directory to my system path?
  12. #22
  13. Contributing User
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Aug 2010
    Location
    Eastern Florida
    Posts
    3,696
    Rep Power
    347
    Ask an internet search engine. It's been well documented.
  14. #23
  15. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2005
    Location
    Chicago, Illinois, U.S.A.
    Posts
    93
    Rep Power
    0
    For Windows 7, I went to Control Panel > System > Advanced system setting > clicked on Environment Variables, under System variables I clicked on Path, and added the

    C:\Program Files\Java\jdk1.7.0_45\bin

    to it;.

    I guess I'll have to reboot to see effects.

    Edit: just had to reboot the command prompt. Now the javac and jar works.
    Last edited by LostShadow; December 30th, 2013 at 04:04 PM.
  16. #24
  17. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2005
    Location
    Chicago, Illinois, U.S.A.
    Posts
    93
    Rep Power
    0
    I was successfully able to create he jar file yesterday but can't execute it.

    I created it via the IDE and via the command prompt.

    Is the jar file to be program.java, program.class, or both?

    Well, I made it 3 times and none of them worked.

    For the jar command, I tried java -jar program.jar as well as .class, and double-clicking the icon doesn't seem to do anything (maybe it opens and closes instantly)

    With the IDE I created it using the program.java, program.class, and both program.java and program.class.

    Same result, nothing. The jar file is created but it doesn't load. However, I could still run the java program on my IDE. Which is a GUI.
  18. #25
  19. Contributing User
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Aug 2010
    Location
    Eastern Florida
    Posts
    3,696
    Rep Power
    347
    The class files are what execute. The .java files do not need to be in the jar file.

    Open a command prompt window and execute the jar file from there so the error messages are written to the window.
    java -jar THEJARFILENAME.jar
    Copy the full text of the window and paste it here.

    To copy the contents of the command prompt window:
    Click on Icon in upper left corner
    Select Edit
    Select 'Select All' - The selection will show
    Click in upper left again
    Select Edit and click 'Copy'

    Paste here.

    Does the jar file have a properly formatted manifest file?

    Have you looked at the tutorial:
    http://docs.oracle.com/javase/tutori...jar/index.html
    Last edited by NormR; December 31st, 2013 at 02:59 PM.
  20. #26
  21. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2005
    Location
    Chicago, Illinois, U.S.A.
    Posts
    93
    Rep Power
    0
    Originally Posted by NormR
    Copy the full text of the window and paste it here.
    no main manifest attribute, in Program.jar

    Originally Posted by NormR
    Does the jar file have a properly formatted manifest file?
    I don't think so.

    I don't have a public class within my main.

    All I have is a declaration:

    public static void main(String[] args)
    {
    Program p = new Program();
    }
    Thanks.
  22. #27
  23. Contributing User
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Aug 2010
    Location
    Eastern Florida
    Posts
    3,696
    Rep Power
    347
    Read the tutorial at the link in my last post. It explains how to create an executable jar file.
  24. #28
  25. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2005
    Location
    Chicago, Illinois, U.S.A.
    Posts
    93
    Rep Power
    0
    Originally Posted by NormR
    Read the tutorial at the link in my last post. It explains how to create an executable jar file.
    You're talking about running an application packaged as a JAR file, right? I don't know what a main-class manifest header is. I posted my main that shows it's lacking any classes or methods.

    Anyways, I no longer get "no main manifest attribute, in Program.jar"

    I now get "Error: Could not find or load main class Program.class"

    What I did was created a Manifest.txt

    And then added in

    Main-Class: Program.class
    <Enter>

    And then at the command prompt:

    jar cfm Program.jar Manifest.txt Program.class

    And then java -jar Program.jar

    Thanks.

    Sorry for the late replies, I don't have Internet at home, I take my laptop to the public library.
  26. #29
  27. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2005
    Location
    Chicago, Illinois, U.S.A.
    Posts
    93
    Rep Power
    0
    I guess I disagree with everything being said here. I just spoke to a member of the IT of the warehouse I work at, asking him about an application.

    He says .exe files in Java have nothing to do with what programs you use to convert it, but what you have in the code. In the public static void main(String args[]).

    And that .jar files are the equivalent of .dll files of C++ or so.

    So attempting to get me to double click on a .jar file (and expecting a GUI to pop up) would be the equivalent of double clicking a .dll file, and expecting a GUI to pop up.
  28. #30
  29. Lord of the Dance
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Oct 2003
    Posts
    3,535
    Rep Power
    1906
    It is correct that you will need to add the main function to run a class directly from the command prompt. This has nothing to do whether you place the class in a Jar file or not.

    For test, I created the below which does let me double click on the Jar file to open a GUI.
    Program.java:
    Code:
    import javax.swing.JFrame;
    import java.awt.Dimension;
    
    public class Program {
    
    	public static void main(String[] args) {
    		System.out.println("HELLO WORLD");
    		
    		JFrame myGUI = new JFrame("TEST");
    		myGUI.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    		myGUI.setPreferredSize(new Dimension(175, 100));
    		myGUI.pack();
    		myGUI.setVisible(true);
    		
    	}
    
    }
    Manifest.txt:
    Code:
    Main-Class: Program
    Command to compile and make the jar:
    Code:
    > javac Program.java
    > jar cfm Program.jar Manifest.txt Program.class
    Last edited by MrFujin; January 15th, 2014 at 05:23 PM. Reason: javac to compile, not java

IMN logo majestic logo threadwatch logo seochat tools logo