jasypt in cmd: cannot find main class
Asked Answered
I

5

6

I am using jasypt 1.9.2 in Windows 7 x64 cmd. Here's encrypt.bat content:

ECHO ON


set SCRIPT_NAME=encrypt.bat
set EXECUTABLE_CLASS=org.jasypt.intf.cli.JasyptPBEStringEncryptionCLI
set EXEC_CLASSPATH=.
if "%JASYPT_CLASSPATH%" == "" goto computeclasspath
set EXEC_CLASSPATH=%EXEC_CLASSPATH%;%JASYPT_CLASSPATH%

:computeclasspath
IF "%OS%" == "Windows_NT" setlocal ENABLEDELAYEDEXPANSION
FOR %%c in (%~dp0lib\*.jar) DO set EXEC_CLASSPATH=!EXEC_CLASSPATH!;%%c
IF "%OS%" == "Windows_NT" setlocal DISABLEDELAYEDEXPANSION

set JAVA_EXECUTABLE=java
if "%JAVA_HOME%" == "" goto execute
set JAVA_EXECUTABLE="%JAVA_HOME%\bin\java"


:execute
%JAVA_EXECUTABLE% -classpath %EXEC_CLASSPATH% %EXECUTABLE_CLASS% %SCRIPT_NAME% %*

I got this error(I also tried cd /d [the dir where encrypt.bat is located] and the error persists):

enter image description here

The error message points out that the main class of org.jasypt.intf.cli.JasyptPBEStringEncryptionCLI is no where to be found. I don't understand this. I tried to change JAVA_HOME value in system variables and no luck.

Isherwood answered 20/11, 2015 at 12:32 Comment(0)
I
10

I finally downloaded again the original release and it works. Seems that I messed something up when I was trying to edit the encrypt.bat... I noticed this difference:

With @echo on, I see this output in working version:

C:\Users\myname>FOR %c in (C:\Users\myname\Documents\[APP]\jasypt-1.9.2-dist_new\bin\..\lib\*.jar) DO set EXEC_CLASSPATH=!EXEC_CLASSPATH!;%c

And in my answer I see this:

C:\Users\myname>FOR %c in (C:\Users\myname\Documents\[APP]\jasypt-1.9.2-dist_new\bin\lib\*.jar) DO set EXEC_CLASSPATH=!EXEC_CLASSPATH!;%c 

Note the .. before lib.

Also: don't put jaspyt in some path with space! It also cause error, even with quotes.

Isherwood answered 17/2, 2016 at 13:46 Comment(2)
Putting jaspyt folder directly in C drive i.e. "C:\jasypt-1.9.2\bin" thus avoiding the spaces did the trick for me.Molybdenum
I don't have any spaces in my path and still getting this error.Myrt
C
1

I also had a same issue when I put unzipped jasypt-1.9.2 folder inside Program Files. You need to move jasypt-1.9.2 folder to C: drive. You should be able to encrypt string without any issues.

Capitoline answered 13/4, 2017 at 8:35 Comment(0)
S
1

I had the same problem with version 1.9.3 . I did the following steps to get it to work:

  1. I cloned the project form its root (https://github.com/jasypt/jasypt.git)
  2. I compiled and packaged the project in /jasypt/ directory using maven (this is the project that is used by the script)
  3. I created the a lib next to bin directory and then I copied the generated jar files into it
  4. then I ran the encrypt.bat again

This way I solved the problem.

Sillsby answered 27/7, 2019 at 9:21 Comment(1)
This one fixed it for me on macOS. :)Ormond
A
0

call the encrypt.bat/decrypt.bat file instead of the .sh file while you are running from the windows machine.

Anibalanica answered 13/2, 2020 at 23:44 Comment(0)
G
0

Here's the updated encrypt.bat file:

@ECHO OFF

set SCRIPT_NAME=encrypt.bat
set EXECUTABLE_CLASS=org.jasypt.intf.cli.JasyptPBEStringEncryptionCLI
set EXEC_CLASSPATH=.
if "%JASYPT_CLASSPATH%" == "" goto computeclasspath
set EXEC_CLASSPATH=%EXEC_CLASSPATH%;%JASYPT_CLASSPATH%

:computeclasspath
IF "%OS%" == "Windows_NT" setlocal ENABLEDELAYEDEXPANSION
FOR %%c in ("%~dp0lib\*.jar") DO set EXEC_CLASSPATH=!EXEC_CLASSPATH!;%%c
IF "%OS%" == "Windows_NT" setlocal DISABLEDELAYEDEXPANSION

set JAVA_EXECUTABLE=java
if "%JAVA_HOME%" == "" goto execute
set JAVA_EXECUTABLE="%JAVA_HOME%\bin\java"

:execute
%JAVA_EXECUTABLE% -classpath "%EXEC_CLASSPATH%" %EXECUTABLE_CLASS% 
%SCRIPT_NAME% %*

Points to Remember:

  • Copy the lib directory within the bin directory with all the jar files present.

  • Jasypt version 1.9.3 uses an old version of icu4j-3.4.4.jar. Using Java 1.8.0_291, I was getting an error:

    java.lang.ExceptionInInitializerError
    

    I replaced it with icu4j-75.1.jar.

Following the above solution will not cause a problem in storing Jasypt within a directory containing spaces like in Program Files.

Groupie answered 1/7, 2024 at 20:58 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.