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.
Related
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`
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.
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).
I have the following files:
A.jar (containing *.class files)
B.jar (containing *.class files)
Program.java (containing Program class with main function, which depends on A.jar and B.jar)
How can I build an executable file Program using GCJ?
It's been a while since I played around with Java so the following are mostly off the top of my head.
In linux usually a java program is launched by a wrapper script. For your case this wrapper script can be the Program, the content:
#!/bin/sh
java -cp A.jar:B.jar:/path/to/dir/where/Program.class/is/in Program
If you prefer to have only a single jar file then you can "unjar" A.jar and B.jar and create a new jar, say Program.jar that contain all the classes from A.jar, B.jar and your Program.class, and you create a little manifest file that tells which class is to be run when you execute the jar file (in this case it's your Program.class).
The content of the manifest file (let's call it manifest.txt):
-----8<------
Main-Class: Program
----->8------
Note the blank line after the "Main-Class: Program" line - it's needed.
So the create the single Program.jar:
gcj --classpath A.jar:B.jar Program.java
mkdir tmp
cd tmp
jar xf ../A.jar
jar xf ../B.jar
cp ../Program.class .
jar cmf ../manifest.txt ../Program.jar .
cd ..
Now create the shell script wrapper Program:
#!/bin/sh
java -jar /path/to/Program.jar
Make it executable:
chmod +x Program
and run it:
./Program
Applause if it works, throw rotten tomatoes otherwise!
This works for me:
gcj -c A.jar -o A.o
gcj -c B.jar -o B.o
gcj --main=Program --classpath=A.jar:B.jar -o Program A.o B.o Program.java
Hi i have been using an IDE but now I need to run and compile from the command line.
The problem is that I have multiple packages and I have tried to find the answer but nothing has worked.
So I have
src/
Support/ (.java files)
Me/ (.java files)
Wrapers/ (.java files)
Do you know how to compile everything with javac?
This should do it (may require additional classpath elements via the -cp command line switch):
javac Support/*.java Me/*.java Wrapers/*.java
But if your build process gets more complex (and it will!), you should look into using Apache Ant for build automation.
You should use build tools like Maven or Ant for such tasks.
In the initial stages, when the project is not very complex you can use the following line to compile, with appropriate classpath in place(as suggested by #Michael):
javac Support/*.java Me/*.java Wrapers/*.java
javac -d compiled $(find src -name *.java)
If you really need to just use javac and standard UNIX commands you could to this:
find src -name \*.java -print0 | xargs -0 javac -d classes
The real answer is javac -d (places where classes to be built and placed) -sourcepath (source of the package at the root) -cp (classpath of the dependencies which can again be classes folder where the classes are build and kept) full qualified name of the java file.
Ex javac -d classes -sourcepath src -cp classes src\com\test\FirstSample.java
The FirstSample.java contains the main method. Pacjage structure mentioned below.
Before compiling
HomeApp
--src
------com\test\FirstSample.java (First Sample using the FirstPojo.java)
------com\test\FirstPojo.java
--classes
After compiling
HomeApp
--src
------com\test\FirstSample.java (FirstSample.java using the FirstPojo.java)
------com\test\FirstPojo.java
--classes
------com\test\FirstSample.class (FirstSample.class using the FirstPojo.class)
------com\test\FirstPojo.class
In many cases Ant is overkill. Just use a BAT file if you are in windows or a shell script (sh file) if you are in linux. You can create a text file which includes all your javac commands and just run that file when you want to build.
For example, I use the following bat file to build one of my apps:
#echo off
echo Building Shazaam...
del classes\com\aepryus\shazaam\*.* /q
del classes\com\aepryus\shazaam\engine\*.* /q
del classes\com\aepryus\shazaam\domain\*.* /q
del classes\com\aepryus\shazaam\persist\*.* /q
del classes\com\aepryus\shazaam\view\*.* /q
del classes\com\aepryus\shazaam\task\*.* /q
del classes\com\aepryus\shazaam\action\*.* /q
del classes\com\aepryus\shazaam\controller\*.* /q
javac src\com\aepryus\shazaam\*.java -classpath \lib\AepUtil.jar;\lib\AepXML.jar;\lib\AepLoom.jar; -d classes
javac src\com\aepryus\shazaam\engine\*.java -classpath \lib\AepUtil.jar;\lib\AepXML.jar;\lib\AepLoom.jar;\lib\Sprout.jar;classes; -d classes
javac src\com\aepryus\shazaam\domain\*.java -classpath \lib\AepUtil.jar;\lib\AepLoom.jar;\lib\Sprout.jar;classes; -d classes
javac src\com\aepryus\shazaam\persist\*.java -classpath \lib\AepUtil.jar;\lib\AepLoom.jar;\lib\Sprout.jar;classes; -d classes
javac src\com\aepryus\shazaam\view\*.java -classpath \lib\Servlet.jar;\lib\AepUtil.jar;\lib\AepXML.jar;\lib\AepLoom.jar;\lib\AepHTML.jar;\lib\Sprout.jar;classes; -d classes
javac src\com\aepryus\shazaam\task\*.java -classpath \lib\AepUtil.jar;\lib\AepLoom.jar;\lib\AepHTML.jar;\lib\Sprout.jar;classes; -d classes
javac src\com\aepryus\shazaam\action\*.java -classpath \lib\Servlet.jar;\lib\AepUtil.jar;\lib\AepLoom.jar;\lib\AepHTML.jar;\lib\Sprout.jar;classes; -d classes
javac src\com\aepryus\shazaam\controller\*.java -classpath \lib\Servlet.jar;\lib\AepUtil.jar;\lib\AepXML.jar;\lib\AepRPC.jar;\lib\AepLoom.jar;\lib\AepHTML.jar;\lib\Sprout.jar;classes; -d classes
cd classes
jar cf ..\war\WEB-INF\lib\Shazaam.jar .
cd..
echo Complete
To compile Run below command [it will store all class files in classes folder]
javac -d classes Support/*.java Me/*.java Wrapers/*.java
**Note : classes folder should be created first
To Run java application, run below command
java -cp classes {mainfile_name}
Replace mainfile_name with your main file.