View difference between Paste ID: WVvdSKWn and E0qtRssf
SHOW: | | - or go back to the newest paste.
1
@ECHO OFF
2
SETLOCAL enabledelayedexpansion 
3
REM Create a Jar file for Tomcat including the folder structure
4
REM Written by Segi Hovav 03-01-2016
5
REM 
6
REM Needs 1 parameter, the Java class name without the extension
7
8
REM Set this to the location of javac
9
SET JDKPATH=C:\Program Files\Java\jdk1.8.0_60\bin
10
11
REM Set this to the location of the lib folder, usually ufs\WEB-INF\lib
12
SET UFSLIB=
13
14
REM DO NOT MODIFY ANYTHING BELOW THIS LINE
15
16
REM Validate that a parameter was provided
17
IF "%1"=="" (
18
     ECHO Error! Please specify the name of the class file without the extension
19
     GOTO END
20
)
21
22
REM Validate that it refers to a Java source code file
23
IF NOT EXIST "%1.java" (
24
     ECHO Error! Please specify the name of a valid Java file
25
     GOTO END
26
)
27
28
REM Call function to parse the Java source file for the package name
29
CALL :getPackageName %1
30
31
REM If the function couldn't determine the package name, exit
32
IF "%packagename%" == "" (
33
     ECHO Error! Unable to determine the name of the package from %1.java
34
     GOTO END
35
)
36
37
REM Create variable with the folder name for the Jar file based on the package by replacing the dot in the package name with \
38
SET ReplaceChar=\
39
set FOLDERNAME=%packagename:.=!ReplaceChar!%
40
41
REM Compile the Java source
42
"%JDKPATH%"\javac %1.java 
43
44
REM If an error occurred display message and quit
45
IF NOT %ERRORLEVEL% == 0 (
46
     ECHO An error occurred compiling the Java file
47
     GOTO :END
48
)
49
50
REM Create the folder for the jar archive if it doesnt exist
51
IF NOT EXIST %FOLDERNAME% MKDIR %FOLDERNAME%
52
53
REM Copy the java class to the package folder
54
copy %1.class %FOLDERNAME% > nul
55
56
REM If an error occurred display message and quit
57
IF NOT %ERRORLEVEL% == 0 (
58
     ECHO An error occurred copying the Java class to the folder %FOLDERNAME%
59
     GOTO :END
60
)
61
62
REM Create the jar archive
63
IF EXIST %1.jar DEL %1.jar
64
"%JDKPATH%"\jar cvf %1.jar %FOLDERNAME% > nul
65
66
REM If an error occurred display message and quit
67
IF NOT %ERRORLEVEL% == 0 (
68
     ECHO An error occurred creating the jar file
69
     GOTO :END
70
)
71
72
REM Copy the jar archive to the resulting location if specified
73
IF DEFINED %UFSLIB (
74
     copy %1.jar "%UFSLIB" > nul==
75
     
76
     IF NOT %ERRORLEVEL% == 0 (
77
          ECHO An error occurred copying the jar file to the folder "%UFSLIB" 
78
          GOTO :END
79
     )
80
     
81
     echo Please restart the Ebase Server
82-
echo Please restart the Ebase Server
82+
) ELSE (
83
     echo Please copy %1.jar to your webapps\WEB-INF\lib folder and restart Ebase
84
)
85
86
REM Cleanup
87
IF EXIST %1.class del %1.class
88
IF EXIST %1.jar del %1.jar
89
90
REM Parse the package 
91
for /f "tokens=1,2,3,4 delims=\ " %%a in ("%FOLDERNAME%") do SET parentFolder=%%a
92
IF NOT %parentFolder% == "" rmdir /S /Q %parentFolder%
93
94
:END
95
EXIT /B %ERRORLEVEL%
96
97
REM Function to parse the Java source file and returns the package name
98
:getPackageName
99
100
REM Parse the Java file for the package
101
type %1.java | find "package" > temp.txt
102
103
REM Store the results in a variable. At this point it will contain package PACKAGENAME;
104
SET /p packagename=<temp.txt
105
106
REM  Create temporary batch file named package.bat which will have the package name be the first parameter of the batch file
107
echo @echo off > package.bat
108
echo echo %%1 >> package.bat
109
110
REM execute and store the results in the temp file
111
cmd /c %packagename% > temp.txt
112
113
REM Assign the package name to packagename
114
set /p packagename=<temp.txt
115
116
REM delete all temporary files 
117
del package.bat
118
del temp.txt
119
EXIT /B 0
120
121
ENDLOCAL