Wildcard in Jar name - java

I am running one jdk command in window batch file as:
javaw -Xms256M -Xmx1024M -Dspring.profiles.active=local -Dport=9001 -jar C:\Users\sampleJAR\myProj-1.0.0.jar
But, every 2 weeks we will have new version coming up and old jar will be replaced by new jar automatically so I was thinking to use wildcard with something like:
javaw -Xms256M -Xmx1024M -Dspring.profiles.active=local -Dport=9001 -jar C:\Users\sampleJAR\myProj-*.jar
I referred lots of articles online which suggested to use *, surround jar name with "" when using *,... None of them worked.

I believe that the articles you are looking at are in reference to the classpath option wildcard expansion.
The -jar option doesn't do this wildcard expansion and expects a filename without any wildcards.
You could try specifying the classpath with the wildcard and then putting the class name that you want to run at the end of the command. Hopefully like:
javaw -Xms256M -Xmx1024M -Dspring.profiles.active=local -Dport=9001 -cp "C:\Users\sampleJAR\*" com.my.classname

Related

How can I execute .jar file from the terminal without specifying its name

How can I execute .jar file in folder from the Windows cmd without specifying its name.
I have tried below command (as there is only 1 jar in that folder I used *) but its not working(Error: Unable to access jarfile *.jar
).
java -jar *.jar
I am not sure it would be a good idea to just run everything in a directory, but you could:
FOR %A IN ("*.jar") DO (java -jar "%~A")
So what you appear to be asking is how to run the command
% java -jar somelongname.jar
as
% java -jar *.jar
to avoid some typing. That's not possible, because neither the Windows CMD shell or the java command is going to expand the *.jar wildcard pattern.
(On Linux / Unix / MacOS, the shell does wildcard expansion before passing arguments to a command. On Windows, it is the responsibility of the command to do this. In practice, it appears that the java command only expands wildcards in the arguments that are going to be passed to your application; see Stop expanding wildcard symbols in command line arguments to Java)
So if you want to avoid typing those pesky characters on Windows, you will need to do something like:
write a simple BAT file to run "java -jar somelongname.jar", or
write a clever BAT file to identify and run a JAR file that matches "*.jar", or
use Powershell.
For what it is worth, I think what you are trying to do is rather dangerous. This is a bit like typing "di*" to run the "dir". What if there is some other more dangerous command on the PATH that is going to match instead of "dir"?

Resolve CLASSPATH with two JARs

I have a java app that needs two jar files to run. craftbukkit.jar is the one that holds the main function, and commons-dbcp-1.4.jar is what I need to allow mysql pooling. I am having issues getting the CLASSPATH to behave properly.
Can someone help point out what I am doing wrong here?
java -Xincgc -Xmx1G -cp "craftbukkit.jar;commons-dbcp-1.4.jar" org.bukkit.craftbukkit.Main nogui
Can't seem to find the Main when i do this, and without the commonds-dbcp-1.4.jar it fails to load properly.
Use java -Xincgc -Xmx1G -cp craftbukkit.jar:commons-dbcp-1.4.jar org.bukkit.craftbukkit.Main nogui
No quotes, and use :, not ;.
Add the line
Class-Path: commons-dbcp-1.4.jar
to Manifest.mf and make sure you leave an empty line at the end of the file assuming that commons-dbcp-1.4.jar is in the same directory.
Check your "path separator". Wich OS you are running on?
For Windows, path separator is ";". On Linux you should use ":"
Windows:
java -Xincgc -Xmx1G -cp "craftbukkit.jar;commons-dbcp-1.4.jar" org.bukkit.craftbukkit.Main nogui
Linux:
java -Xincgc -Xmx1G -cp "craftbukkit.jar:commons-dbcp-1.4.jar" org.bukkit.craftbukkit.Main nogui

Setting the classpath java error

I am trying to follow this tutorial to be able to use Jade (Java Agent Development Framework). I am pretty new with java. I have a problem with this command: (I am using Mac OSx)
java -cp lib\jade.jar;classes jade.Boot -gui -agents ping1:examples.PingAgent.PingAgent
I get this error:
Usage: java [-options] class [args...]
(to execute a class)
or java [-options] -jar jarfile [args...]
(to execute a jar file)
...
-bash: classes: command not found
I have set my environment variables like this:
export CLASSPATH=$CLASSPATH:/Applications/jade/classes
export CLASSPATH=$CLASSPATH:/Applications/jade/lib/jade.jar
and here is the hierarchy of the folders:
If you need some more information to understand the problem please let me know.
Try adding quotes around your class path: java -cp "lib\jade.jar;classes" .... Without them, bash interprets the semi colon as the start of a new command, which causes the error message -bash: classes: command not found
Edit
It just struck me that you of course are running in *nix. Then the path separator would be :, not ;. Then the quotes shouldn't even be needed. Semi colon is the path separator in Windows.
Try
java -cp "lib\jade.jar;classes" jade.Boot -gui -agents ping1:examples.PingAgent.PingAgent
Looks like bash is treating the ; as end of command and treats classes as a new command.
The command is in Windows notation, not Unix one. On Unix systems You have to use lib/jade.jar instead of lib\jade.jar

