How to compile and run Java programs that include import with Sublime Text 2?

I have Windows 7, not OS X.

I configured my Sublime Text 2 with this turorial:

Compile and run Java programs with Sublime Text 2

It works great with this code:

enter image description here

But if I want to compile and run the code with the import, it no longer works.

enter image description here

So my question is how to configure this batch code so that I can compile and run Java code that includes import?

@ECHO OFF cd %~dp1 ECHO Compiling %~nx1....... IF EXIST %~n1.class ( DEL %~n1.class ) javac %~nx1 IF EXIST %~n1.class ( ECHO -----------OUTPUT----------- java %~n1 
+6
source share
2 answers

I used the following setup to run java in sublime 2, and I just tested the import function and it worked perfectly:

Make the bat file with the following and save it anywhere in your PATH. I suggest C: \ Program Files \ Java \ jdk * \ bin \ save everything together.

 @ECHO OFF cd %~dp1 javac %~nx1 java %~n1 

then edit C: \ Users \ your_user_name \ AppData \ Roaming \ Sublime Text 2 \ Packages \ Java \ JavaC.sublime-build, the content will be

 { "cmd": ["javac", "$file"], "file_regex": "^(...*?):([0-9]*):?([0-9]*)", "selector": "source.java" } 

replace "javac" with the name of your bat file (for example, javacexec.bat) and save it.

Now you can run it with ctrl + b.

+1
source

This package for sublime text 2 solved my problem.

https://github.com/psychowico/SublimeJavaCompiler

Features:

  • JavaC: compile current file
  • JavaC: compiling and running the current file
  • JavaC: compile the current project
  • JavaC: compiling and running the current project
  • JavaC: creating a Jar package for a project
  • JavaC: creating and running a Jar package for a project
  • JavaC: Clear Project
+1
source

Source: https://habr.com/ru/post/945689/


All Articles