-I flag JAVA command # .bat CMAKE - java

I have to extract and generate some .h files from a jar and idl file.
Need to use a .bat from external developers:
#echo off
java -jar C:\WorkspaceSwim\trunk\iB\build\BlueGen\target\bluegen.jar -o C:\WorkspaceSwim\trunk\Example\Distribution\build\GeneratedDDSFiles C:\WorkspaceSwim\trunk\Example\Distribution\Flight.idl
set NDDSHOME=C:\WorkspaceSwim\trunk\iB\build\ToolBox\NDDS
set RPCDDSHOME=C:\WorkspaceSwim\trunk\iB\build\ToolBox\RPCDDS
setlocal
set dir=%~dp0
set args=%1
:getarg
shift
if "%~1"=="" goto continue
set args=%args% %1
goto getarg
:continue
set JREHOME=%JAVA_HOME%
"%JREHOME%\bin\java" -DPATH="%PATH%" -DNDDSHOME="%NDDSHOME%" -DRPCDDSHOME="%RPCDDSHOME%" -Djava.ext.dirs="%RPCDDSHOME%\classes\" com.eprosima.rpcdds.idl.RPCDDSGEN %args% "-I%RPCDDSHOME% /idl"
I think there are some fail on the script , but i can't see it. Maybe a problem with quotes? i tryied this 3 posibilities :
"%JREHOME%\bin\java" -DPATH="%PATH%" -DNDDSHOME="%NDDSHOME%" -DRPCDDSHOME="%RPCDDSHOME%" -Djava.ext.dirs="%RPCDDSHOME%\classes\" com.eprosima.rpcdds.idl.RPCDDSGEN %args% "-I%RPCDDSHOME%\idl"
Error: principal class \idl doesn't found or load
"%JREHOME%\bin\java" -DPATH="%PATH%" -DNDDSHOME="%NDDSHOME%" -DRPCDDSHOME="%RPCDDSHOME%" -Djava.ext.dirs="%RPCDDSHOME%\classes" com.eprosima.rpcdds.idl.RPCDDSGEN %args% "-I%RPCDDSHOME%\idl"
Error: principal class com.eprosima.rpcdds.idl.RPCDDSGEN doesn't found or load
"%JREHOME%\bin\java" -DPATH="%PATH%" -DNDDSHOME="%NDDSHOME%" -DRPCDDSHOME="%RPCDDSHOME%" -Djava.ext.dirs="%RPCDDSHOME%\classes\ com.eprosima.rpcdds.idl.RPCDDSGEN %args%" -I "%RPCDDSHOME%\idl"
Unrecognized option: -I
Error: Could not create the Java Virtual Machine.
Previusly i use this .cmake to generate the code that will run this .bat
add_custom_command(
OUTPUT ${DDSGeneratedFiles}
COMMAND java -jar ${iB_BlueGen} -o ${GeneratedDDSDirName} ${LocatedFile}
COMMAND "set NDDSHOME=${iMASBlue_NDDS_DIR} &" "set RPCDDSHOME=${iB_RPCDDS_DIR} &" ${RPCDDSGenerator} -replace -d ${GeneratedDDSDirName} -I${CMAKE_CURRENT_SOURCE_DIR} ${LocatedFile}
DEPENDS ${IncludeDependencies}
MAIN_DEPENDENCY ${LocatedFile}
COMMENT "Calling RPCDDS Generator '${RPCDDSGenerator}' on '${IdlFile}'"
)
Thnx for your answers.

To debug batch files, change line
#echo off
in your batch file to
#echo on
and run again

Related

How to add jar to java project under linux

i use this shell script to start the java project
cd target
echo "shell parameters: $*"
java -classpath . com.tencent.Example $*
But now I need to use the jdbc jar,How should I modify the shell script and in which path to put the jar?
If the jar is in the current directory,Change the shell to this.
cd target
echo "shell parameters: $*"
java -classpath .:./mysql-connector-java-8.0.27.jar com.tencent.Example $*

Why isn't command line not finding finding my .java files?

I am using Windows CMD, and for some reason, I am getting this error message relating to my .java files. For example, I am typing:
javac FirstProgram.java
However, this error message occurs:
javac: file not found: FirstProgram.java
Usage: javac <options> <source files>
use -help for a list of possible options
I typed in javac -version, and I am currently using javac 1.8.0_144. Someone on in another Stack Overflow question suggested to change the System Variables. I used JAVA_HOME as the variable name, and I copied the path to my JDK folder, but thus far, I haven't had much luck. I still receive the same error message.
There are several problems here ... including why
PROBLEM 1:
"...I am not even allowed to save my FirstProgram.java in the Java
folder in Documents." <= ?!?
PROBLEM 2:
"...I got the error message about a false flag" <= This is probably a space " " in the path name
STRONG SUGGESTION:
Download Eclipse and try compiling and running your program from Eclipse. In other words, using an IDE, instead of the command line.
You can download Eclipse here:
http://eclipse.org
There is a good "starters tutorial" here:
Creating your first Java project
Run the dir or dir/p command to see your directory contents on your command prompt
c:\path\to\your program directory\dir
See if FirstProgram.java is listed or not? If not then you are in a wrong directory.
Now you have two options
You change to the correct directory using cd command or
You use the absolute path for your FirstProgram.java file
Navigate to that specific folder containing that program then [ Shift + L_Click ], click open cmd, then run it again to ensure it is being ran in that folder.
You should try to use absolute path while using the command if it says the file isn't found.
javac /some/directory/path/to/the/file/FirstProgram.java
Note: On command line, most of the shells would anyway not let you complete the path if the file doesn't exist there. And the other way if you're copying the path from an explorer/finder, it shall be guaranteed to be existing.
Edit: The absolute path as pointed out in comments would be using forward slashes in Windows, e.g :
javac \some\directory\path\to\the\file\FirstProgram.java
This is my a simplified DOSJavaIDE environment for simple test applications if Eclipse is too much of a hassle. I can point compiling and running an application to a specific JVM version. Study this script to see how folder structure and paths are given in each of the commands.
Folders and files
c:\projects\test1\classes\
c:\projects\test1\lib\
c:\projects\test1\lib\somelib1.jar
c:\projects\test1\lib\somelib2.jar
c:\projects\test1\src\
c:\projects\test1\src\test\GameLoop2.java
c:\projects\test1\src\META-INF\MANIFEST.MF
c:\projects\test1\javaenv.bat
javaenv.bat
#REM Standalone JavaDosEnvironment
#set JAVA_HOME=C:\Program Files\Java\jdk1.8.0_112
#"%JAVA_HOME%\bin\java" -version
#set cmd=%1
#if "%cmd%"=="" (
#echo Please specify command to run ^(1..n or empty to exit^)
#echo 1=Compile, 2=Jar, 12=CompileJar
#echo 3=Run-test1 GameLoop2 with vsync
#SET /p cmd="1..n: "
)
#IF /I "%cmd%"=="1" set cmd=compile
#IF /I "%cmd%"=="compile" call :COMPILE
#IF /I "%cmd%"=="2" set cmd=jar
#IF /I "%cmd%"=="jar" call :JAR
#IF /I "%cmd%"=="12" set cmd=compilejar
#IF /I "%cmd%"=="compilejar" (
call :COMPILE
call :JAR
)
#IF /I "%cmd%"=="3" set cmd=run-test1
#IF /I "%cmd%"=="run-test1" call :RUN-test1
#goto :END
:COMPILE
xcopy /Y .\src\META-INF\*.* .\classes\META-INF\
set cp=./lib/somelib1.jar;./lib/somelib2.jar
"%JAVA_HOME%\bin\javac" -classpath "%cp%" -sourcepath ./src -d ./classes ./src/test/*.java
#goto :eof
:JAR
xcopy /Y .\src\META-INF\*.* .\classes\META-INF\
SET MF=./classes/META-INF/MANIFEST.MF
"%JAVA_HOME%\bin\jar" cvfm ./lib/test.jar %MF% -C ./classes .
#goto :eof
:RUN-test1
"%JAVA_HOME%\bin\java" -cp "./lib/*" test.GameLoop2 "fullscreen=false" fps=60 vsync=true
#goto :eof
:END
#pause
MANIFEST.MF
Implementation-Title: testapp
Implementation-Version: 1.0.0 (2017-07-21)
Implementation-Vendor: myname
Implementation-URL: http://my.homepage.com/
Run this script in a command-line such as javaenv.bat compile, javaenv.bat jar, javaenv.bat run-test1 or run without arguments to prompt for selection list.
See a customized manifest where you may write anything you want and is included in a ./lib/test.jar file. Compile target has few 3rd party dependency libraries in a classpath.

Input filename into jar from windows batch file

I want to input a file into my jar after it is executed from batch file.
I wrote the following batch code.
#echo off
set path=%PATH%;C:\Program Files\Java\jre7\bin
java -jar E:\ER\er_v.3.3.17.jar
The above code is working fine. However, after the jar file is executed I need to feed another file for it to run successfully.
I want something like this
#echo off
set path=%PATH%;C:\Program Files\Java\jre7\bin
java -jar E:\ER\er_v.3.3.17.jar
echo E:\Run.xml
Can somebody help me with this?
Here you go. I tested this and it works.
#echo off
setlocal
:: if java.exe is not in %path%
for %%I in (java.exe) do if "%%~$PATH:I" equ "" (
set "PATH=%PATH%;C:\Program Files\Java\jre7\bin;C:\Program Files (x86)\Java\jre7\bin"
)
echo E:\Run.xml| java -jar E:\ER\er_v.3.3.17.jar
This passes "E:\Run.xml" to the stdin of java -jar etc.

Specifying Play 2.0 port with "dist"

I'm creating a packaged project usingdist and am trying to modify the generated start script to run the app on port 9001.
Here is what is generated:
exec java $* -cp "`dirname $0`/lib/*" play.core.server.NettyServer `dirname $0`
Here is what I tried, which doesn't seem to work.
exec java $* -Dhttp.port=9001 -cp "`dirname $0`/lib/*" play.core.server.NettyServer `dirname $0`
Any ideas?
I've also tried specifying http.port=9001 in application.conf with no avail. It was very easy to do this in Play 1.2.X, seems a step backward.
After running play dist and then extracting the generated bundle, you can start Play 2 on a different port by running:
./start -Dhttp.port=5432
Or if you would rather edit the start script you can update it to be:
#!/usr/bin/env sh
exec java $* -Dhttp.port=5432 -cp "`dirname $0`/lib/*" play.core.server.NettyServer `dirname $0`
And then run:
./start

ArrayIndexOutOfBounds Exception on executing linux sh file

I have a program in java which takes 0'th aargument as file location like
File f = new File(args[0]);
so when i execute it using a windows batch(.bat) file it works correctly .
but when i execute the same using a linux shell file(.sh) in linux i get ArrayIndexOutOfBoundsException.
WINDOWS BATCH FILE :
#echo off
for /f %%i in ("%0") do set scriptpath=%%~dpi
set cp=%scriptpath%/../lib/*.jar;
java -classpath %cp% com.synchronizer.main.MYSynchronizer %scriptpath% "%1" "%2"
LINUX SH FILE:
export JAVA_HOME=/usr/local/java
PATH=/usr/local/java/bin:${PATH}
THE_CLASSPATH=
for i in `ls ../lib/*.jar`
do
THE_CLASSPATH=${THE_CLASSPATH}:${i}
done
java -cp ".:${THE_CLASSPATH}" \
com.synchronizer.main.MYSynchronizer
please help!
It looks like a problem in script (no arguments are passed to the Java program).
You can consider to debug the script like this: debugging scripts
Hope this helps
Your shell script is not passing any parameters:
java -cp ".:${THE_CLASSPATH}" com.synchronizer.main.MYSynchronizer
Try:
java -cp ".:${THE_CLASSPATH}" com.synchronizer.main.MYSynchronizer "$1" "$2"
As stated above, your Linux shell script is not sending any arguments to the Java program that you are trying to start.
And, adding to that, you are not showing us how you run the Linux shell script. If no argument is given on the command line when you start the shell script, no arguments can be passed to your Java application from the shell script.
If you want to see the actual command that is going to be run by your shell script, you can always put "echo" in front of a line and see what all variables are expanded to. This is a simple way to debug shell scripts.

Categories