How does the "Eclipse IDE" manipulate Windows environment "Path" variable? - eclipse

I have problems setting "run configuration" in Eclipse. When I use the Windows cmd to compile and run java.class I use .bat file that looks like this:
rem Wipe standard Windows Path variable and use this:
set PATH = C: \ Program Files \ .this path.;..and this one..;…;…
rem needed CLASSPATH's
set CLASSPATH = "... some \ path / *; ...
rem Path to native .dll libs
set LIB_PATH = "C: \ ... \ bin"
javac-cp% CLASSPATH% "... \ SomeExample.java"
java-cp% CLASSPATH%-Djava.library.path =% LIB_PATH% SomeExample
And everything works as it should, both compile and run are ok. When I try to do the same through Eclipse, by adjusting the classpath in run configuration GUI, compile is ok (I test it manualy in CMD), but during execution compiled class, I get java.lang. "UnsatisfiedLinkError ... someImportantDLL.dll: The specified procedure could not be found, " Which is the same error that I get while running in cmd if I do not set the PATH enviroment variable manually in .bat file!
What should I do in Eclipse to run properly compiled class?

Add the correct -Djava.library.path to the VM Arguments field. Don't rely on the external environment--you should control everything about your application's environment so you won't have any "gotchas" when you roll it out.

Related

After "deactivate" from virtualvenv, prompt has "if defined _OLD_VIRTUAL_PYTHONPATH (set "PYTHONPATH=" ) "

I have a python (3.11) virtual env named "Test". Using VSC, Command "Workon Test" puts me in the Test virtual env. However, when I "deactivate", the command prompt has "if defined _OLD_VIRTUAL_PYTHONPATH (set "PYTHONPATH=" ) followed by the correct command prompt as expected (C:\Users\ksarn\ENVS>).
C:\Users\ksarn\ENVS>pip list
Package Version
--------------------- -------
distlib 0.3.6
filelock 3.8.0
pip 22.3.1
platformdirs 2.5.4
setuptools 65.5.0
virtualenv 20.16.7
virtualenvwrapper-win 1.2.7
C:\Users\ksarn\ENVS>workon test
(test) C:\Users\ksarn\ENVS>whereis python
C:\Users\ksarn\ENVS\test\Scripts\python.exe
(test) C:\Users\ksarn\ENVS>deactivate
C:\Users\ksarn\ENVS>if defined _OLD_VIRTUAL_PYTHONPATH (set "PYTHONPATH=" )
C:\Users\ksarn\ENVS>
C:\Users\ksarn\ENVS>whereis python
C:\Users\ksarn\AppData\Local\Programs\Python\Python311\python.exe
C:\Users\ksarn\ENVS>
Why is it showing set "Python path statement?
Re-installed python 3.11 (with path selected), virtualenv and virtualenvwrapper-win. No change.
I had the same problem. What worked for me in Windows is editing the routine that creates each environment.
Find and go the folder where default python is installed, which is used as base for virtualenv, e.g., C:\Users\<UserName>\AppData\Local\Programs\Python\Python311 (user only installation).
Secondary click > Edit on the file \Scripts\mkvirtualenv.bat
Search for "_OLD_VIRTUAL_PYTHONPATH" (about in the middle of the file) and write the # character to mute each command to be written in activate.bat and deactivate.bat. The result should look something like this:
:: In activate.bat, keep track of PYTHONPATH.
:: This should be a change adopted by virtualenv.
>>"%WORKON_HOME%\%venvwrapper.quoteless_envname%\Scripts\activate.bat" (
echo.:: In case user makes changes to PYTHONPATH
echo.#if defined _OLD_VIRTUAL_PYTHONPATH (
echo. #set "PYTHONPATH=%%_OLD_VIRTUAL_PYTHONPATH%%"
echo.^) else (
echo. #set "_OLD_VIRTUAL_PYTHONPATH=%%PYTHONPATH%%"
echo.^)
)
:: In deactivate.bat, reset PYTHONPATH to its former value
>>"%WORKON_HOME%\%venvwrapper.quoteless_envname%\Scripts\deactivate.bat" (
echo.
echo.#if defined _OLD_VIRTUAL_PYTHONPATH (
echo. #set "PYTHONPATH=%%_OLD_VIRTUAL_PYTHONPATH%%"
echo.^)
)
Save the file and re-create any environment tha had the problem. It shouldn't verbose any command.
As an alternative, you can edit directly edit the activate.bat and deactivate.bat files for each environment within its \Scripts\ subfolder.

