Searching Directories for Dependencies with a Makefile - java

I currently have a makefile as such:
SOURCES = \
src/package1/*.java \
src/package2/*.java\
src/package3/*.java\
src/package4/*.java \
src/package5/*.java \
src/package6r/*.java \
src/package7/*.java \
src/package8/*.java \
src/package9/*.java
Later on in the make file i have:
new:
make clean
make caller
caller: $(SOURCES) src/package1/file1.java src/package2/file3.java
javac src/package1/main.java
At first I kept getting an error regarding rules for each of the files that needed to be built. It was of the form:
"‘No rule to make target `xxx', needed by `yyy'.’"
I found it's description here: http://www.gnu.org/software/make/manual/html_node/Error-Messages.html and how to solve it here: http://www.chemie.fu-berlin.de/chemnet/use/info/make/make_4.html#SEC26
Now, all the .class files are appropriately being created in the bin/package{1,2,3,4,5,6,7,8,9}/file{1,2,3,4,5,6}.class location; however, when the below command runs:
javac src/package1/main.java
It gives a plethora of errors stating:
error: cannot find symbol
I've tried changing the javac command to the following with the -cp flag:
javac -cp src/package1/*;src/package2/*...
But it doesn't seem to be grabbing all the dependencies, and the command is just too long. I've been trying a lot of work arounds, but I'm not sure how to best do this with a makefile and the javac command?
I already have a ant build which works, but I specifically need this make file to work as well,
Thank you for your time!
Best Regards,

Related

Eclipse JNI fails with 'javac: invalid flag: ../bin' [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 7 months ago.
Improve this question
I'm trying to create a JNI project in Eclipse using CDT. I'm following this tutorial.
So first I created my project as a Java project and created a HelloJNI class in the default package, which contains some really basic code.
I then added a C nature to my project, selecting 'Makefile Project' in 'Project type' and 'Linux GCC' in 'Toolchains'.
Then I created a new directory called 'jni' to store all the C code. I then created a new file in eclipse called 'makefile' (note the lowercase name) and added this to it.
# Define a variable for classpath
CLASS_PATH = ../bin
# Define a virtual path for .class in the bin directory
vpath %.class $(CLASS_PATH)
# $* matches the target filename without the extension
HelloJNI.h : HelloJNI.class
javac -h -classpath $(CLASS_PATH) $*
I then created a build target called 'HelloJNI.h' in the jni folder, which automatically used the makefile. I then attempted to build the target, but I got this error:
javac -h -classpath ../bin HelloJNI
javac: invalid flag: ../bin
Usage: javac <options> <source files>
use -help for a list of possible options
make: *** [makefile:9: HelloJNI.h] Error 2
I am puzzled by the error message. Does javac recognize ../bin as a flag? Is there some weird bug happening in Eclipse? If I try to do this in the terminal, I get the same error. I tried searching for answers, but found none.
This is my directory strcture:
-bin
HelloJNI.class
-jni
makefile
-src
HelloJNI.java
Edit: Changing the javac call to
javac -h -classpath $CLASS_PATH $*
gave me the following error:
error: Class names, 'LASS_PATH,HelloJNI', are only accepted if annotation processing is explicitly requested
Starting point
Looking at the tutorial you're following,
your question lines up with "2. Getting Started", specifically "Step 2" – compiling Java and generating a C/C++ header file.
To revisit, here's what you tried:
javac -h -classpath ../bin HelloJNI
A few points..
The -h option to javac specifies a directory. This directory is where the generated header file should go. It requires a directory name immediately after, like this: -h directory. In the attempt above, it's using the -h option, but doesn't specify a directory. That's an issue.
This includes -classpath ../bin which isn't necessary for this example. It's not a problem, but it isn't necessary to include and can be removed.
"HelloJNI" is not an appropriate input for the compiler - you need to specify a ".java" filename
The fix
In the tutorial, they show this example:
javac -h . HelloJNI.java
This works because:
They're using -h with "." as the directory (where "." means "current directory").
They're compiling the .java file – "HelloJNI.java"
Also, they're not using -classpath.
That option is used to designate where to find class files for compilation (as input to compilation itself), but that isn't relevant for this tutorial example
– there aren't any necessary input classes for javac to work.
So, just remove -classpath ../bin altogether.
In the end, things should work for you if you run the command as they posted in the tutorial:
javac -h . HelloJNI.java
Also: JDK version differences
You didn't specify which JDK version you're using, but if you're using an older (pre-8) version of the JDK, there are
different steps to follow (namely, using javah in addition to javac).

Java pngquant on java not compiling into dll and jnilib

I was trying to make libimagequant library work in java but I can't make the "dll" and can't make the "jnilib", I don't know why but it just doesn't work, if somebody could help it would be awesome.
I have already tried to make the "Makefile" but it gives me errors on errors, maybe someone already compiled a dll, I still don't understand why they don't pre build all the source.
EDIT NUM 1:
I would like to make the libimagequant library work in my java program,
I downloaded the library https://github.com/ImageOptim/libimagequant
when i tried to run make Makefile java it gave me a message that touch is not recognized, as touch is not important i removed the command from Makefile, then i run it again and now it is giving me this error:
process_begin: CreateProcess(NULL, env bash C:\Users\Me\Desktop\libimag
equant\configure, ...) failed.
make (e=2): The system cannot find the file specified.
make: Nothing to be done for `Makefile'.
javah -o org/pngquant/LiqObject.h org.pngquant.LiqObject
javac org/pngquant/PngQuant.java
javah -o org/pngquant/PngQuant.h org.pngquant.PngQuant
javah -o org/pngquant/Image.h org.pngquant.Image
javah -o org/pngquant/Result.h org.pngquant.Result
make: *** No rule to make target `config.mk', needed by `pam.o'. Stop.

Java CL compiling: Adding multiple JAR files

I'm trying to find the simplest way to compile some Java code via Command Line while including multiple JAR files. This is what I've most recently tried and it does not seem to work.
javac -d bin -sourcepath src -cp lib/* ConfigToExcel.java
The error I'm getting is
javac: invalid flag: lib/FIRST_JAR_FILE.jar
I'm sure there is a simple fix to this issue but I cannot seem to find it.
Try with straight quotes (") with the classpath:
-cp "lib/*"

Classpath to use for MapR/Hadoop/Hive

I'm trying to compile some java code for hadoop and need to know what classpath I need to specify. For cloudera I use this below but what do I use for a MapR installation? Surprisingly I could only find how to set the classpath in google, not what to set it to.
javac -classpath "/opt/cloudera/parcels/CDH-4.6.0-1.cdh4.6.0.p0.26/lib/hadoop/client/*" mr.java -d mr
Found the answer by trial and error. Oddly google is very silent on this and all the books and examples I've read appear to assume this is too obvious to bother printing.
mkdir MyClass
javac -classpath "/opt/mapr/hadoop/hadoop-0.20.2/lib/*" MyClass.java -d MyClass
jar -cvf MyClass.jar -C MyClass .
Additionally, if you want the hive libraries, eg for compiling a hive UDF:
javac -classpath "/opt/mapr/hadoop/hadoop-0.20.2/lib/*:/opt/mapr/hive/hive-0.12/lib/*" MyClass.java -d MyClass
EDIT: one thing I would add is make sure you put quotes around the path, otherwise linux expands it on the command line which is not what you want. The * in the path needs to be passed to java as is.

Javac multiple classpaths (colon separator not working)

I'm trying to compile a java program that uses multiple .jar files but am experiencing compile problems. I also can't copy the full output from the virtual machine, but i'll try to post the relevant information.
javac -g Model.java
This ends up getting 33 errors (GL11 cannot find symbol)
javac -g -classpath /media/sf_vm_source/java/java_pkg/lwjgl-*/jar/lwjgl.jar Model.java
This ends up with 5 errors (GL11 is found) [5 errors are from other jars but i'm trying to get it to work with 2 .jars first]
javac -g -classpath /media/sf_vm_source/java/java_pkg/lwjgl-*/jar/lwjgl.jar:/media/sf_vm_source/java/java_pkg/lwjgl-*/jar/lwjgl_util.jar Model.java
This ends up with 33 errors again (GL11 cannot find symbol)
Other info:
sf_vm_source is auto-mounted by virtualbox and has 777 permissions recursively including /media.
Moving all the jar files to a local lib file and using wildcards removes the compile error, but of course has its own issues.
If you are using the relative path in your classpath, then you may have to add the current path(using a dot(.)) to all the jars path. Something like this:
javac -g -classpath ./media/sf_vm_source/java/java_pkg/lwjgl-*/jar/lwjgl.jar Model.java
Also the use of wildcard lwjgl-* may not work here

Categories