forked from npocmaka/batch.scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjavaHybrid.bat
More file actions
46 lines (36 loc) · 992 Bytes
/
javaHybrid.bat
File metadata and controls
46 lines (36 loc) · 992 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
@Deprecated /* >nul 2>&1
:: self compiled java/.bat hybrid
::
:: deprecated is the only one annotation that can be used outside the class definition
:: and is needed for 'mute' start of multi-line java comment
:: that will be not printed by the batch file.
:: though it still creates two files - the .class and the .java
:: it still allows you to embed both batch and java code into one file
@echo off
setlocal
java -version >nul 2>&1 || (
echo java not found
exit /b 1
)
::find class name
::can be different than the script name
for /f "usebackq tokens=3 delims=} " %%c in (`type %~f0 ^|find /i "public class"^|findstr /v "for /f"`) do (
set "javaFile=%%c"
goto :skip
)
:skip
copy "%~f0" "%javaFile%.java" >nul 2>&1
javac "%javaFile%.java"
java "%javaFile%"
::optional
::del %javaFile%.* >nul 2>&1
endlocal
exit /b 0
*******/
public class TestClass
{
public static void main(String args[])
{
System.out.println("selfcompiled .bat/.java hybrid");
}
}