javac: compile a java class with third-party library - javac

I have a class that uses "org.apache.ant" and the class is very simple, it's not even in a package.
So I simply use javac MyClass.java to compile it, of course, I got this error saying package "org.apache.ant" not found.
I've downloaded the artifact.
So how do I specify the source of the library in the javac command?
Thanks

Use classpath to include the package after you compile.
It might look something like this...
javac -classpath .;org.apache.ant.jar MyClass
java -classpath .;org.apache.ant.jar MyClass
Refer to this link for more information.
Help with packages in java - import does not work
Update
Following the Ant Installation tips here.
https://supportweb.cs.bham.ac.uk/docs/tutorials/docsystem/build/tutorials/ant/ant.html

Related

"main has been compiled by a more recent version of the Java Runtime", Unsure of what the issue is

I was trying to compile and run a java file using command prompt, first used "javac main.java" then ran the class file with "java main"
Upon running the class file, I'm hit with an error:
"Error: A JNI error has occurred, please check your installation and
try again Exception in thread "main"
java.lang.UnsupportedClassVersionError: main has been compiled by a
more recent version of the Java Runtime (class file version 61.0),
this version of the Java Runtime only recognizes class file versions
up to 52.0"
I then found this possible solution, and updated my User Variables "Path" to jdk17.0.1\bin, and my System Variables "Path" to jre1.8.0_311\bin. I was a bit confused on which Path I was to updated/change so I just updated both...? Not sure if this was the correct thing to do.
In addition, both java -version and javac -version output the latest version "17.0.1" and "jre1.8.0_311".
java -version and javac -version :
Error Message :
What confuses me is that running code in eclipse works fine, so I'm not quite sure that it's an issue with Path so I'm not sure what the issue is.

Importing classes from jar file in grails

I have downloaded and copied the http-builder-0.5.0-RC2.jar to the lib folder of my grails project. I am using GGTS and see the jar in my lib folder when I open the project.
BuildConfig.groovy has the following line in the dependency section:
compile 'org.codehaus.groovy.modules.http-builder:http-builder:0.5.0-RC2'
When I try to reference a class from the jar the I am getting a reference error indicating the class name cannot be resolved.
Is there something I am missing in regards to importing classes from a jar file? I am new to java / groovy and would appreciate some help. Thanks.
import groovyx.net.http.HTTPBuilder
This results in:
Groovy:unable to resolve class groovyx.net.http.HTTPBuilder
I have downloaded and copied the http-builder-0.5.0-RC2.jar to the lib folder of my grails project.
This should not be necessary, since HttpBuilder is in Maven Central. Just declare the dependency and let Grails download the JAR itself along with its transitive dependencies. You may also want to consider using a more recent version of HttpBuilder (0.5.0-RC2 is from 2009, at the time of writing the current release is 0.7.1).
Delete the JAR from your lib directory and try refreshing your Grails dependencies again.

Dart library / package keyword meaning?

Is Dart library exactly the same Java package ?
Is Dart package exactly the same Java library (JAR) ?
A package is a set of libraries which can for example be deployed to pub.dartlang.org. I guess this is similar to a jar file.
A library is one Dart script file with or without a name (or a set of Dart script files with part/part of) and is the boundary for privacy. Private members are only visible or accessible from within the same library.

Compiling Vaadin project with Ant.

I am new to vaadin and I have to compile my vaadin project which has .aj and .java files with circular dependencies. When I compiled with ant, I get an error indicating/related to circular dependencies. So can pl someone guide to compile my project?
I just used maven to fix my problem. Its working for me.
Visit this link for more details maven commands and details

How to add project dependency (classes from another module/folder) in Grails?

Is there a way for me to add dependencies from other folders/projects(non-grails, but definitely java projects) into my grails project? I've tried searching but didn't really get much of an answer. :(
You can use every possible library which is in a maven repository. So transform your java project to a maven or gradle project. Install your builded jar to maven repo and then you can add dependency in grails-app/conf/BuildConfig.groovy.
dependencies {
compile "your.group:your.artifact:1.0"
}
You have to get the code into your project somehow.
These are the options:
JAR
Package your module as a jar file and copy this to your project's lib/ directory.
source code
Copy the source code for your module into src/java/
Maven Artifact
Package your module as a maven artifact, and specify it in the dependencies closure of grails-app/conf/BuildConfig.groovy.
Read more in the grails documentation at http://grails.org/doc/latest/guide/conf.html#configurationsAndDependencies

Resources