Problems building javax.usb - reference implementation and linux implementation - java

For javax.usb, there are three modules:
javax-usb
javax-usb-ri
javax-usb-ri-linux
The faq indicates that in order to use javax-usb, one must build all three modules. Each module has an associated tarball. I've downloaded each of them and unpacked them. So I have a folder with each of these folders in it.
In a console, I enter the javax-usb folder and enter
ant all
and the jar gets built. No problem. Everything's perfect!
I enter the javax-usb-ri colder and enter
ant all
and it errors out indicating:
[javac] Compiling 50 source files to /home/nato/javax/javax-usb-ri/src
[javac] /home/nato/javax/javax-usb-ri/src/com/ibm/jusb/DefaultUsbInterfacePolicy.java:12: package javax.usb does not exist
[javac] import javax.usb.*;
[javac] ^
[javac] /home/nato/javacrap/javax/javax-usb-ri/src/com/ibm/jusb/DefaultUsbInterfacePolicy.java:18: cannot find symbol
and a bunch more errors like that.
I figure that this is because the jar that I made is not on the classpath. Okay.
So I check, and I don't have a classpath environment variable. My understanding is that then the classpath is just ./ So I copy the jsr80.jar file to the javax-usb-ri folder and to the javax-usb-ri/src folder and a few other places and it doesn't seem to matter where I put it, I can't get it to build.
This is frustrating. Is this the best way to get Java to use libusb? Is there some maven repository with a better/more integrated java solution?
If not, can you suggest what's wrong with my attempted build process?
Thanks!

You can provide the path of the jar to Ant via the 'lib' option.
Try changing the command as:
ant all -lib < path of jar>.
For example, if the jsr80.jar file is kept in /home/user1/myjars; then the command would be
ant all -lib /home/user1/myjars/

Related

User defined packages in Java

I have been editing, running, and compiling code in Notepad++ using NppExec. I have set a classpath at C:\Java. This folder contains: C:\Java\com\DOMAINNAMEWITHHELD\Classes. Inside this folder I have 3 .java files, and one .class file (Runner.java, Pirate.java, Ninja.java, and Pirate.class). I was running these files in a folder on a flash drive, and none of the three could see each other. So I moved them to my new classpath defined directory, and still cannot get anything except:
C:\Java\com\DOMAINNAMEWITHHELD\Classes\Runner.java:12: error: cannot find symbol
phil.throwAStar(tim);
throwAStar() is defined in Ninja, and called in Runner.
In the three source files, I defined a package like this:
package com.DOMAINNAMEWITHHELD.Classes;
If I am in any other directory, and try:
import com.DOMAINNAMEWITHHELD.Classes.*;
I get the exact same error. What am I doing wrong?
So Once I cleaned up some syntax errors from troubleshooting, and trying to keep up with class, I finally got Runner, Ninja, Pirate, and now Wizard to compile, and run. In case you guys are wondering how to run a .class file contained in a package:
Let's say the file is: C:\Java\com\DOMAINWITHHELD\classes\Runner.class
Type this into a command prompt to run Runner:
cd C:\Java
java com.DOMAINWITHHELD.classes.Runner
Now the class 'Runner' in the package 'com.DOMAINWITHHELD.classes' should execute.

Packages not found while compiling java

I'm trying to compile my java file to class.
It is a plugin to a much larger program and it runs fine from eclipse when running from source.
I work in Linux, and in shell I type the following javac MyPlugin.java
This is just some of the output:
MyPlugin.java:11: package javolution.util does not exist
import javolution.util.FastList;
^
MyPlugin.java:12: package javolution.util does not exist
import javolution.util.FastMap;
^
MyPlugin.java:14: package org.apache.log4j does not exist
import org.apache.log4j.Logger;
^
MyPlugin.java:15: package org.jwebsocket.api does not exist
import org.jwebsocket.api.PluginConfiguration;
^
My assumption is that the rest of the errors are caused because the imports cannot be reached.
Do I need to add something to the original command to have these imports included?
You are missing jars from the following projects:
http://javolution.org/
http://logging.apache.org/log4j/1.2/
http://jwebsocket.org/
You can download the missing JARs and include them in your compilation classpath.
Alternatively, you could let maven manage the download and compilation of your application.
Update: Gathering all external jars together in one location
To get all your external libraries in one place you could create a runnable JAR in eclipse using:
Export...->Java->Runnable JAR File
Enter your_temp_jar.jar and click
Copy required libraries into a sub-folder next to the generated JAR
After clicking Finish all the required jars will be in a folder called your_temp_jar_lib.
You should specify the jar files which contains following classes in your classpath.
javolution.util.FastList
javolution.util.FastMap
org.apache.log4j.Logger
org.jwebsocket.api.PluginConfiguration
you can use -cp to specify classpath of jars.
Typing javac at the command line is not a viable or scalable way to build java code. While you could use -cp to javac to add the required dependencies to this compilation, you'd be far better served by learning ant or maven.

Compiling and running a Java program on a Mac

This is an extremely basic question, but I haven't been able to find the answer anywhere. I'm completely new to Java.
There's a Java program on github that I'm trying to get running on my Mac. The associated documentation does not give any information on compiling or running the code. I would prefer not disclosing in any more detail the specific program I'm trying to run.
The program contains multiple .java files and a classmexer.jar file for tracking memory usage. There is also a subfolder, cern, that contains additional subfolders that ultimately contain .class files. There is no makefile.
I've downloaded all of the source code as a tar.gz file and unwrapped it into ~/codeDirectory/. When I try to compile from this directory with
$ javac *.java
or
$ javac A.java
(where A.java is the first class that program calls), I get dozens of compile errors. This code clearly compiles successfully elsewhere, so I'm unsure what to make of this.
The first error that appears is
A.java:5: cannot access cern.colt.function.DoubleFunction
class file for cern.colt.function.DoubleFunction not found
cern.jet.random.AbstractDistribution.makeDefaultGenerator();
^
./B.java:4: package com.javamex.classmexer does not exist
import com.javamex.classmexer.*;
^
./B.java:180: cannot find symbol
symbol : variable MemoryUtil
location: class B
long noBytes = MemoryUtil.deepMemoryUsageOf(hp);
^
My suspicion is that there's an improperly or incorrectly specific path somewhere, but I haven't been able to find it.
Thanks in advance for any help troubleshooting.
If you downloaded a Java program from github, it's nearly certain that it comes with a build.xml for use with Apache Ant, or a pom.xml for use with Apache Maven, or some other file for use with some other build tool. Typically, a code base on github will have documentation telling you what tool to use and how to use it.
The program I was attempting to run was incomplete and did not include the source code for two dependencies (including colt, which the compiler flagged above). Thanks to Anony-Mousse for suggesting this option. Installing all the necessary source code solved the problem; the developer has also updated the files.

compiling multiple java classes in linux

i used netbeans to code the classes and they are all included in a package but when i try to compile the application class in linux it spits out errors on class definitions for the classes i am working with. points at the class names for the objects and says "cannot find symbol" i need help!!!
use javac -sourcepath < your source code path >
Better check -help option as it mostly solve your problems
cd to the directory containing your package then run:
javac -classpath . your_package_name/*
I'm not a Java guru, but I have a small java project that I developed years ago and have recently ported to compile with javac on Linux.
I got this to work in two different ways:
Created a single Java source file that held all of my classes
Put each of my classes in a separate file but all in the same directory
In each case, I can compile and run with the following:
javac *.java && java name_of_main_class
Notice that I did not specify a "-classpath" option when I compiled. I guess this works because I have not used a directory substructure or created a package. If you are dealing with those issues, this page appears to have some examples that may help you: Help with packages in java - import does not work
A key thing to understand about Java packages: They correspond to subdirectories where the classes are defined (or to JAR files which just bundle and compress those subdirectories into a single file). Therefore, anytime you specify the package keyword in your source, you need to make sure that the source files (and the class files) are distributed to subdirectories correspondingly. The -classpath option to javac may provide a workaround when subdirectory structures do not exactly match what is specified by the package keyword.
If you built the project using NetBeans, you can use Ant to build the project on command line. NetBeans generate Ant Build script.
just cd into the directory where the project is located then type 'ant'
it should build the project for you automagically

Java Project Compilation Errors

I have downloaded a complete package of Java product and trying to compile it using Ant. The project compiles with many errors, mostly related to imports starting with "org.apache.commons".
I'm new to Java. It looks to me that some system component is missing.
Some of the errors are:
package org.apache.commons.logging does not exist
package com.ibm.icu.text does not exist
cannot find symbol
What should I do to get rid of those errors?
As Sujee has said you need to include 2 jar files in your classpath. You can find the jars here:
http://download.icu-project.org/files/icu4j/4.4.1.1/icu4j-4_4_1_1.jar
http://apache.forthnet.gr/commons/logging/binaries/commons-logging-1.1.1-bin.zip
org.apache.commons.logging and com.ibm.icu.text are third party Java libraries. Download them from their websites and include in the Java classpath.
Update
Classpath is a list of file system paths which defines the locations of Java classes and libraries. JVM uses this to load the class it needs in the runtime. Usual practice is to put all libraries in a sub folder called 'lib' then add '\lib' in the classpath. My advice is to use a graphical tool like Eclipse so you don't need to manually do this. Please read this wikipedia article for more info about Classpath.

Categories