I have tried posting this request in Cloud9's forums, but since it never posts, I am hoping someone here could give me a hand. (The forum keeps saying my question is being submitted for review, but then never shows up).
I can't get Java code to compile and run. I've Googled the issue and read other posts in their limited forums, but I can't get it to compile and run a simple Hello World! program. My .java filename matches the class and the code is fine.
I have tried putting my .java files in the following directories:
test/java/
test/src/
I just get this:
bash: src/HelloWorld.java: No such file or directory
I tried this: http://www.programmingforliving.com/2014/09/java-coding-with-cloud9-ide.html
But I just get:
Running HelloWorld.java
Error: Could not find or load main class HelloWorld
Any suggestions? Given I'm essentially a Java noob I am hoping the solution is fairly simple.
Without you pasting in your code it's tough to tell but make sure your class and filename are both titled HelloWorld. Make sure your src folder is in your main workspace folder so your file should be at /home/ubuntu/workspace/src/HelloWorld.java.
Also, this documentation looks pretty similar to the blog you referenced but still worth a look https://docs.c9.io/docs/custom-runners.
I think that Codenvy is much better in java than Cloud9. It provides easy build & run configuration, code completion, project sharing with permissions or factory (creates clone of your project with one click in minutes).
Take a look at official java spring factory. This link opens temporary(personal) java project ready to code, build & run.
Also Codenvy has project wizard that has a lot of project types including java console app (uses maven).
Ok, decided to screw around with it and figured it out... (then saw that Brady Dowling had posted a link that explained in better detail what needed to be changed).
At any rate, I noticed a few things in Cloud9.
Even after making the changes and saving, it would still not compile correctly. I had to close my session of C9 and go back in. Then it would work.
After compiling, and trying to run the program, it wasn't automatically picking the Java runner I made. So if you are running into issues, make sure the Java (or whatever you decided to name it) runner is selected in the console.
You have to compile and run separately. Kind of annoying, but at least it works. Unlike C/C++ in C9, it won't compile and run by simply hitting 'Run'. If you do, it creates an error saying the .class doesn't exist. Simple as pressing F7 to build, then F5 to run.
Anyway, I took screenshots of what I had to change to get it working. Essentially, just the directories it looks for the .java file in (the right arrows) and the directory it looks for/compiles the .class file to (the left arrows). Since I was putting the .java and .class in the same directory (java), I just changed both to 'java'. In the links Brady and myself posted, they used .bin (for .class) and src for (.java).
1st picture is the Builder file (I called it javac) and the 2nd picture is the Runner file (I called it Java).
Anyway, I hope this helps someone out. I am really liking C9 and it perfectly suits my novice needs at the moment. I like the ability to dabble in multiple languages to see what I like without having to switch applications. The real-time live preview HTML/CSS like Brackets is another huge plus for me.
Regards
For what I understand, C9 workspaces don't come with jdk installed. But I always use these commands:
sudo apt-get update
(wait a while for it to finish processing. Then)
sudo apt-get install default-jdk
(Then It will ask you for some permission. Type "Y")
And then it compiles and runs normally using the terminal.
Sometimes you will also need to install a package to get javac.
Example:
sudo apt-get install openjdk-7-jdk
The java command works right of the box. You may java -version to see that it is Ubuntu running. You can also locate the java binary and see that it is amd64. That is all you need to know to download jdk manually from Oracle.com, like
wget --no-check-certificate --no-cookies --header "Cookie: oraclelicense=accept-securebackup-cookie" http://download.oracle.com/otn-pub/java/jdk/8u92-b14/jdk-8u92-linux-i586.tar.gz
tar xf jdk-8u92-linux-i586.tar.gz
and voila, jdk-1.8.0_92/bin/java(c) can be executed! It allows you to compile java files.
Related
I am trying to run a executable jar file I made in Intellij on JDK 11.0.2 that contains a GUI system. I have java 8 and Java SDK 11.0.2 installed. Whenever I double click the jar file I expect the main gui login screen to come up, but nothing happens. I have tried other options such as trying to run it through cmd (it gave me an access error) and the HKEY_CLASSES_ROOT\jarfile has the command: "C:\Program Files\Java\jdk-11.0.2\bin\javaw.exe" -jar "%1" %* already.
Cant comment quite yet on other peoples posts so ill just submit an answer, tho its gonna be more of a swing and miss probably.
Id recommend opening that jar file with a java decompiler (The one i had in mind is jd-gui) and checking the integrity of the code, file system, and, in general, just check arround for common errors when packaging, maybe you included something you shouldnt in the class and hence why the problem, or its crashing on load cause of a missing reference you had linked to with a relative path which got broken upon moving the file, those are the two big ones that come to mind that you should check first upon opening the file, other than that, i cant provide much more insight, godspeed to you!
I'm currently learning java from a book and I just reached packages. I've been saving all my files on my desktop and compiling/running programs from Mac's Terminal console.
John-MacBook-Pro:~ john$ cd desktop
John-MacBook-Pro:desktop john$ javac Learning.java.
John-MacBook-Pro:desktop john$ java Learning
.... program executes and so on .....
Now I save my .java files into a package (create a new folder). Let's call the package 'book' And I'm told to run programs like this now:
javac book/Learning.java
java book.Learning
This works when I have one folder, sure, but when subclasses and more packages are added into that book folder how do I compile things deeper in? Not to mention how to run them afterwards?
The book might have assume prior knowledge so it just dives right in and tells me to setup CLASSPATH or use -classpath on my Macbook before attempting. I've tried various commands on terminal and it seems to compile sometimes where I have to manually change directory to open each folder (which is a lot of typed commands). Trying to run any classes always result in class not found. Every other answer seems to have some of the basic stuff setup already or is explained in terminology I don't understand yet.
When more classes are added, you compile them all:
javac book/Learning.java book/chapter/Chapter.java ...
You run the main class exactly the same way:
java book.Learning
If you're not in the package where the root of the package tree is (i.e. your desktop directory), you pass it in the classpath:
java -classpath /users/Leosam/desktop book.Learning
Note that it works on macOS the same way as on any other platform.
So I'm new to java (more familiar with python) so sorry if this is a really silly question. I have a folder of java files. I created a new directory and compiled the java files into it.
~ mkdir classes
~ javac -d classes my_code/*.java
Now, after initially compiling the code, I was able to run the scripts in terminal using:
java classes/some_script
Next, to make updates in the code I'm using a IDE (intellij). But after I save the some_script.java file the updates dont show up when I rerun the statement above in terminal.
Is there something I have to do (in terminal) to update the files so that when I rerun the statement in terminal the changes I made in the IDE show up? (ps I'm using a mac).
Thanks in advance.
Each time you modify the source code you need to compile the code. Contrary to python you cannot just save the file and run it.
Is any way to view the actual code behind the default classes in Java (java.awt.*;, javax.swing.*;, etc) to see exactly what it is that is happening?
I don't mean just the documentation, or a list of methods, etc, but the source code itself in full detail (in other words, what could be used to create an exact copy of an entire method/class if copied and pasted into the code for a program in Java).
The Java source code for all the API classes is shipped in the JDK installer in a file named src.zip. It's often just sitting in your install directory. Unzip it, and have a look.
If it's not there, you may have chosen not to install it; reinstall the JDK and watch for the "source code" option, making sure to include it.
I frequently use http://docjar.com for this purpose.
Example: I want to see the source code for String. Search for the FQCN, java.lang.string (using the "Package/class Name" option). Click the result you want, then click the source link at the top of the page. Voila: http://www.docjar.com/html/api/java/lang/String.java.html
src.zip usually comes with JDK.
I also find http://www.codeatlas.com to be a great place to look for JVM based source code in general. For example, if you are ever looking for how java.awt.ActionEvent is implemented you can find it here:
http://www.codatlas.com/project/L_fXVCOhW4_lzXEd3R5DNQ__/master/src/share/classes/java/awt/event/ActionEvent.java?keyword=ActionEvent&line=59
What's nice about it is that it gives an IDE like browsing experience by adding cross-reference and syntax highlighting.
For those who use linux distributions, like ubuntu, archlinux, etc. You can always get openjdk source code via corresponding package management system. This means you can choose a faster mirror to get the source code.
For ubuntu users:
$ sudo apt-get install openjdk-7-source
For Archlinux users:
$ sudo pacman -S openjdk7-src
The source will be located in the $JAVA_HOME, somewhere like /usr/lib/jvm/java-7-openjdk/src.zip.
Other distributions will have likewise package names, so not listed here.
1) Use Eclipse to attach the source code in C:\users\program files\jdkx.x
2) Use GrepCode if you are just browsing the code and to save memory used by heavy weight eclipse on your machine
Ok, So I have been making this All-in-One Batch File Compiler for Java Files, to compile the Class Files, Manifest files, and the Jar Files. Everything works but one thing... I can't seem to figure out how to call another path in certain cases.. I will explain a case example below the Batch Code:
# echo off
COLOR 0a
Title Leaum's All-In-One Java Compiler
echo Compiling The Class Files...
"Whattt to do here?!" C:\JavaApps
javac -classpath . *.java
Pause
cls
echo Type the CLASS File Name Exactly...
set Man=
set /p Man=Type CLASS File Name: %=%
pause
echo Compiling The Manfiest File...
echo Main-Class: %Man%>>manifest.txt
pause
cls
I posted it in pastebin because the code thing was being weird.
Anyway, Line 6 for example, let's say I want it to call that Folder to Search for certain .Java Files when it needs to. When ever I am compiling a Java file that contains for example "TextIO.putln" Code, I would need it to call the TextIO.java/Class file in order for it to compile correctly, and I just want to store all the standalone/applet files in a separate directory... And have it include that in the Class Compiler, But still create the Class Files in what ever directory the Current project .Java is in.. If any of this makes sense? I can't seem to find a way to make it call the TextIO though :3.
Any help would be great. Thank you!
Don't re-invent this wheel, especially in a platform specific language!
Learn Maven 3 or at least Ant or even Gradle. SCons would even be preferable to Windows specific batch files, there is nothing of value to learn from the approach you are taking.
If I'm understanding your question right, you simply need to add the directory containing your utility classes to the classpath for the compiler, e.g.:
javac -classpath .;C:\JavaApps *.java
But I do agree with Jarrod and others that, in the long run, it is better to learn to use a build tool.