Sublime Forum

Questions about Build Systems in Tools Menu

#1

Hi, I’ve been using Sublime Text for a few months now, mostly with JavaScript, CSS, HTML and PHP.

I’m a relatively new programmer and at this point know JavaScript well, and some PHP, but that’s about it. I’m beginning to learn Java and Python, and I just realized to my delight that I can test and run my Python code inside of Sublime Text by selecting the right Build System type from the Tools menu. I then also realized that I can use the Sublime Text console panel just like the Python Shell.

Anyway, my point of this post is that I’m wondering what else can Sublime Text do… under the Tools menu there is the Build System submenu… under that is listed:

Make
D
Run
Haskell
JavaC
Python
Ruby

  1. My first question is what is “Make.” I notice that when I write JavaScript in SublimeText that “Make” is automatically selected. What does this mean? What is “Make” and how is it intended to be used?

  2. What is “Run”? How is this feature meant to be used?

  3. What is JavaC? I know what Java is and I know what C is, but what is “JavaC”? Does this mean Sublime Text can be used to test and run Java code, similar to the Eclipse IDE? If so, how can I set this up? Can error messages be output to the console panel when typing Java, just like with Python?

  4. Are there any other Build Systems that can be downloaded somewhere, or is this all there is? Are there some build systems available for C# or C++?

There seems to be so many gems to Sublime Text, but so little documentation for the layperson, like myself.

Thank you.

0 Likes

#2

1, 4) Make is a wide-spread general purpose build system. In particular, it is used for C++ projects. Google “GNU make” and “makefile”
2) Not sure but I think “Run” just executes the file
3) JavaC is the Java Compiler, “javac.exe”. It should compile your program and show any errors in the build output window.

You don’t have the debugging features of Eclipse, such as breakpoints, etc.
Note that for bigger Java web applications you don’t call javac directly; you usually have Apache Ant which is the Java equivalent of Make. But in that case you probably just need to run a “build.bat” file.

If you want to run the java program after it’s compiled, check this thread: https://forum.sublimetext.com/t/compile-and-run-java-in-sublimetext/409/1

0 Likes

#3

Thanks, that gives me a starting point and some things to research.

I created a “Hello World” C++ program and hit F7 in Sublime Text. “Make” was selected as the Build System. I got this error message in the console:

[quote]
‘make’ is not recognized as an internal or external command, operable program or batch file.[/quote]

I think I’m missing some core concept as to how to set this up. What do I need to do to get this to work?

I also tried compiling a simple Java program in Sublime Text with JavaC selected as the build system, but the same thing happened. I have the JDK 1.6 installed. Is there a way in which I need to tell Sublime Text where javac.exe is located on my computer? Or do I simply need to save my file in a specific location in order for it to work? (I read the link you gave me, but am still lost…)

Regarding Python… I have Python 2.6 and Python 3.1 installed on my computer; however, it doesn’t appear as if Sublime Text is using either. If I enter:

help()

Into the console, I get

How can I set Sublime Text up to use Python 2.6 or 3.1?

Thanks!

0 Likes

#4

Sublime needs to find the tools you’re using (make.exe, javac.exe, etc); add them to your %PATH% environment variable.

For ‘make’ to work, you also need to create a makefile. It’s overkill for a hello world program, but it’s a good exercise I guess. Google it or look for C++/make tutorials.

As for Python, Sublime comes with its own version of python (2.5.2 atm), which is also what you have in the console. It’s also what’s used by the plugins.

If you run your own .py files, it’ll use your default python installation, not Sublime’s. Which version is used depends on the %PATH% variable as well.

0 Likes

#5

Hmm… it sounds like it will be more difficult than I anticipated. I have no idea where to put the %PATH% variable you’re referring to or how to code it.
For now, I think I’ll have to use other editors while I learn C++ and Java. I love Sublime Text, but if there’s no easy way to run and test… In the mean time I’ll keep using it to learn Python with.

Thanks for your help gpfsmurf. I’ll do some study on how to create a makefile… :wink:

0 Likes

#6

Yeah, I got it to work! At least the Java part of it…

I manged to find this doc page through a Google search: sublimetext.com/docs/build

That was very helpful. First I saved a Hello.java file to C:/test

class Hello { public static void main(String] args) { System.out.println("Hello World!"); // Display the string. } }

I realize now what you meant by setting my %PATH% variable. I needed to point commands received to that directory location to the javac.exe app by setting this in the command prompt:

C:\test> set PATH=%PATH%;C:\jdk1.6.0_16\bin

Then in Sublime Text I selected Preferences -> Browse Packages. Then I opened the Java folder and found the file JavaC.sublime-build
This is what it showed me on the first line:

build javac.exe

I then changed it to:

build javac.exe "$File"

This compiled the file, but didn’t do anything else, so I wasn’t getting any response in the console. Each time I hit F7 in Sublime Text it actually needed to build twice: once to compile the .java file to a .class file, and the second time to run the .class file.

So I added this line underneath of the other, which mimics the way a Java class file is run in the command prompt:

build java.exe "$BaseName"

And now it works. :smile:

Whew… simple enough once you know what you’re doing. Still working on getting a C++ file to compile and run…

0 Likes

#7

Newbie here learning Python…

Is it possible to test out my Python programs in the console without having Python installed? If I choose Python as the build system and then hit F7 with a python file open I just get “python.exe is note recognized as in internal / external command.”

I can only find a Python.dll with the Sublime install.

I know it’s easy to install Python but I like the idea of using Sublime for quick testing and learning on my Netbook or other PCs without having to install and additional instance of Python.

0 Likes

#8

Yeah, I think you need Python installed, I don’t think Sublime Text installs it for you… I could be wrong. But either way, you’d need some version of it installed one way or another if you plan to use it.

Well, I’m a newbie too, but what I’ve been doing is making sure that I save my Python file to the Python installation folder in the root directory of the drive.
So, for example, install Python 2.6 and it places a folder called Python26 in the root of your C drive. Then save your .py files in Sublime Text to that directory and when you run the file by pressing F7 it uses that Python installation.

Anyone else have any insight as to why this works? Or how to set it up so that files could be saved anywhere else on the system and still know how to use Python?

0 Likes

#9

Actually, I guess you could try this too:

Preferences -> Browse Packages. Find the Python.sublime-build file and open it.

Then change the first line to this and save the file:

build "C:/Python26/python.exe" "$File"

Or if you’re using Python 3.1:

build "C:/Python31/python.exe" "$File"
0 Likes

#10

Thanks for the replies allenm541 - yes that approach works. You can also just add the location of your preferred python.exe to your windows Path environment variable and it will work fine.

I’m still wondering if it’s possible to run python files without installing python and just using the python files that come with sublime (python dll and also a zipped python 2.5 distribution) - but no big deal if this isn’t possible.

0 Likes

#11

It’s not, no - there’s no python.exe that’s distributed with Sublime Text.

0 Likes

#12

Thanks for confirming that.

0 Likes

#13

Thanks for the dialog on Java and Build Systems, the solutions in this thread helped tremendously. It’s nice to hit a couple keystrokes and viola . I’m taking my first programming class at University, and Java is the language being taught. Overall this editor is robust and lightweight, I absolutely love it. I registered with the forum just to say thanks to the author and the contributors on the forums. I’m going to have a productive semester. Thanks everyone.

-Abisha

P.S. I would love to support the editor, but is there a student discount? :smiley:

0 Likes

#14

I’ve just come back to doing some more Python learning… but today when I have a Python file loaded and hit F7 in Sublime I get a blank Output Panel.

I still have build system set as Python, the file type is .py and python.exe is set correctly in my Windows path… this used to work fine. If I look in the Console I can see Sublime trying to execute the files and if I copy these lines into a command prompt they run just fine:

running command "C:/Python25/python.exe" "D:\Documents\Programming\python\02-trivia.py" from directory D:\Documents\Programming\python exec: trying C:\Windows\system32\cmd.exe /A /S /C ""C:/Python25/python.exe" "D:\Documents\Programming\python\02-trivia.py""

I also just tried on my laptop with the same result. The only change I can think that has happened since my previous posts here is that I’ve upgraded to Sublime 1.3 (also just tried the latest beta with same result).

Can someone else confirm if this is happening for them? I’m confused! (Or have done something stupid!)

0 Likes

#15

Can you show the code?

I’ve had similar experiences with poweshell, but I haven’t been able to determine what’s the root of the problem.

0 Likes

#16

aha - just realised the problem… i had:

raw_input

in the files i was playing with… works fine if not.

any ideas how i can get user input from the console?

0 Likes