Ubuntu: javac package gnu.io does not exist - java

I am running on Ubuntu 12.04. I am trying to communicate my Arduino with Java.
I have a source file SerialTest.java in directory /home/me/Desktop/folder
Inside the directory contains both RXTXcomm.jar, librxtxSerial.so, and my source code file.
I tried these methods to compile the SerialTest.java:
$ javac SerialTest.java
and I get the following errors:
SerialTest.java:4: error: package gnu.io does not exist
$ javac -verbose -classpath .:RTXXcomm.jar SerialTest.java
And I got the same error
SerialTest.java:4: error: package gnu.io does not exist
What I have referred to: javac -classpath not doing the trick
May I know what I am doing wrong? I am new to this. Thank you.

Your classpath option is wrong. It should be:
-classpath .:RTXXcomm.jar
Note the colon (:). The semicolon (;) is used as a command separator by the shell.
What happens currently is that this command is executed:
javac -verbose -classpath .
Hence the first error: "no source files". And then this command is passed:
RTXXcomm.jar SerialTest.java
Hence the second error: "RXTXcomm.jar: command not found."

Related

Javac compiler not recognizing wildcard?

I set up a folder containing a test java file that only contains the word "test". I want docker to compile it. To run it, I call
$ docker run -it -v ~/my/path/testpayload:/payload -w /payload test_docker javac -cp /usr/share/java/*:. *.java
However, I get the following error
javac: file not found: *.java
Usage: javac <options> <source files>
use -help for a list of possible options
If I explicitly state the name of the java file like so:
$ docker run -it -v ~/my/path/testpayload:/payload -w /payload test_docker javac -cp /usr/share/java/*:. TestPayload.java
It tries to compile and returns with the expected error:
TestPayload.java:1: error: reached end of file while parsing
test
^
1 error
I tried it again with the wildcard but without the classpath and it still doesn't work, which makes me think it's something with the wildcard, I googled but it seems to me like I'm using the wildcard correctly.
Thanks.

Generating Java header file error

Sorry for asking but I am having trouble generating a Java header file from my code - in command prompt I typed:
javah -o JNIDemoJava.h -classpath JNIDemoJava/build/classes jnidemojava.Main
From what I've read that should have worked but I get this error:
Error: Could not find class file for 'jnidemojava.Main'.
Before you say I forgot to clean and build to compile it I did, but I still have this error if you need more info just ask .
Update: Problem was solved
It seems your command is right. In which platform you run your command? Be cautious to the file separator, it's \ in Windows and / in *NIX.
So in Windows you should
javah -o JNIDemoJava.h -classpath JNIDemoJava\build\classes jnidemojava.Main
In *NIX, you should
javah -o JNIDemoJava.h -classpath JNIDemoJava/build/classes jnidemojava.Main

javac: invalid flag: activation-1.1.jar

I'm using Tomcat7 , jdk 1.7.0_55 & eclipse, when I trying to compile the entire project(Java Code) using COMMAND PROMPT, its showing Error Like
javac: invalid flag: D:\COMPILE\lib\activation-1.1.jar.
The given below steps are followed to compile the code.
Step.1: dir *.java /s /b > FilesList.txt
Step.2: javac #FilesList.txt -d compiledCode -cp D:\COMPILE\lib\*.jar
After run the Step.2 command its showing Error.so I removed the error jar file from my lib folder & run the command but its showing same error with another jar.
Note: I Already have ANT build.xml but I want to compile the project through COMMAND PROMPT.
The lib*.jar gets expanded by the command shell. You need to avoid that by using quotes.
***** -cp "D:\COMPILE\lib\*" *****
The argument to -cp is a single path list (like $PATH, not multiple arguments with one path each). Multiple files can be separated by : (or ; on Windows)

javac: invalid flag: .getting error when compiling a java servlet

i run command
javac -classpath /home/coolhunk/JBoss/jboss-6.0.0.Final/common/lib/jboss-servlet-api_3.0_spec.jar -d helloapp.war/WEB-INF/classes -sourcepath src/com/manning/jbia/intro/*
for generating java class files.but i am getting error
javac: invalid flag: src/com/manning/jbia/intro/HelloWorldServlet.java~
Usage: javac <options> <source files>
use -help for a list of possible options
can anyone please point out what is the mistake in this command ??
Try these commands using tomcat, place your servlet source in src folder and run these,
C:\Documents and Settings\ssit>cd C:\src
C:\src>javac -classpath "C:\Program Files\Apache Software Foundation\Tomcat 6.0\
lib\servlet-api.jar" MyServlet.java
you can get the class file for the servlet. After getting the class file make the war file.
javac -classpath /home/coolhunk/JBoss/jboss-6.0.0.Final/common/lib/jboss-servlet-api_3.0_spec.jar -d helloapp.war/WEB-INF/classes -sourcepath src/com/manning/jbia/intro/*
The problem is the last item. The wildcard causes it to be expanded into everything in the directory, which causes everything after the first expansion to be treated as a source file name. The expansions also appear to include src/com/manning/jbia/intro/HelloWorldServlet.java~, which the compiler doesn't want to know about.
Try this:
javac -classpath /home/coolhunk/JBoss/jboss-6.0.0.Final/common/lib/jboss-servlet-api_3.0_spec.jar -d helloapp.war/WEB-INF/classes -sourcepath src src/com/manning/jbia/intro/*.java

setting multiple jar files as classpath in cygwin

I have the program x.java in c:\cygwin\programs\x.java and it uses y.jar and z.jar that are also in the folder c:\cygwin\programs.
In windows:
c:cygwin\programs>javac -classpath c:\cygwin\programs\y.jar;c:\cygwin\programs\z.jar x.java
No errors.
In cygwin
(1)
$javac -classpath c\:/cygwin/programs/y.jar;c\:/cygwin/programs/z.jar x.java
Errors: $'PK\003\004': Command not found.
(2)
$javac -classpath c:\cygwin\programs\y.jar;c:\cygwin\programs\z.jar x.java
Errors: -bash command Command not found.
(3)
$javac -classpath 'c:/cygwin/programs/y.jar;c:/cygwin/programs/z.jar' x.java
No error.
Why is it giving error in case of (1),(2)...
You are messing up with escape character back-slash \. In Unix based environment, it's better to use / as path separator. If you want to use backlashes for some reason, use an additonal backslash i.e. \\ to treat it as literal in the path.
Because of above, first tow statements are not resulting into correct path and hence failure.
Cygwin treats the ; character as starting a new command line, so in (1) it is trying to execute the separate commands
$ javac -classpath c\:/cygwin/programs/y.jar
$ c\:/cygwin/programs/z.jar x.java
The error message is from Cygwin trying to execute the jar file directly as a script.
You can quote the entire argument with '' as in (3), or escape the semicolon:
$ javac -classpath c\:/cygwin/programs/y.jar\;c\:/cygwin/programs/z.jar x.java

Categories