Perl Escape Quotes Problem

Pardon me if this is too trivial.
I am doing an XSLT by calling system() in Perl script like this:
system("java -Xms256m -Xmx512m -jar $saxonJar -o $tmpFile $inFile $xslFile $saxonParams");
$inFile is a string that contains a relative path to the xml file that is going to be translated using XSLT.This worked fine except for those $inFile that has space in the string, for example, like "Intro to Dance.htm", then it will report a syntax error.
If this is in MS-DOS, then I can easiliy get around this problem by putting a quote around the $inFile string in the XSLT command. I did try putting escape in the above command like:
system("java -Xms256m -Xmx512m -jar $saxonJar -o $tmpFile \"$inFile\" $xslFile $saxonParams");
It does not work. Could anybody help how should I put quotes around $inFile?
Thanks.
You can avoid the shell (and thus shell-escaping problems) by passing your command line to system as a list instead. Try
system( 'java', '-Xms256m', '-Xmx512m', '-jar', $saxonJar, '-o', $tmpFile, $inFile, $xslFile, $saxonParams );
See the perldoc for system for more on how this works.
Is this, in fact, MS-DOS?
You said it didn't work, but not what actually happened. Did you get an error? What was it?
If this is on a Unixish system, just substitute single quotation marks:
system("java -Xms256m -Xmx512m -jar $saxonJar -o $tmpFile '$inFile' $xslFile $saxonParams");
I don't know if that will work on MS-DOS or not.
If the filename contains " or ' it becomes a little more complex, because those will need to be preserved at the shell level:
$inFile =~ s/(['"])/\\$1/g;
system("java -Xms256m -Xmx512m -jar $saxonJar -o $tmpFile \"$inFile\" $xslFile $saxonParams");
(Or something similar.)
Better still, use the multi-argument form:
system('java', '-Xms256m', '-Xmx512m', '-jar', $saxonJar, '-o', $tmpFile,
$inFile, $xslFile, $saxonParams);
and let the interpreter and the shell figure it out.

Passing arguments to java vm from NSIS script

I'm developing my first java application using Eclipse. I've recently needed to adjust the amount of memory allocated by passing -Xmx256M to the JVM. The application is currently package up as a runnable jar and installed using the NSIS.
I'm having a problem passing arguments to the jar file once its installed. What is the common practice for doing this? Here is what I'm currently doing in my nsi file:
CreateShortcut "$SMPROGRAMS\$StartMenuGroup\$(^Name).lnk" "$SYSDIR\javaw.exe" "-Xmx256M -jar $INSTDIR\Foo.jar"
This results in the following being created as the shortcut Target on windows:
C:\WINDOWS\system32\javaw.exe -Xmx256M -jar C:\Program Files\Foo\Foo.jar
Unfortunately this does not work due to the space in C:\Program Files, If I change the link created manually to include quotes all is well:
C:\WINDOWS\system32\javaw.exe -Xmx256M -jar "C:\Program Files\Foo\Foo.jar"
UPDATE: Ordering of -jar and -Xmx256M swapped. The issue remains the same however. The spaces in the path to the jar file are causing an issue. I think I either need to find a way of adding quotes into the command, as shown when I manually change the target, or change my approach completely!
NSIS strings can be quoted with single quotes, double quotes, or the backward single quote. You can also escape with $\ ($\" etc)
CreateShortcut "$SMPROGRAMS\$StartMenuGroup\$(^Name).lnk" '"$SYSDIR\javaw.exe"' '-Xmx256M -jar "$INSTDIR\Foo.jar"'
Have you tried keeping the quotes in but escaping the path separators?
C:\WINDOWS\system32\javaw.exe -Xmx256M -jar "C:\\Program Files\\Foo\\Foo.jar"
Pretty sure you should put quotes around "C:\WINDOWS\system32\javaw.exe" even though there are no spaces.

Categories

Resources