Stale file is located outside of the allowed root path when using Cuckoo

I wanted to mock some of my files, so I used Cuckoo framework. I am using Swift Package Manager, so I did every step that is shown in README of framework.
I tried to use this script
# Define output file. Change "${PROJECT_DIR}/${PROJECT_NAME}Tests" to your test's
root source folder, if it's not the default name.
OUTPUT_FILE="${PROJECT_DIR}/${PROJECT_NAME}Tests/GeneratedMocks.swift"
echo "Generated Mocks File = ${OUTPUT_FILE}"
# Define input directory. Change "${PROJECT_DIR}/${PROJECT_NAME}" to your project's root source folder, if it's not the default name.
INPUT_DIR="${PROJECT_DIR}/${PROJECT_NAME}"
echo "Mocks Input Directory = ${INPUT_DIR}"
# Generate mock files, include as many input files as you'd like to create mocks for.
"${PROJECT_DIR}/run" --download generate --testable "${PROJECT_NAME}" \
--output "${OUTPUT_FILE}" \
"${INPUT_DIR}/Common/Repository/LatestNewsRepository/LatestNewsRepositoryImpl.swift" \
# ... and so forth, the last line should never end with a backslash
# After running once, locate `GeneratedMocks.swift` and drag it into your Xcode test target group.
I also downloaded the latest run script and I had to check For install builds only.
When app is launched I am getting this error -
Stale file '.../LibraryTests/GeneratedMocks.swift' is located outside of the allowed root paths.
Things I tried -
Clean Xcode derived data
Clean build folder
Reset Xcode
Reset Packages Cache
and I am still not getting output file. Is there anything else I should try?

On scala project - Getting error GC overhead limit exceeded when running sbt test command

I'm new in scala programming and getting GC overhead limit exceeded error when I execute sbt test command in one of big scala project. Anyone knows how can I solve this?
I got help from my friends :)
Increase the memory option by executing with -mem option for example:
sbt -mem 2048 test
Other options:
For Mac & Linux user:
if we need to execute this a lot. We can update the .bash_profile file and add below command:
export SBT_OPTS="-Xmx2G"
Other solution (works with Windows as well):
There's also a specific sbtopts file where you can persist this memory setting:
Find a file in Mac/Linux:
/usr/local/etc/sbtopts
Or in Windows
C:\Program Files (x86)\sbt\conf
and add below configuration:
# set memory options
#
-mem 2048
Hopefully any of these tips will help someone with this problem.
EDIT:
If anyone using IntelliJ IDEA like me, you can increase the sbt memory usage using the VM Parameters as in the picture below.
-Xmx4G
Having a look at the launcher script for running sbt, which on my system resides at /usr/share/sbt/bin/sbt, we see the following:
declare -r sbt_opts_file=".sbtopts"
declare -r etc_sbt_opts_file="/etc/sbt/sbtopts"
declare -r dist_sbt_opts_file="${sbt_home}/conf/sbtopts"
...
# Here we pull in the default settings configuration.
[[ -f "$dist_sbt_opts_file" ]] && set -- $(loadConfigFile "$dist_sbt_opts_file") "$#"
# Here we pull in the global settings configuration.
[[ -f "$etc_sbt_opts_file" ]] && set -- $(loadConfigFile "$etc_sbt_opts_file") "$#"
# Pull in the project-level config file, if it exists.
[[ -f "$sbt_opts_file" ]] && set -- $(loadConfigFile "$sbt_opts_file") "$#"
# Pull in the project-level java config, if it exists.
[[ -f ".jvmopts" ]] && export JAVA_OPTS="$JAVA_OPTS $(loadConfigFile .jvmopts)"
run "$#"
Thus we can put configuration settings in:
.jvmopts
.sbtopts
/etc/sbt/sbtopts
${sbt_home}/conf/sbtopts
For example, typelevel/cats project uses .jvmopts to set -Xmx3G. Alternatively we could do
echo "-mem 2048" >> .sbtopts
Regarding environmental variablessbt -h documents that
JAVA_OPTS environment variable, if unset uses "$java_opts"
.jvmopts if this file exists in the current directory, its contents
are appended to JAVA_OPTS
SBT_OPTS environment variable, if unset uses "$default_sbt_opts"
.sbtopts if this file exists in the current directory, its contents
are prepended to the runner args
For example,
export JAVA_OPTS=-Xmx2G
sbt
should run sbt with 2G of memory.
Note that if you are running tests in forked JVM, then you can increase memory via javaOptions setting in build.sbt like so:
Test / fork := true
Test / javaOptions ++= Seq("-Xmx4G")
VisualVM is a useful tool to see what settings were passed to a JVM process when experimenting with different ways of configuring SBT.

How to deploy to multiple environments with webpack using msdeploy

I've got a .NET WebAPI solution, and a UI built in Angular2 RC4 (angular-cli webpack version). I'm confused about how to deploy these to different environments, especially configuration parameters - there seems to be a mismatch between the .NET way and the UI way of doing things, which I don't quite get.
Here's how I've got it currently in TeamCity. The WebAPI solution is built once only, and is configured at deploy time. The various configuration parameters the project needs (such as connection strings, endpoints etc.) are stored in web.config. When I deploy to my test environment using MSDeploy, I pass in setParam arguments to the MSDeploy command line which replaces the connection strings and endpoints in the web.config with those values. When I deploy to production, I use the same build but pass in different arguments to the setParam in the command line.
This approach makes sense to me because I know that the exact same build is going from one environment to the next, the only difference being the parameters I specifically told it to set for each environment. Super.
With Angular2 and webpack it looks like a different approach is needed. When I build my project (with ng build -prod) it minimizes and bundles my HTML and Javascript files into 3 or 4 files, along with gzipped versions of those files. This is great for reducing file size and increasing speed of my website, but there is no way to "inject" configuration parameters into these gzip files like there is with MSDeploy's setParam. Everywhere I've seen that mentions webpack is showing webpack.dev.config.js and webpack.prod.config.js. But doesn't that mean we need to build a different bundle for each environment? And actually with Angular2 the webpack bit is considered "a black box" and it's not possible to supply your own webpack.config file anyway.
The only workaround I can think of is to use TeamCity's "File Content Replacer" on the "main.1234abcd6946c6a08519.bundle.js" to replace my configuration parameters with the values for that environment, then gzip that file - overwriting the one created by webpack.
But this is horrible, so I'm looking for any better suggestions?
I don't have any experience with webpack or if this is better than your workaround but you can use the TextFile kind of setParam entry to alter any file in your project using Regex find/replace at deploy time.
https://technet.microsoft.com/en-us/library/dd569084(v=ws.10).aspx
I went with creating a separate package for each environment. I added a build step that replaces my API URL on localhost in src\app\environment.ts, with the appropriate URL for that environment, then it runs npm build -prod and then MSDeploy to create the package. I do this for all environments I want to target.
Here's the script:
REM =====CREATE TEST PACKAGE==================================================
REM backup the environment file
ren src\app\environment.ts environment.ts.bak
copy /Y src\app\environment.ts.bak src\app\environment.ts
REM replace localhost in environment file with the TEST environment URL
"%env.FART%" src\app\environment.ts http://localhost:12345 %TEST.api.url%
REM build using this environment
call npm run build-prod
REM restore backup environment file
del /Q src\app\environment.ts
ren src\app\environment.ts.bak environment.ts
REM create TEST package
"%env.MSDEPLOY%" ^
-verb:sync ^
-source:contentPath="%teamcity.build.workingDir%\dist" ^
-dest:package="%teamcity.build.checkoutDir%\Package_TEST.zip"
REM =====CREATE PROD PACKAGE==================================================
REM backup the environment file
ren src\app\environment.ts environment.ts.bak
copy /Y src\app\environment.ts.bak src\app\environment.ts
REM replace localhost in environment file with the PROD environment URL
"%env.FART%" src\app\environment.ts http://localhost:12345 %PROD.api.url%
REM build using this environment
call npm run build-prod
REM restore backup environment file
del /Q src\app\environment.ts
ren src\app\environment.ts.bak environment.ts
REM create PROD package
"%env.MSDEPLOY%" ^
-verb:sync ^
-source:contentPath="%teamcity.build.workingDir%\dist" ^
-dest:package="%teamcity.build.checkoutDir%\Package_PROD.zip"
By the way, %env.FART% is the location of fart.exe which is a great find/replace tool that I use to replace one string in a file with another.

