I have problem with compiling NanoVM project from:
http://www.harbaum.org/till/nanovm/index.shtml
NanoVM is Java implementation for AVR microcontrollers. I know this is not efficient. I have problem with "makefile" file. This makefile contains instructions to compile Java .class from source .java files. But i don't know, how can i run makefile? I was using previously javac.exe compiler to write java standard applications. In install instructions writes that I must have Java SDK (J2SE). Is there any difference between SDK and JDK? I have JDK installed, i have read earlier that there isn't any difference between SDK and JDK, but i'm not sure. I know makefile files are used to manage compilation, i previously used makefile to compile programs wrote in C, but is there some Java compiler like gcc? Sorry for my stupid question, i'm quite newbie in makefiles, i think solution is very simple.
My makefile:
#
# Makefile for NanoVMTool
#
APP = NanoVMTool
VERSION = 1.5
all: ../$(APP).jar
CLASSPATH = ../../java/examples
NATIVEPATH = ../../java/native
JAVAFILES = AccessFlags.java CodeInfo.java ConstPoolEntry.java FieldInfo.java \
MethodInfo.java AttributeInfo.java CodeTranslator.java \
ConstPoolEntryError.java InnerClassInfo.java NanoVMTool.java \
ClassFileReader.java CommonInfo.java ConvertException.java \
LineNumberInfo.java NativeMapper.java ClassInfo.java \
Config.java Debug.java LocalVariableInfo.java UVMWriter.java \
ClassLoader.java ConstPool.java ExceptionInfo.java \
MethodIdTable.java Uploader.java NVMComm2.java
# compile target code
$(CLASSPATH)/%.class: $(CLASSPATH)/%.java
javac -classpath $(CLASSPATH):$(NATIVEPATH) $<
%.class: %.java
echo "public class Version {" > Version.java
echo " public static String version = \"V$(VERSION)\";" >> Version.java
echo "}" >> Version.java
javac $<
../$(APP).jar: $(APP).class
jar cmf $(APP).mf ../$(APP).jar *.class
# convert and upload a class file (should be moved to vm/target Makefile)
asuro-%: $(CLASSPATH)/%.class $(APP).class
java $(APP) ../config/Asuro.config $(CLASSPATH) $*
mega8-%: $(CLASSPATH)/%.class $(APP).class
java $(APP) ../config/Mega8.config $(CLASSPATH) $*
clean:
rm -f *.class *~
In order to run a Makefile (on Linux / UNIX), you first need to install "make" and any of the other tools that it uses. In this case, the tools are just the java, javac and jar commands. For the last two, you need a JDK installation.
But i don't know, how can i run makefile?
Change directory to the directory containing the Makefile, then run 'make' with the appropriate target. In this case make all.
Is there any difference between SDK and JDK?
There is no such thing as the Java SDK.
... but is there some Java compiler like gcc?
The Java compiler is javac. That is what your makefile is using.
Sorry for my stupid question, i'm quite newbie in makefiles, i think solution is very simple.
The REAL solution is to find and read a tutorial on Makefiles and how to read, write and use them. (In general, the solution to asking newbie questions is to educate yourself so that you aren't a newbie!)
Related
Can command java run a compiled scala code? If so, why do we have an exclusive command scala?
You can run byte code generated by Scala if you include all necessary runtime libs for Scala (scala-library.jar, scala-swing.jar ...) in the classpath. The scala command does this automatically, and supports Scala specific command line arguments.
Yes, it can. Scala is compiled down to Java bytecode. But remember that it depends on the Scala runtime classes, so you need to still have Scala's jar files on the classpath.
If so, why do we have an exclusive command scala?
Convenience wrapper.
Scala is designed to integrate easily
with applications that run on modern
virtual machines, primarily the Java
virtual machine (JVM). The main Scala
compiler, scalac, generates Java class
files that can be run on the JVM.
-> http://www.artima.com/scalazine/articles/steps.html
As long as you have installed the scala runtime you should be fine: compile classes with scalac and run them with java.
Just want to add my own answer as additional value for the future readers:
scala, if run without parameter, will run an interactive shell
scala, if run with a text file name as parameter, will regard the file as a scala script
those two can't be done using java
If you look closely, the scala command is simply a bash helper-script which summarize to the below command:
$cat /usr/local/Cellar/scala#2.11/2.11.12_1/libexec/bin/scala
execCommand \
"${JAVACMD:=java}" \
$JAVA_OPTS \
"${java_args[#]}" \
"${classpath_args[#]}" \
-Dscala.home="$SCALA_HOME" \
$OVERRIDE_USEJAVACP \
"$EMACS_OPT" \
$WINDOWS_OPT \
scala.tools.nsc.MainGenericRunner "$#"
There are 2 things required to run a .class file compiled using scalac ( the scala compiler) using the java command.
We need to include the scala-library.jar and the location of the .class file in the classpath. To find the location of scala-library.jar, please execute the
below:
which scala /usr/local/opt/scala#2.11/bin/scala
In my case the scala-*.jar files are in :
/usr/local/Cellar/scala#2.11/2.11.12_1/idea/lib on Mac
The location of the Main2.class file which is in /training/example1/scala.
So, to execute the program we could use the below command:
java -cp /usr/local/Cellar/scala#2.11/2.11.12_1/idea/lib/scala-library.jar:/training/example1/scala/ Main2
EDIT-1: If you are using windows, please use semicolon(;) as the separator in java classpath command.
I downloaded a sample code written in java that has multiple jar files and java files. I am not a Java programmer so I am having a hard time compiling the code. Here's my attempt:
javac -classpath lib/*.jar src/*.java
However this is what I get:
javac: invalid flag: lib/dom4j-1.6.1.jar
Usage: javac <options> <source files>
use -help for a list of possible options
What's wrong with my approach and how can I compile the code? ALl the jar files are located in the lib folder, and the java files in the src folder.
You need to stop the shell from globbing the wild-card in lib/*.jar by escaping it.
Also, you need to remove the .jar suffix ... because that's how classpath wildcards work; see Oracle's "Setting the classpath" document.
So ...
javac -classpath lib/\* src/*.java
Using an IDE is another option. However, if all you want to do is compile and run, then downloading and installing and learning to use an IDE is overkill (IMO). And the flipside is that it is good for an IDE-using Java programmer to also understand how to compile and run from the shell prompt ...
old post, but thought below details help,
you can specify jar files by separating by ; in windows and : in unix
Eg: (windows)
javac -cp first.jar;second.jar;third.jar YourClass.java
(unix)
javac -cp first.jar:second.jar:third.jar YourClass.java
Source: https://gullele.com/pass-all-the-jars-in-classpath-when-compiling-java/
I downloaded a Java library with a file titled Makefile, but I do not know what to run it with. It has no extension, and this is the text that appears when I open it in TextEdit:
all: BigDecimalMath.jar Wigner3jGUI.jar html
html:
javadoc -sourcepath . -private -d html org.nevec.rjm
BigDecimalMath.jar:
javac org/nevec/rjm/*.java
jar cf $# org
Wigner3jGUI.jar:
javac org/nevec/rjm/*.java
jar cmf Wigner3jGUI.mf $# org/nevec/rjm/*.class
distclean:
rm -rf html *.jar org/nevec/rjm/*.class
Could anyone help me figure out how to run this file (By the way, I have a Mac running Mavericks if that matters at all)
try two commands
make
java -jar Wigner3jGUI.jar
Makefiles are similar to ant files and are run by the make program. I have not seen make used to build jars (usually c/c++). However, it looks like it will build the jars. The all target should build the jars, which can then be run by the java command.
Hello I am new in Java development. I tried to write a makefile which should be runnable in Linux:
JFLAGS = -g
JC = javac
.SUFFIXES: .java .class
.java.class:
$(JC) $(JFLAGS) $*.java
Heap.class: FibonacciHeap.java \
FileOperation.java \
MinLeftistTree.java \
RandomPermutation.java \
Heap.java
default: classes
classes: $(CLASSES:.java=.class)
clean:
$(RM) *.class
In my assumption, Heap.class should be dependent on all the other java file. Also, the main file should be in it as well.
However, I cannot get it run, it shows
Heap.java:3: package heap.FibonacciHeap does not exist
and cannot find the other reference from other java file, such as
Heap.java:61: cannot find symbol symbol : variable RandomPermutation location: class heap.Heap
list = RandomPermutation.GetList(listnum[route]);
This program runs fine in eclipse. Do you have any suggestions?
I am new and I might commit some mistake....and I don't know much about compiler and make file. If you can point it out I will be grateful!
I don't see where you set CLASSPATH. I don't care that it's a make file or Ant - javac.exe and java.exe expect the CLASSPATH to be set when they run. Where's yours?
I believe you have to set CLASSPATH in the makefile, before you run javac.exe.
I'd forget about make (and Eclipse) for a moment. Can you make this project compile and run in a command shell? If you can't, I'd say that you should not be leaning on any tools to help you.
Reading this might be helpful.
Is make really a requirement for fulfilling this assignment? How will the professor know that you used Eclipse or make or Ant or command shell to compile your .java to .class files?
How to compile all files in directory to *.class files?
Well, this seems pretty obvious, so I may be missing something
javac *.java
(With appropriate library references etc.)
Or perhaps:
javac -d bin *.java
to javac create the right directory structure for the output.
Were you looking for something more sophisticated? If so, could you give more details (and also which platform you're on)?
Yet another way using "find" on UNIX is described here:
http://stas-blogspot.blogspot.com/2010/01/compile-recursively-with-javac.html
The following two commands will compile all .java files contained within the directory ./src and its subdirectories:
find ./src -name *.java > sources_list.txt
javac -classpath "${CLASSPATH}" #sources_list.txt
First, find generates sources_list.txt, a file that contains the paths to the Java source files. Next, javac compiles all these sources using the syntax #sources_list.txt.
Here's a code fragment that I use to build an entire project where, as usual, source files are in a deeply nested hierarchy and there are many .jar files that must go into the classpath (requires UNIX utilities):
CLASSPATH=
for x in $(find | grep jar$); do CLASSPATH="$CLASSPATH:$x"; done
SRC=$(find | grep java$)
javac -cp "$CLASSPATH" $SRC