Am trying to execute a makefile which will automatically runs a compiled front end of a java code i have written. the contents of the make file is as follows:
build: compile test
compile:
javac lexer/*.java
javac symbols/*.java
javac inter/*.java
javac parser/*.java
javac main/*.java
test:
#for i in `(cd tests; ls *.t | sed -e 's/.t$$//')`;\
do echo $$i.t;\
java main.Main <tests/$$i.t >tmp/$$i.i;\
diff tests/$$i.i tmp/$$i.i;\
done
clean:
(cd lexer; rm *.class)
(cd symbols; rm *.class)
(cd inter; rm *.class)
(cd parser; rm *.class)
(cd main; rm *.class)
yacc:
/usr/ccs/bin/yacc -v doc/front.y
rm y.tab.c
mv y.output doc
When i run make from netbeans, i get this error on the terminal:
javac lexer/*.java
Makefile:4: recipe for target `compile' failed
/bin/sh: javac: command not found
make: *** [compile] Error 127
MAKE FAILED (exit value 2, total time: 660ms)
Please how do i solve this problem.?
The error means the Java compiler (javac) cannot be found.
Your JAVA_HOME variable needs to be set and also appended to PATH.
JAVA_HOME=C:\Program Files\Java\jdk1.7.0_06\bin
export Path:=$(JAVA_HOME);$(Path)
Add these lines to the start of your makefile.
Related
I am working on a docker image which I need to install sbt1.8.2. I downloaded the sbt1.8.2.zip file and unzip it, however while checking the version of sbt using sbtVersion, java is missing even though I declared the JAVA_HOME.
This is my sample dockerfile:
ENV SBT_VERSION=1.8.2
ENV JAVA_VERSION=1.8.0_60
ENV JAVA_HOME /opt/jdk${JAVA_VERSION}/jre/
# Install SBT
RUN curl -L -o sbt-$SBT_VERSION.zip download/internal/url/sbt-1.8.2.zip
RUN unzip -o sbt-$SBT_VERSION.zip -d /opt/
CMD /opt/sbt/bin/sbt run \
sbt sbtVersion
This is my sample bats file for testing.
#!/usr/bin/env bats
load $(pwd)/helpers/sdp-helper.bash
#test "SBT Version" {
EXPVER="1.8.2"
run ${dockerRun} bash -c "JAVA_HOME=/opt/jdk1.8.0_60/jre /opt/sbt/bin/sbt sbtVersion"
sdp::outCmd2Tap
[[ ${status} -eq 0 ]]
[[ ${lines[0]} =~ "${EXPVER}" ]]
}
Error:
/opt/sbt/bin/sbt: line 460: java: command not found
copying runtime jar...
mkdir: cannot create directory '': No such file or directory
/opt/sbt/bin/sbt: line 467: java: command not found
/opt/sbt/bin/sbt: line 229: exec: java: not found
Previously I was able to run make all and make java. I did a make clean after which make java fails with com/example/tutorial/AddressBookProtos.java:95: error: package com.google.protobuf does not exist.
I followed this SO post, but it fails.
examples $protoc --version
libprotoc 3.5.1
examples $make java
make: Nothing to be done for `java'.
examples $make clean
rm -f add_person_cpp list_people_cpp add_person_java list_people_java add_person_python list_people_python
rm -f javac_middleman AddPerson*.class ListPeople*.class com/example/tutorial/*.class
rm -f protoc_middleman addressbook.pb.cc addressbook.pb.h addressbook_pb2.py com/example/tutorial/AddressBookProtos.java
rm -f *.pyc
rm -f protoc_middleman_go tutorial/*.pb.go add_person_go list_people_go
rmdir tutorial 2>/dev/null || true
rmdir com/example/tutorial 2>/dev/null || true
rmdir com/example 2>/dev/null || true
rmdir com 2>/dev/null || true
examples $make java
protoc $PROTO_PATH --cpp_out=. --java_out=. --python_out=. addressbook.proto
javac -cp $CLASSPATH AddPerson.java ListPeople.java com/example/tutorial/AddressBookProtos.java
com/example/tutorial/AddressBookProtos.java:95: error: package com.google.protobuf does not exist
com.google.protobuf.GeneratedMessageV3 implements
^
com/example/tutorial/AddressBookProtos.java:19: error: package com.google.protobuf does not exist
com.google.protobuf.MessageOrBuilder {
Is there an older version of Protobuf that I can use? Or how can I fix this error.
I got the same errors untill I fixed a typo in $CLASSPATH. It is too sad Javac does not emit better error messages when jar files in classpath do not exist.
I want to start my java program by script. I also want to include .jar files by executing the script.
My script looks like this:
if [ -d ./bin ]; then
rm -fr ./bin
fi
mkdir ./bin
javac -sourcepath ./src -d ./bin -cp ./../Jars/CFMgr.jar ./src/gui/App.java
if [ "$?" != "0" ]; then
echo "compile errors..."
exit -1
fi
java -classpath ./bin:./../Jars/CFMgr.jar:./../Jars/ojdbc14.jar gui.App
Every time I execute it with this command ./script.sh in the linux terminal, I get the following error:
https://s4.postimg.org/kevatu0nx/Unbenannt.png
test:
java -cp "./bin/*:./lib/*" com.YourClass
You are compiling only App.java , which need Panel.java. so compile all the classes in gui package at the same time.
One solution is to export your java program to an executable jar and then:
java -jar yourProgram.jar
I'm trying to create a .dll while following this tutorial (http://www3.ntu.edu.sg/home/ehchua/programming/java/JavaNativeInterface.html) to use JNI in my eclipse project. There's an issue with my makefile however that may be unrelated to all the JNI stuff.
I'm getting "unknown option: --add-stdcall-alias" when I build (make all). I'm using the Mac GCC Compiler. Here's my console log and make file:
EDIT: So i removed the option that is giving me the error and my build worked. However, I feel unsafe just removing a line of code that I am clueless about. Any one want to tell me the implications of removing this code?
console output:
18:05:33 ** Build of configuration Default for project HPA* Testing *
make all
javah -classpath ../bin HPAProgram
gcc -Wl,--add-stdcall-alias -shared -o hpaprogram.dll HPAProgram.o
ld: unknown option: --add-stdcall-alias
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: ** [hpaprogram.dll] Error 1
18:05:34 Build Finished (took 823ms)
makefile:
# Define a variable for classpath
CLASS_PATH = ../bin
# Define a virtual path for .class in the bin directory
vpath %.class $(CLASS_PATH)
all : hpaprogram.dll
# $# matches the target, $< matches the first dependancy
hpaprogram.dll : HPAProgram.o
gcc -Wl,--add-stdcall-alias -shared -o $# $<
# $# matches the target, $< matches the first dependancy
HPAProgram.o : HPAProgram.c++ HPAProgram.h
gcc -I /System/Library/Frameworks/JavaVM.framework/Versions/A/Headers/ -c $< -o $#
# $* matches the target filename without the extension
HPAProgram.h : HPAProgram.class
javah -classpath $(CLASS_PATH) $*
clean :
rm HPAProgram.h HPAProgram.o hpaprogram.dll
I practiced by following the same tutorial, it turned out that it's OK to get rid of "-Wl,--add-stdcall-alias".
BTW, in Mac, you have to use ".dylib" instead of ".so", otherwise you will get error saying "java.lang.UnsatisfiedLinkError: no hello in java.library.path".
I have a java project, and need to write makefile to let it run on Linux. My project includes external jar files and resource package(.txt resourses).I am really a newbie for Linux, and just learn how to write makefile.
I refer to some materials and write a makefile like this:
# Set the file name of your jar package:
JAR_PKG = ADBproject1.jar
# Set your entry point of your java app:
ENTRY_POINT = adb/Bing_WebResults/Run.java
# Need resource directory
RES_DIR = yes
SOURCE_FILES = \
adb/jsonModels/Metadata.java \
adb/jsonModels/Result.java \
adb/jsonModels/Data.java \
adb/jsonModels/DataContainer.java \
adb/models/Weight_ID.java \
adb/models/Pair.java \
adb/models/Document.java \
adb/models/Collections.java \
adb/Bing_WebResults/Bing_Search.java\
adb/Bing_WebResults/Run.java \
JAVAC = javac
JFLAGS = -encoding UTF-8
vpath %.class bin
vpath %.java src
# show help message by default
Default:
#echo "make new: new project, create src, bin, res dirs."
#echo "make build: build project."
#echo "make clean: clear classes generated."
#echo "make rebuild: rebuild project."
#echo "make run: run your app."
#echo "make jar: package your project into a executable jar."
build: $(SOURCE_FILES:.java=.class)
# pattern rule
%.class: %.java
$(JAVAC) -cp bin -d bin $(JFLAGS) $<
rebuild: clean build
.PHONY: new clean run jar
new:
ifeq ($(RES_DIR),yes)
mkdir -pv src bin res
else
mkdir -pv src bin
endif
clean:
rm -frv bin/*
run:
java -cp bin $(ENTRY_POINT)
jar:
ifeq ($(RES_DIR),yes)
jar cvfe $(JAR_PKG) $(ENTRY_POINT) -C bin . res
else
jar cvfe $(JAR_PKG) $(ENTRY_POINT) -C bin .
endif
But I don't know how to add those two external .jar files (gson.jar, commons.jar) into makefile. And I'm not quite sure, whether the file paths I wrote are correct.
javac has a -cp and -classpath argument:
-classpath <path> Specify where to find user class files and
annotation processors
-cp <path> Specify where to find user class files and
annotation processors
They seem to be equivalent as far as the documentation is concerned.
I solve the problem by adding all *.jar files to a new folder "lib".
Then
javac -sourcepath src/ -classpath lib/*.jar
will solve the external jar file problem.