I have two visual studio projects (for different purpose... they act on two different hardware) and also, I have a Java project that have control on something else. I am working in windows. My question is that how can I write a script (like shell script) to control different projects from a single program. More specifically, suppose I want to do something like this: execute project 1 with parameters x1,x2,...,xn, then execute project 2 with parameters y1,y2,...,yn, then execute project 1, then project 3, & so on...
Is there any tutorial or short description that I can follow to implement my concept?
There's a myriad of options/scripting languages/... to achieve this, but if you just want to run a bunch of exes then a simple windows batch file will do just fine:
#echo off
set my_exe=c:\path\to\my.exe
set my_other_exe=c:\path\to\my_other.exe
%my_exe% a
%my_exe% a b c
%my_other_exe% x
%my_other_exe% x y z
pause
Save this with your favourite editor with a .bat extension and run by double-clicking. The lines with set create variables so you don't have to paste the full path to your exes the whole time. The lines referring to those variables will invoke the executables aith the argumenst that come after it. Search the internet for 'batch file examples' or something like that and you will quickly find all the info needed.
Related
I tried googling a lot but couldnt get a proper working solution ..
directory consists of all java files and external jarfile(google.guava.jar).. i want to execute it in a batch file.. i have tried a lot of things...but still says deffclasserror.. can anyone help me out on how to make it work...(Windows)..
Structure looks like this:
Folder
--------jar file
--------java file
--------bat file
set path="C:\Program Files (x86)\Java\jdk1.8.0_73\bin"
javac -cp google.guava.jar convertohash
javac FinalOutput.java
java convertohash
java FinalOutput
pause
Try this:
"C:\Program Files (x86)\Java\jdk1.8.0_73\bin\java" -cp %YOUR_CLASSPATH%;%YOUR_CLASSPATH_REPORTS%;%EXTRA_LIB% -Djava.library.path=./dll your.main.class
Before this line you need to set up your YOUR_CLASSPATH your YOUR_CLASSPATH_REPORTS and EXTRA_LIB with = and separating the concurrences with ";" (without the ""). For example:
SET EXTRA_LIB=.\lib\mysql-connector-java.jar;.\lib\anotherlibrary.jar; etc
Being the "lib" folder the one were you store your libraries, the route doesn't stricly needs to be the one shown on the example just put the one were you store your libraries (if you are using some ofc).
Also keep in mind that if you are going to use this bat in several machines they must have the same jdk installed and on the same route specified or you'll need to change it manually because the application wont launch.
So I have a java project with multiple java files.
I know that is almost straight forward to start a java application using batch file. But that is for a pretty simple java program with a single class.
However I am wondering if it is possible to do that with in a scale of a project that you usually create using eclipse. A large project with multiple packages, classes and multiple java files.
My try was to write a script and apply on the main class as following
set path = C:\Program Files\Java\jdk1.7.0_25\bin
javac -classpath twitter/twitter4j-stream-3.0.5.jar;twitter4j-core-3.0.5.jar" sourcepath="lib/twitter4j-core-4.0.1.jar;lib/twitter4j-core-4.0.1.jar;lib/twitter4j-stream-4.0.1.jar;svm_light_lib Program.java
java Program
However when I start the .bat file it automatically closes.
Any Ideas ?
Thanks in advance
First, never overwrite the environment variable path, not even
temporarily. Append your folder instead: set "path=%path%;%mypath%" or set "path=%mypath%;%path%".
(There exists a particular path command but I'm not sure about right syntax: path=%path%;%mypath% with = assignment or path %path%;%mypath% without it).
Use full path to a program if you know it, e.g. "%mypath%\javac".
For better readability, values for -classpath and -sourcepath options are stored to the environment variables mycpth and mysrcp, respectively. Note and use proper " quotation and no spacing around = to avoid any leading and trailing spaces in all set commands.
pause to see all the javac output. Displays the message Press any key to continue . . .
Next code should be (syntax) error-free. However, success depends (among others) on classpath and sourcepath entries visibility as well...
set "mypath=C:\Program Files\Java\jdk1.7.0_25\bin"
set "path=%path%;%mypath%"
set "mycpth=twitter/twitter4j-stream-3.0.5.jar;twitter4j-core-3.0.5.jar"
set "mysrcp=lib/twitter4j-core-4.0.1.jar;lib/twitter4j-core-4.0.1.jar;lib/twitter4j-stream-4.0.1.jar;svm_light_lib"
"%mypath%\javac" -classpath "%mycpth%" -sourcepath "%mysrcp%" Program.java
pause
java Program
However I am wondering if it is possible to do that with in a scale of a project that you usually create using eclipse. A large project with multiple packages, classes and multiple java files.
Of course it is possible!
In this case, I suspect the problem is that you java command doesn't have a "-cp" argument. The java command is probably failing because it can't find twitter classes ... at runtime.
Remember to include "." on the classpath ... or else java won't find the file that you just compiled.
#JB Nizet's suggestion is also very important advice for finding out what is actually happening.
I am working on a system where I am using part of the JOGL OpenGL bindings to Java. I find the basic idea behing the "gluegen" C to Java binding generator good but the docs are thin and I havn't been able to locate a simple sample of gluegen usage consisting of:
A C module the does something like modify a string or print a string to stdout (ie: easily tested from java code) an expanded version one with multiple methods that handle each data type handled by gluegen.
the appropriate "cfg", ".h" files needed to power gluegen for the sample source.
A build script - ideally simple not factored out too much into an endless chain to follow generic makefile or shell script :)
the result of running the build script gives you the generated and sample code for a complete native side DLL with DLL main, export tables, and whatever else is needed to load into java on a windows box (.lib for unix)
A C compile of the code with MSVC and/or GCC to compile and link the code and generated code to produce the DLL.
The generated java class or classes that mate with the DLL including initialization.
In a sense sort of a "hello world" in C to be called from Java as a place to start.
PK
I have my java code running.
I added a groovy shell to evaluate the main groovy file.
What it does is simple.
GroovyShell.run (main.groovy)
Now, in my main.groovy, if I have other .groovy files I'd like to "require", how can I do that?
Is there something like "require, source, load, require_one, import" filename?
http://groovy.codehaus.org/Embedding+Groovy
if you scroll down to the section entitled "Dynamically loading and running Groovy code inside Java" you will see a full example with two different approaches to solving your problem
Actually, here is the answer:
I couldn't find a function like that in Groovy.
So, when evaluating your file, you have to parse all groovy files.
If you add new files on the fly and would like to evaluate them, you can't reuse the shell, not even through a singleton via the evaluated script
What you can do is register your parsed files and force the shell to "re-parse" them all again when re-evaluating your file.
Is there a way to use m4 macros when developing in Java for Eclipse, ie. making sure the preprocessor is automatically invoked before Eclipse compiles?
Or has anyone used another preprocessor successfully with Eclipse?
You can specify an arbitrary builder on an Eclipse project, and order the builder so that it is executed before the Java builder is run.
To define the new builder, open the project properties (right click->Properties or alt-enter), select Builders then New.... Select Program, then in the dialog configure the builder (hopefully you know what needs to be done here) and select OK. Back in the Builders page you can then select your new builder and select Up until it is before the Java Builder
I think I have a way.
I just now got it working with the c preprocessor in eclipse on windows. I'm sure it could be adapted to M4, but I DO use gnu CPP's ability to create make files expressing the dependencies of a file. Doing that for m4 would be up to you. It has a few problems. If there's an error during preprocessing eclipse ignores it and keeps going. Also if you built with "run" the preprocessor's console output disappears as soon as the program starts.
Since I don't understand ant, and I don't have time to learn, my version is based on using Ruby for glue. I wrote a little automake in Ruby that takes a list of files that have been touched before the last make, filters out the ones that are preprocessed files, and those that are preprocessor includes, scans untouched preprocessor files to see if they depend on anything that has been changed, then processes them all.
These all depend on using Eclipse's "builders" which only seem to work in Juno.
In my case the setting for the project are:
create a builder for the project settings that runs before the java builder
set the location to: C:\Ruby192\bin\ruby.exe
set the working directory to C:\Ruby192\bin\
set the arguments to: C:\preprocessors\mymake.rb ${build_project} ${build_files:acf}
this passes the directory of the project followed by the file that have been touched
set "refresh" to "project containing the selected resource" and "recursively include subfolder"
set build options to: Allocate console
Run the builder: after clean,during manual builds, and during autobuilds
Note that according to my simple make ".jpp" files will be processed into ".java" files
and ".jpp" files can #include ".jph" files (and only .jph files)
".jph" files can also #include ".jph" files and only ".jph" files
All of these files have to be under the /src/ directory (recursively in directories under /src/ which is how eclipse organizes java code and packages).
Here's the Ruby code:
require 'set'
$path = (ARGV[0].gsub('\\','/')+'/src')
$process=(ARGV[1..-1]||[]).map{ |a| a.gsub('\\','/') }
def pending(ending)
($process.select do |a|
a[0..$path.length-1]==$path && a[-4..-1].downcase == ending
end).to_set
end
def read_make_dependencies(filename)
((File.open(filename).read.
split("\n")[1..-1].
map do |a|
if a[-2..-1]==' \\'
a=a[0..-3]
end
a.lstrip.gsub('\\/','/').gsub('\\','/').rstrip
end)||[]).to_set
end
$pendingJph=pending('.jph')
$pendingJpp=pending('.jpp')
Dir.chdir($path)
$untouchedJph=Dir['**/*.jph'].map{|a| $path+'/'+a}.to_set - $pendingJph
$untouchedJpp=Dir['**/*.jpp'].map{|a| $path+'/'+a}.to_set - $pendingJpp
Dir.chdir('C:/MinGW/bin')
$pendingJph.each do|a|
o = a[0..-4]+'depend'
system "cpp -MM \"#{a}\" -o \"#{o}\""
$pendingJph = $pendingJph + read_make_dependencies(o)
end
$untouchedJpp.each do|a|
o = a[0..-4]+'depend'
system "cpp -MM \"#{a}\" -o \"#{o}\""
if not (read_make_dependencies(o) & $pendingJph).empty?
puts "touching #{a}"
$pendingJpp << a
end
end
$pendingJpp.each do|a|
o = a[0..-4]+'java'
puts "processing #{a}"
system "cpp -w -P -C -x c \"#{a}\" -o \"#{o}\""
end