Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @ECHO OFF
- SETLOCAL enabledelayedexpansion
- REM Create a Jar file for Tomcat including the folder structure
- REM Written by Segi Hovav 03-01-2016
- REM
- REM Needs 1 parameter, the Java class name without the extension
- REM Set this to the location of javac
- SET JDKPATH=C:\Program Files\Java\jdk1.8.0_60\bin
- REM Set this to the location of the lib folder, usually ufs\WEB-INF\lib
- SET UFSLIB=
- REM DO NOT MODIFY ANYTHING BELOW THIS LINE
- REM Validate that a parameter was provided
- IF "%1"=="" (
- ECHO Error! Please specify the name of the class file without the extension
- GOTO END
- )
- REM Validate that it refers to a Java source code file
- IF NOT EXIST "%1.java" (
- ECHO Error! Please specify the name of a valid Java file
- GOTO END
- )
- REM Call function to parse the Java source file for the package name
- CALL :getPackageName %1
- REM If the function couldn't determine the package name, exit
- IF "%packagename%" == "" (
- ECHO Error! Unable to determine the name of the package from %1.java
- GOTO END
- )
- REM Create variable with the folder name for the Jar file based on the package by replacing the dot in the package name with \
- SET ReplaceChar=\
- set FOLDERNAME=%packagename:.=!ReplaceChar!%
- REM Compile the Java source
- "%JDKPATH%"\javac %1.java
- REM If an error occurred display message and quit
- IF NOT %ERRORLEVEL% == 0 (
- ECHO An error occurred compiling the Java file
- GOTO :END
- )
- REM Create the folder for the jar archive if it doesnt exist
- IF NOT EXIST %FOLDERNAME% MKDIR %FOLDERNAME%
- REM Copy the java class to the package folder
- copy %1.class %FOLDERNAME% > nul
- REM If an error occurred display message and quit
- IF NOT %ERRORLEVEL% == 0 (
- ECHO An error occurred copying the Java class to the folder %FOLDERNAME%
- GOTO :END
- )
- REM Create the jar archive
- IF EXIST %1.jar DEL %1.jar
- "%JDKPATH%"\jar cvf %1.jar %FOLDERNAME% > nul
- REM If an error occurred display message and quit
- IF NOT %ERRORLEVEL% == 0 (
- ECHO An error occurred creating the jar file
- GOTO :END
- )
- REM Copy the jar archive to the resulting location if specified
- IF DEFINED %UFSLIB (
- copy %1.jar "%UFSLIB" > nul==
- IF NOT %ERRORLEVEL% == 0 (
- ECHO An error occurred copying the jar file to the folder "%UFSLIB"
- GOTO :END
- )
- echo Please restart the Ebase Server
- ) ELSE (
- echo Please copy %1.jar to your webapps\WEB-INF\lib folder and restart Ebase
- )
- REM Cleanup
- IF EXIST %1.class del %1.class
- IF EXIST %1.jar del %1.jar
- REM Parse the package
- for /f "tokens=1,2,3,4 delims=\ " %%a in ("%FOLDERNAME%") do SET parentFolder=%%a
- IF NOT %parentFolder% == "" rmdir /S /Q %parentFolder%
- :END
- EXIT /B %ERRORLEVEL%
- REM Function to parse the Java source file and returns the package name
- :getPackageName
- REM Parse the Java file for the package
- type %1.java | find "package" > temp.txt
- REM Store the results in a variable. At this point it will contain package PACKAGENAME;
- SET /p packagename=<temp.txt
- REM Create temporary batch file named package.bat which will have the package name be the first parameter of the batch file
- echo @echo off > package.bat
- echo echo %%1 >> package.bat
- REM execute and store the results in the temp file
- cmd /c %packagename% > temp.txt
- REM Assign the package name to packagename
- set /p packagename=<temp.txt
- REM delete all temporary files
- del package.bat
- del temp.txt
- EXIT /B 0
- ENDLOCAL
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement