Error Expanding Script Generated Classpath for Java in PowerShell Script - java

Synopsis:
I am trying to convert a shell script from UNIX to Powershell.
The script cannot "hardcode" the path, but must instead list a directory to dynamically build the path at runtime.
Also, the script must pass in 1 parameter to indicate the "type" of the run.
I am placing my "attempted" re-write of the script (after much googling/binging)
This script might be very close as the "echo" statements produced what seems to be correct.
$EXE_CLASS="com.sungard.sims.dacar.standalone.Dacar"
#$DACAR_TAG=%1
$JAVA_EXE="$ENV:JDK15\jre\bin\java"
#JAVA_EXE=\opt\java\bin\java
$JARS="dist\lib\Dacar-Engine.jar;dist\lib\Dacar-Common.jar;dist\lib\Dacar-Collector.jar;dist\lib\standalone-Dacar.jar;dist\lib\DACAR-CRG.jar;"
#dynamically append all .jar files from the jars directory.
ls jars\*.jar | % { $JARS +=";jars\"+ $_.name }
$JAVA_OPTS="-server -Xloggc:.\engine.gc.log -Xmx2048m -Xms2048m -XX:NewSize=512m -XX:MaxNewSize=512m -XX:SurvivorRatio=8 -XX:+UseParNewGC -XX:+UseConcMarkSweepGC -XX:MaxTenuringThreshold=8 -XX:CMSInitiatingOccupancyFraction=60 -XX:+PrintGCTimeStamps -XX:MaxPermSize=128m -XX:PermSize=128m -DinstName=${DACAR_TAG} -DprocType=ENGINE"
echo "exe: -> $JAVA_EXE"
echo "opts: -> $JAVA_OPTS"
echo "jars: -> $JARS"
echo "class: -> $EXE_CLASS"
& $JAVA_EXE $JAVA_OPTS "-classpath .\configuration;$JARS $EXE_CLASS 1> dacar.out 2> dacar.err"
please note that I have commented out the use of the DACAR_TAG which would normally be passed in as %1 in batch script containing "TEST|DEV|PROD|QA|STRESS|[CLIENT SPECIFIC VALUE]"
Here is the output:
PS C:\dacar> .\startDacar.ps1
exe: -> c:\Program Files\Java\jdk1.5.0_22\jre\bin\java
opts: -> -server -Xloggc:.\engine.gc.log -Xmx2048m -Xms2048m -XX:NewSize=512m -XX:MaxNewSize=512m -XX:SurvivorRatio=8 -XX:+UseParNewGC -XX:+UseConcMarkSweepGC -XX:MaxTe
nuringThreshold=8 -XX:CMSInitiatingOccupancyFraction=60 -XX:+PrintGCTimeStamps -XX:MaxPermSize=128m -XX:PermSize=128m -DinstName=TESTING -DprocType=ENGINE
jars: -> dist\lib\Dacar-Engine.jar;dist\lib\Dacar-Common.jar;dist\lib\Dacar-Collector.jar;dist\lib\standalone-Dacar.jar;dist\lib\DACAR-CRG.jar;;jars\activation.jar;jars
\commons-beanutils-1.6.jar;jars\commons-codec-1.3.jar;jars\commons-collections-3.2.jar;jars\commons-configuration-1.4.jar;jars\commons-dbcp-1.4.jar;jars\commons-digester
-1.6.jar;jars\commons-discovery-0.4.jar;jars\commons-id.jar;jars\commons-lang-2.2.jar;jars\commons-logging-1.0.3.jar;jars\commons-pool-1.5.4.jar;jars\concurrent.jar;jars
\graphics.jar;jars\ha-javamail-1.0-beta-1.jar;jars\hsqldb.jar;jars\ibatis-core-3.0.jar;jars\jcommon-1.0.6.jar;jars\jconn3.jar;jars\jdom.jar;jars\jetty-6.1.15.jar;jars\je
tty-util-6.1.15.jar;jars\jfreechart-1.0.3.jar;jars\jgroups-all.jar;jars\jmxri.jar;jars\jta.jar;jars\junit.jar;jars\log4j-1.2.9.jar;jars\mailapi.jar;jars\postgresql-8.0.3
09.jdbc2ee.jar;jars\postgresql-8.4-701.jdbc3.jar;jars\quartz-1.6.0.jar;jars\servlet-api-2.5-20081211.jar;jars\smtp.jar;jars\svnant.jar;jars\svnClientAdapter.jar;jars\svn
javahl.jar;jars\truezip-6.jar;jars\uic-optional.jar;jars\uic.jar
class: -> com.sungard.sims.dacar.standalone.Dacar
Unrecognized option: -server -Xloggc:.\engine.gc.log -Xmx2048m -Xms2048m -XX:NewSize=512m -XX:MaxNewSize=512m -XX:SurvivorRatio=8 -XX:+UseParNewGC -XX:+UseConcMarkSweepG
-XX:MaxTenuringThreshold=8 -XX:CMSInitiatingOccupancyFraction=60 -XX:+PrintGCTimeStamps -XX:MaxPermSize=128m -XX:PermSize=128m -DinstName=TESTING -DprocType=ENGINE
Could not create the Java virtual machine.
Adding the tag will be my next question if I can't figure this out.
JUST AS AN FYI, from with in a ps1 script I can start it the program with the following command successfully:
& "c:\Program Files\Java\jdk1.6.0_20\jre\bin\java" -server -Xloggc:.\engine.gc.log -Xmx2048m -Xms2048m -XX:NewSize=512m -XX:MaxNewSize=512m -XX:SurvivorRatio=8 -XX:+UseParNewGC -XX:+UseConcMarkSweepGC -XX:MaxTenuringThreshold=8 -XX:CMSInitiatingOccupancyFraction=60 -XX:+PrintGCTimeStamps -XX:MaxPermSize=128m -XX:PermSize=128m -DinstName=TESTING -DprocType=ENGINE -classpath ".\configuration;dist\lib\Dacar-Engine.jar;dist\lib\Dacar-Common.jar;dist\lib\Dacar-Collector.jar;dist\lib\standalone-Dacar.jar;dist\lib\DACAR-CRG.jar;;jars\activation.jar;jars\commons-beanutils-1.6.jar;jars\commons-codec-1.3.jar;jars\commons-collections-3.2.jar;jars\commons-configuration-1.4.jar;jars\commons-dbcp-1.4.jar;jars\commons-digester-1.6.jar;jars\commons-discovery-0.4.jar;jars\commons-id.jar;jars\commons-lang-2.2.jar;jars\commons-logging-1.0.3.jar;jars\commons-pool-1.5.4.jar;jars\concurrent.jar;jars\graphics.jar;jars\ha-javamail-1.0-beta-1.jar;jars\hsqldb.jar;jars\ibatis-core-3.0.jar;jars\jcommon-1.0.6.jar;jars\jconn3.jar;jars\jdom.jar;jars\jetty-6.1.15.jar;jars\jetty-util-6.1.15.jar;jars\jfreechart-1.0.3.jar;jars\jgroups-all.jar;jars\jmxri.jar;jars\jta.jar;jars\junit.jar;jars\log4j-1.2.9.jar;jars\mailapi.jar;jars\postgresql-8.0.309.jdbc2ee.jar;jars\postgresql-8.4-701.jdbc3.jar;jars\quartz-1.6.0.jar;jars\servlet-api-2.5-20081211.jar;jars\smtp.jar;jars\svnant.jar;jars\svnClientAdapter.jar;jars\svnjavahl.jar;jars\truezip-6.jar;jars\uic-optional.jar;jars\uic.jar" com.sungard.sims.dacar.standalone.Dacar
But that is not really an option, as That is just invoking the thing in a hard coded fashion.

One thing to note about PowerShell variable expansion is that if it's anything more than a simple $VARIABLE expression you typically need to escape it using curly braces or a sub-expression.
So this line:
$JAVA_EXE="$ENV:JDK15\jre\bin\java"
Could be represented as either:
$JAVA_EXE="${ENV:JDK15}\jre\bin\java"
or...
$JAVA_EXE="$($ENV:JDK15)\jre\bin\java"
EDIT: Apparently PowerShell does
correctly evaluate all 3 examples. I
seem to recall the first syntax not
working but perhaps that was in
PowerShell 1.0 or a CTP...
Another useful tip that I often suggest people do when working with external .exe commands is to map it to an alias using the Set-Alias command. This way it makes working with the command a lot more natural as you don't have to use the &"string" syntax.
Set-Alias java "$($ENV:JDK15)\jre\bin\java.exe"
java blah1 blah2 etc

Related

Error: Could not create the Java Virtual Machine. Spigot Minecraft

i'm trying to install spigot server on debian 10, when i run start.sh:
#!/bin/sh
while true
do
java -Xms4G -Xmx4G -XX:+UseG1GC -XX:+ParallelRefProcEnabled -XX:MaxGCPauseMillis=200 -
XX:+UnlockExperimentalVMOptions -$
echo "restarting in 10"
sleep 10
done
i've got this output:
i don't have any idea on how to fix it, any help?
The script seems to require an argument which should be the jar name.
Also, you put a wrong back to break line ("\n") which seems to break the bash.
For me, you should replace -$ by the jar file or spigot, like that:
#!/bin/sh
while true
do
java -Xms4G -Xmx4G -XX:+UseG1GC -XX:+ParallelRefProcEnabled -XX:MaxGCPauseMillis=200 -XX:+UnlockExperimentalVMOptions spigot-1.18.jar
echo "Restarting in 10 seconds"
sleep 10
done
The script is not correct.
#!/bin/sh
while true
do
java -Xms4G -Xmx4G -XX:+UseG1GC -XX:+ParallelRefProcEnabled -XX:MaxGCPauseMillis=200 -XX:+UnlockExperimentalVMOptions -XX:+DisableExplicitGC -XX:+AlwaysPreTouch -XX:G1NewSizePercent=30 - XX:G1MaxNewSizePercent=40 -XX:G1HeapRegionSize=8M -XX:G1ReservePercent=20 -XX:G1HeapWastePercent=5 -XX:G1MixedGCCountTarget=4 -XX:InitiatingHeapOccupancyPercent=15 -XX:G1MixedGCLiveThresholdPercent=90 -XX:G1RSetUpdatingPauseTimePercent=5 -XX:SurvivorRatio=32 -XX:+PerfDisableSharedMem -XX:MaxTenuringThreshold=1 -Dusing.aikars.flags=https://mcflags.emc.gs -Daikars.new.flags=true -jar spigot.jar nogui
echo "restarting in 10"
sleep 10
done
Reference: https://www.vultr.com/docs/setup-spigot-on-debian-10/

Heap and PermGenspace increase in tomcat

I see that tons of questions posted in SO and other sites to increase tomcat memory when outoferror occurs. But none of them looks the same because some of them said use CATALINA_OPTS and some said JAVA_OPTS. and the location mostly they said like bin/setenv.sh if no file created it.
I follow the above things and still could not set the memory correctly as expected.
I have created the setenv.sh file inside bin directory of currently using tomcat.But still heap space is not increased.
CATALINA_OPTS="-Dfile.encoding=UTF-8 -server -Xms512m -Xmx1024m -XX:PermSize=512m -XX:MaxPermSize=1024m -XX:+DisableExplicitGC"
this is my content of setenv.sh and please anyone explain what is the problem here, and whether set or export need to use in setenv.sh.
Can any one guide me for this?
Please try to edit the bin/setenv.sh
export CATALINA_OPTS="-Dfile.encoding=UTF-8 -server -Xms512m -Xmx1024m -XX:PermSize=512m -XX:MaxPermSize=1024m -XX:+DisableExplicitGC"
JAVA_OPTS is passed to all JVM processes running on the same machine.
Use CATALINA_OPTS if you specifically want to pass JVM arguments to Tomcat.
By using the ps -eaf | grep 'tomcat' in the terminal, we can confirm the values.
Eg.,
root 32451 1 99 13:57 pts/1 00:00:07 /usr/java/jdk1.7.0_79/bin/java
-Djava.util.logging.config.file=/opt/apache-tomcat/conf/logging.properties
-Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager
-Dfile.encoding=UTF-8 -server -Xms512m -Xmx1024m -XX:PermSize=512m -XX:MaxPermSize=1024m -XX:+DisableExplicitGC
-Djava.endorsed.dirs=/opt/apache-tomcat/endorsed -classpath /opt/apache-tomcat/bin/bootstrap.jar:/opt/apache-tomcat/bin/tomcat-juli.jar
-Dcatalina.base=/opt/apache-tomcat
-Dcatalina.home=/opt/apache-tomcat
-Djava.io.tmpdir=/opt/apache-tomcat/temp org.apache.catalina.startup.Bootstrap start

Running jar in eclipse works slower

I try to split OpenStreeemMap which weights 350MB into smaller peaces using http://wiki.openstreetmap.org/wiki/OSMT. When I run it from cmd line it finishes in like 40s.
However, when I try to import it to Eclipse and invoke method it takes like 15 minutes or it stucks.
I set Xmx1024m and Xms256m in Eclipse run configuration. I tried to run command line from Java code but this also runs very slowly.
1) You can compare all the VM arguments:
[How to get vm arguments from inside of java application?
2) If you are interested, You can try JVMMonitor (Eclipse Market Place).
36128 osmt.Main --split ----index-file=D:/Splitter/Splitted/node2tn --output-dir=D:/Splitter/Splitted --tile-size=0.1 D:/Splitter/map
4696 -Dosgi.requiredJavaVersion=1.6 -Xms40m -Xmx512m -XX:MaxPermSize=256m
28344 it.polito.appeal.traci.examples.OpenStepsClose -agentlib:jdwp=transport=dt_socket,suspend=y,address=localhost:61123 -Xmx1024M -Xms256M -Dfile.encoding=Cp1252
20748 com.sun.javaws.Main -secure C:\Users\xxx\AppData\LocalLow\Sun\Java\Deployment\cache\6.0\45\3ca5a4ad-384499c4 -DcmxServerMode=ejb -Dorg.omg.CORBA.ORBClass=com.ibm.CORBA.iiop.ORB -Dorg.omg.CORBA.ORBSingletonClass=com.ibm.rmi.corba.ORBSingleton -Djavax.rmi.CORBA.StubClass=com.ibm.rmi.javax.rmi.CORBA.StubDelegateImpl -Djavax.rmi.CORBA.PortableRemoteObjectClass=com.ibm.rmi.javax.rmi.PortableRemoteObject -Djava.naming.factory.url.pkgs=com.ibm.ws.naming -Dcom.ibm.CORBA.enableClientCallbacks=true -Xbootclasspath/a:C:\Program Files (x86)\Java\jre7\lib\deploy.jar;C:\Program Files (x86)\Java\jre7\lib\javaws.jar;C:\Program Files (x86)\Java\jre7\lib\plugin.jar -Xverify:remote -Xmx512m -Xms128m
37200 sun.tools.jps.Jps -lvm -Denv.class.path=C:\Users\xxx\Desktop\JADE\;D:\Splitter -Dapplication.home=C:\Program Files (x86)\Java\jdk1.6.0_45 -Xms8m
28224 -Dosgi.requiredJavaVersion=1.6 -Xms40m -Xmx512m -XX:MaxPermSize=256m
So as we can see when I run it from Eclipse its task 28344 , when I run from cmd its probabaly 37200

