Linux: How to get path to file in nested folder - java

I want to execute:
java -jar rootfolder/nested folders/*.jar
I just don't know how to specify the nested folder structure, which I will not know as it is dynamically generated.
I tried:
java -jar rootfolder/**/*.jar
but get the following error:
Error: Unable to access jarfile

Can you find the jar-file, using a find command?
find ./ -name "*.jar"
In case yes, you can use the result of that command as input for your command:
java -jar `find ./ -name "*.jar"`
Or, (this is more readable but it does not always work):
java -jar $(find ./ -name "*.jar")

This should run the first .jar file found:
java -jar `ls rootfolder/**/*.jar | head -1`

Related

Create .jar file idea project command line

I want to create a jar file from this project https://github.com/5up3rc/weblogic_cmd
I have seen that there is a weblogic_cmd/.idea/artifacts/weblogic_cmd_jar.xml file which is probably what I need but I haven't seen any tutorial on how to do it via command line.
I have also tried to compile it manually
find src -name \*.java -print0 | xargs -0 javac -cp -classpath ./lib/*.jar -o ./classes/
but I failed.

How to run shell scripts along with java applications using docker?

Following is my Dockerfile , i am copying a folder and two java jar files onto the image and the intention was to execute the script file which is inside the copied directory followed by executing the two java applications .
FROM openjdk:latest
COPY ./mycluster /dir/latest/
COPY ./app1.jar /dir/latest/
COPY ./app2.jar /dir/latest/
CMD ["sh", "-c", "cd /dir/latest/ ;./local_cluster_startup.sh ./;sleep 5 ;java -jar app2.jar;sleep 5;java -jar app1.jar;"]
After building the docker image and running the following command docker container run tryout:nsdap the output is
sh: 1: cd: can't cd to /dir/latest/
sh: 1: ./local_cluster_startup.sh: not found
Error: Unable to access jarfile app2.jar
Error: Unable to access jarfile app1.jar
Can anyone please tell me what am doing wrong here ?
I am looking for a minimal docker image that would be able to execute java jars and the shell scripts . Can you please help me out ? Thanks
Use WORKDIR (https://docs.docker.com/engine/reference/builder/#workdir) to switch to the directory "/dir/latest".
Then you can run your commands from that directory
WORKDIR /dir/latest
CMD ["./local_cluster_startup.sh ;sleep 5 ;java -jar app2.jar;sleep 5;java -jar app1.jar;"]

Beginner: Need to Run a Makefile in Windows

I am currently trying to install a program from Sourceforge. The installation process requires that I change directory paths in the makefile and execute it. I have been researching how to run the makefile but I am still lost and was hoping to get some help or be pointed in the right direction. I am running Windows 8.1. I believe the program is going to execute a java class file. However, I am unfamiliar with the language and not sure how I should alter the makefile to run in windows 8.1. I tried to run "make" in the command prompt but that didn't work. I posted the makefile below. I understand I should change the directory for ImageJ (which I have installed). But I'm not sure how I should alter path for windows and how I can then execute it. The manual instructs me to change IMAGEJ_DIR to the installation place of the program ImageJ. Then execute "make" and "make install" will generate the jar file. "My imageJ folder is located at C:\Program Files. Do I need to change the directory to execute this makefile, and if so how can I do that in windows? The makefile itself is located in my downloads folder. Any help would be greatly appreciated. Thanks!
JC=javac IMAGEJ_DIR=/home/wenja/ImageJ PLUGIN_DIR=$(IMAGEJ_DIR)/plugins/OpenBeamProfiler IJ_JAR=$(IMAGEJ_DIR)/ij.jar APACHEMATH_JAR=$(IMAGEJ_DIR)/plugins/commons-math3-3.2.jar LIBJAR=$(IJ_JAR):$(APACHEMATH_JAR) CLASSPATH=$(IMAGEJ_DIR):./:$(LIBJAR) CLASSDIR=./classes COMPILEFLAGS=
COMPILEFLAGS=-Xlint:deprecation
COMPILEFLAGS=-Xlint:unchecked
all: $(CLASSDIR)/BeamProfiler_Plugin.class $(CLASSDIR)/BeamProfilerFrame.class $(CLASSDIR)/BeamProfilerResultFrame.class $(CLASSDIR)/BeamViewWindow.class $(CLASSDIR)/BeamFunctionGauss.class $(CLASSDIR)/BeamFunctionSuperGauss.class
clean: rm -f $(CLASSDIR)/*.class rm -f *.jar
$(CLASSDIR)/BeamProfiler_Plugin.class: BeamProfiler_Plugin.java $(JC) $(COMPILEFLAGS) -cp $(CLASSPATH) -d $(CLASSDIR) BeamProfiler_Plugin.java
$(CLASSDIR)/BeamProfilerFrame.class: BeamProfilerFrame.java $(JC) $(COMPILEFLAGS) -cp $(CLASSPATH) -d $(CLASSDIR) BeamProfilerFrame.java
$(CLASSDIR)/BeamProfilerResultFrame.class: BeamProfilerResultFrame.java $(JC) $(COMPILEFLAGS) -cp $(CLASSPATH) -d $(CLASSDIR) BeamProfilerResultFrame.java
$(CLASSDIR)/BeamViewWindow.class: BeamViewWindow.java $(JC) $(COMPILEFLAGS) -cp $(CLASSPATH) -d $(CLASSDIR) BeamViewWindow.java
$(CLASSDIR)/BeamFunctionGauss.class: BeamFunctionGauss.java $(JC) $(COMPILEFLAGS) -cp $(CLASSPATH) -d $(CLASSDIR) BeamFunctionGauss.java
$(CLASSDIR)/BeamFunctionSuperGauss.class: BeamFunctionSuperGauss.java $(JC) $(COMPILEFLAGS) -cp $(CLASSPATH) -d $(CLASSDIR) BeamFunctionSuperGauss.java
Note: the "_" in the jar file name in important to be recognized by ImageJ
for including manifest use
jar cfm Beam_Profiler.jar Manifest.txt BeamProfiler_Plugin.class BeamProfilerFrame.class BeamProfilerResultFrame.class
it is important to jar *.class to also get ...$1.class etc.
jar: all cd $(CLASSDIR) &&\ jar cf Beam_Profiler.jar * &&\ mv Beam_Profiler.jar ../
install: jar #if test ! -d $(PLUGIN_DIR); then mkdir $(PLUGIN_DIR); fi
cp Beam_Profiler.jar $(PLUGIN_DIR)
uninstall: rm -f $(PLUGIN_DIR)/Beam_Profiler.jar
Try this,
Open command prompt => Go to windows start menu (run programs) -> type the command "cmd.exe"; this will list the command prompt program in the list. Open the command prompt. Probably it'll be defaulted to your home directory. So issue the command "cd Downloads\directory_of_the_program_to_install" to navigate to the program directory. Now go to the real program folder, then find that make file, open it in edit mode, and then change the entry
IMAGEJ_DIR=c:\program files\imagej_directory. Then go to the command prompt that we opened before, and issue the command make and then makeinstall. This would do the trick.

How to translate an entire folder or package from Java to Objective-C?

I've used an older version of Google's Java to Objective-C (J2ObjC) converter previously (i.e. version 0.5.2) and it was straightforward to translate an entire folder of Java files to their equivalent Objective-C files (and to preserve the directory structure in doing so). I just had to run the following shell executable:
$ ./run.sh —-preservedirs <path to input folder>
I've just downloaded the latest version of J2ObjC (i.e. version 0.9.1) and it's not clear from the Getting Started page or elsewhere how I can translate an entire folder of Java files rather than just a single Java file using the j2obc executable. The only example provided in the Getting Started page is to translate a single Java file which has no dependencies or imports elsewhere as follows:
$ ./j2objc Hello.java
Can anyone provide me with an example of how to translate an entire package assuming I have a folder named input which contains my com package which contains all of the sub-packages and Java files that I want to translate?
To build a whole project, I add the source root(s) to the -sourcepath, then use the find command to locate all Java sources. For example, to build Square.com's Dagger library:
$ export J2OBJC=~/j2objc # change to wherever your distribution is
$ cd ~/src/dagger/core
$ $J2OBJC/j2objc -d build_output -sourcepath src/main/java \
-classpath $J2OBJC/lib/javax-inject.jar \
`find src/main/java -name '*.java'`
All the generated .h and .m files are now in the build_output directory, in subdirectories according to their package (like javac does). To compile all the .m files into a static library, I use:
$ cd build_output
$ j2objcc -c -I. `find . -name '*.m'`
$ libtool -static -o libdagger.a *.o
If there is no better way built into run.sh, you could use find's -exec flag:
find <path to input folder> -type f -exec --preservedirs ./run.sh {} \;
Or, you could use xargs to do multiple files at the same type:
find <path to input folder> -type f | xargs ./run.sh --preservedirs
(You might also need to add -name "*.java" to the find arguments if there are non-Java files in your directories).

Creating a shell script to run Java program

I used a shell script to run a Java class.
My script contains
#!/bin/sh
java -jar jobs/job.jar
These are my failed attempts to run it.
[root#]#sh testapp.sh
Unable to access jarfile jobs/job.jar
if I just do this at the command line it works fine
[root#]#java -jar jobs/job.jar
thanks.
The best way is to get the current dirname and get in there with this:
#!/bin/sh
cd `dirname "$0"`
java -jar ./job/job.jar
Use the absolute path to your JAR file, e. g. /root/jobs/job.jar.

Categories