Windows Batch error: "'ping' is not recognized as an internal or external command operable program or batch file."

I am trying to run this command in windows:
ping -n 5 127.0.0.1 > nul
I get the error:
'ping' is not recognized as an internal or external command operable
program or batch fie.
Why can't windows find ping? Here is my script where it does not work:
#ECHO OFF
::set path
SET path=M:\\5.bmp
:findfile
IF EXIST %path% (
ECHO File found
) ELSE (
ECHO File not found
ping -n 5 127.0.0.1 > nul
goto findfile
)
You have overridden the PATH environment variable, so the command processor can no longer find the ping executable.
The fix is nice and simple - just use a different variable name!
:: set path
SET MyPath=M:\\5.bmp
:findfile
IF EXIST %MyPath% (
Please note that if you genuinely wanted to set the path environment variable, you should append to it like so:
REM Set temporarily for this session
SET PATH=%PATH%;C:\Some\Folder
REM Set permanently (but note - this change will not be made to this session)
SETX PATH=%PATH%;C:\Some\Folder
Hi to fix "ping" please follow below steps
Go to Properties in My computer
Advanced system settings ----->Advanced -----> Environment Variables
Select 'PATH' from the list of system variables and edit and set PATH to c:\windows\system32 ; this will solve your problem.
-----> if still u have a problem, do the below steps...
Control Panel --> System and security --> Windows Firewall --> Advanced settings --> Inbound rules --> New rule --> custom rule
in Protocol and ports: Protocol: ICMPv4
on the same panel go to customize, choose "Specific ICMP types", check the box "echo request"
The rest is trivial; go to next... next... and save it.
You should be done. This box responds ping from this point on.
Cheers
Prasad
How to diagnose this error:
'ping' is not recognized as an internal or external command operable
program or batch fie.
Because your path environment variable does not contain the directory that points to the executable: ping.exe. So the question becomes why can't your command line program cmd.exe locate ping.exe?
You can print out your path variable on the commandline like this:
echo %PATH%
Which prints for me:
C:\WINDOWS;C:\WINDOWS\system32;C:\Program Files\jZip;C:\MinGW\bin
The above string is delimited by semicolons(;). Notice the element called: C:\WINDOWS\System32, that is the element that defines where ping.exe can be located.
Solutions
You didn't specify C:\WINDOWS\System32 in your path variable. Make sure it is there.
ping.exe is missing. Find out who deleted it and put it back.
ping.exe is corrupt. Run it where it sits: C:\WINDOWS\System32\ping.exe, or replace ping.exe.
You have overridden the PATH variable before you look for it.