java command line batch file

I have following command line batch file
REM test
call java -server -Xms2048m -Xmx4096m -XX:MaxPermSize=512m -Dlog4j.configuration=file:///C:/codex/props/log4j.xml -Dlog4j.output.dir=C:/logs//codex-logs -jar codex-1.0.jar
Question is that is there anyway file can be maintain format having carriage return lines?
something like following for better reading and maintainability???
REM test
call java -server -Xms2048m -Xmx4096m -XX:MaxPermSize=512m
-Dlog4j.configuration=file:///C:/codex/props/log4j.xml
-Dlog4j.output.dir=C:/logs//codex-logs
-jar codex-1.0.jar
I think Jiri Kremser's answer is correct but if your goal is "better reading and maintainability" , you can use variables too:
REM test
set var1=java -server -Xms2048m -Xmx4096m -XX:MaxPermSize=512m
set var2=-Dlog4j.configuration=file:///C:/codex/props/log4j.xml
set var3=-Dlog4j.output.dir=C:/logs//codex-logs
set var4=-jar codex-1.0.jar
echo %var1% %var2% %var3% %var4%
call %var1% %var2% %var3% %var4%
Use the character ^ for it
REM test
call java -server -Xms2048m -Xmx4096m -XX:MaxPermSize=512m^
-Dlog4j.configuration=file:///C:/codex/props/log4j.xml^
-Dlog4j.output.dir=C:/logs//codex-logs^
-jar codex-1.0.jar
I believe adding simply the backslash '\' at the end of each line will allow you make it behave like one line. Since it escapes the newline character.

Play Framework Run Application Issue

I am getting the following error whenever i am trying to run a new Web Application created using Play.
Error occurred during initialization of VM
Could not reserve enough space for object heap
Error: Could not create the Java Virtual Machine.
Error: A fatal exception has occurred. Program will exit.
In Play framework 2.0.3, <play framework install dir>\framework\build.bat script you need to replace the command line argument for the command below
java -Xms512M -Xmx1024M -Xss1M -XX:+CMSClassUnloadingEnabled -XX:MaxPermSize=256M %DEBUG_PARAM% -Dfile.encoding=UTF8 -Dplay.version="%PLAY_VERSION%" -Dsbt.ivy.home="%~dp0..\repository" -Dplay.home="%~dp0." -Dsbt.boot.properties="file:///%p%sbt/sbt.boot.properties" -jar "%~dp0sbt\sbt-launch.jar" %*
Into
java -XX:+CMSClassUnloadingEnabled %DEBUG_PARAM% -Dfile.encoding=UTF8 -Dplay.version="%PLAY_VERSION%" -Dsbt.ivy.home="%~dp0..\repository" -Dplay.home="%~dp0." -Dsbt.boot.properties="file:///%p%sbt/sbt.boot.properties" -jar "%~dp0sbt\sbt-launch.jar" %*
Just downloaded and unzipped 2.2.1 on my Windows 8 computer.
Followed the documentation at Play Framework website, and ended up having the same issue as you. Adjusting the various parameters in the build file didn't do anything, but the:
java -XX:+CMSClassUnloadingEnabled %DEBUG_PARAM% -Dfile.encoding=UTF8 -Dplay.version="%PLAY_VERSION%" -Dsbt.ivy.home="%~dp0..\repository" -Dplay.home="%~dp0." -Dsbt.boot.properties="file:///%p%sbt/sbt.boot.properties" -jar "%~dp0sbt\sbt-launch.jar" %*
... solved the problem.
I don't know where other people found this solution, but there's no mentioning of this solution on the Play Framework website. In fact, there's nothing to suggest that anything could go wrong. After all, it's just a file you need to unzip.
It's running now, however it's a little hard to trust a framework that screws up that early on. Seems the authors don't test on anything but Linux.
in 2.3 Play framework :
GO to :
C://Play2.3/framework/build.bat and open this file and make these changes.
Replace this line with below line.
java -Xms512M -Xmx1024M -Xss1M -XX:+CMSClassUnloadingEnabled -XX:MaxPermSize=256M %DEBUG_PARAM% -Dfile.encoding=UTF8 -Dplay.version="%PLAY_VERSION%" -Dsbt.ivy.home="%~dp0..\repository" -Dplay.home="%~dp0." -Dsbt.boot.properties="file:///%p%sbt/sbt.boot.properties" -jar "%~dp0sbt\sbt-launch.jar" %*
java -XX:+CMSClassUnloadingEnabled %DEBUG_PARAM% -Dfile.encoding=UTF8 -Dplay.version="%PLAY_VERSION%" -Dsbt.ivy.home="%~dp0..\repository" -Dplay.home="%~dp0." -Dsbt.boot.properties="file:///%p%sbt/sbt.boot.properties" -jar "%~dp0sbt\sbt-launch.jar" %*
then type this command on command promt:
C:\Users\k.ashish\Downloads\play-2.2.3\play-2.2.3\yourapp>play
C:\Users\k.ashish\Downloads\play-2.2.3\play-2.2.3\yourapp>run
If you are not able to execute this command then set the play2.3 framework path in Environment variable in windows like java path .

Categories