how to import joda time in java on Ubuntu system - java

I'd like to generate dates sequence in a range. This thread suggests to use Joda-Time package. I downloaded it and unzipped it to the same directory as my Main.java.
When I try import ./joda-time-2.7/org.joda.time.DateTime;, the compiler says:
Main.java:4: error: expected
import ./joda-time-2.7/org.joda.time.DateTime;
^
Main.java:4: error: expected
import ./joda-time-2.7/org.joda.time.DateTime;
^
Main.java:4: error: class, interface, or enum expected
import ./joda-time-2.7/org.joda.time.DateTime;
^
And when I try import org.joda.time.DateTime;, the compiler says:
MissingDateSearch.java:5: error: package org.joda.time does not exist
import org.joda.time.DateTime;
^
It seems that I didn't include the package into my building path. This thread discusses how to set the building path for java. Currently, my "environment" file only has PATH variable. I don't want to make any global change just for one project.
So my question is, does any one know how to include the package in a way without global change? Or does any one has a simple way to generate dates in a range without joda-time?
Thanks!
ADDED
This problem can be bypassed by using IDEs like eclipse. Any terminal based solutions are still welcomed.

Use the
import org.joda.time.DateTime;
import statement and ensure that JodaTime jar file is on your classpath at compile & runtime

Related

Getting Was expecting: <NAME> ... when importing java file in jython

I am quite new to jython. And in my project there is an existing jython file.
This jython file is referring to few java classes present in custom jar.
Here are the import statements
from oracle.ess import PrintVersion
from oracle.as.scheduler import CalendarWrapper
first import statement is not giving any error
but second import statement is giving error under as which is part of package name saying was expecting: NAME ...
One more thing both import statement are part of same jar, so I can not think of any classpath related issues.
So I am feeling like as is not allowed word as part of java package name.
Is there some thing like not allowed words in java package name while using them in jython.
Any kind of help will be appreciated.
as is a keyword, check it with keyword.iskeyword(s):
import keyword
keyword.iskeyword('as')
This makes it impossible to import any module named as.

SBT project with a Java module in IntelliJ

I am learning developing project in IntelliJ.
I started a new SBT project. Now I have two files, one is a Scala script projectName/src/main/scala/scalaScript.scala and the other is a Java class projectName/src/main/java/moduleName/MyClass.java
The Scala script is used for me to test codes line-by-line in a Scala Console. In oder to test the class I defined in MyClass.java, I think I need to compile it first and then import moduleName.MyClass in the Scala script. After that, I can use the java class to create objects and do whatever I want.
If I am not using IntelliJ, I just need to go to the java module directory and call javac -cf myJavaLibrary.jar MyClass.java to create a jar. Then move myJavaLibrary.jar into the same directory as that of my Scala script file.
How do I efficiently do that in IntelliJ? What is the working pipeline?
Update 1
I switched to using Scala worksheet. However, after import moduleName.MyClass, there is an error saying the module is not found.
import bestbuy.Laptop
where bestbuy is the module name, and Laptop is a class. Then the message says:
Error:not found: value bestbuy
import bestbuy.Laptop
^
Error:(6, 10) not found: value bestbuy
;import bestbuy.Laptop
^
Error:(18, 50) not found: value bestbuy
println(MacroPrinter211.printImportInfo({import bestbuy.Laptop;}))
^
Error:(26, 50) not found: value bestbuy
println(MacroPrinter211.printImportInfo({import bestbuy.Laptop;}))
^
Update 2
In the worksheet, you should check the little box in front of "Make project" so that all the source code will be compiled and the byte code will be saved in the target directory where SBT expects. Then I can successfully import bestbuy.Laptop in the worksheet.
However, I am still expecting an answer to my original question. If I can import bestbuy.Laptop in the Scala script file instead of a worksheet. In the worksheet all codes are executed at once, while I would like to execute them one line at a time.
After the project is compiled, I tried executing import bestbuy.Laptop in the Scala Console, but got error:
scala> import bestbuy.Laptop
<console>:13: error: not found: value bestbuy
import bestbuy.Laptop
^
It seems that the console's class path is not properly configured. How can I configure the console's class path?
to use repl-like environment in IntelliJ just create new scala worksheet file and in there you can import your Java class and use it. IDE will compile everything for you.
You can also use terminal, type in sbt console and you will have your repl with your project classes in classpath, so you can import and use them.

Java importing packages

I have a program in my desktop that I want to run (structure in the url), but when I do compile, with
\code\nlp\assignments\parsing\javac PCFGParserTester.java
I get:
PCFGParserTester.java:6: error: package nlp.io does not exist
import nlp.io.PennTreebankReader;
^
PCFGParserTester.java:7: error: package nlp.ling does not exist
import nlp.ling.Tree;
^
PCFGParserTester.java:8: error: package nlp.ling does not exist
import nlp.ling.Trees;
^
PCFGParserTester.java:9: error: package nlp.parser does not exist
import nlp.parser.EnglishPennTreebankParseEvaluator;
how do I get my program to correctly import my packages?
You want to be in the \code directory and compile with:
javac nlp\assignments\parsing\PCFGParserTest.java
(And you should have a package declaration of package nlp.assignments.parsing; to match the position in the directory structure.)
That way javac will look for the other classes appropriately.
Alternatively, and rather more simply, you could use an IDE such as Eclipse or NetBeans, and it would take care of all this for you - you'd just specify the code directory as a source directory, and all would be well.

org.apache.hadoop.mapreduce Not Found-- Hadoop

I am working on Hadoop. I need to process images using the power of Big Data. To play around with it, I have referred this example.
I need to create Sequence file prior working on the image duplicates.
So i used this source code for creating sequence file.
When i compile this in Hadoop environment i am missing some packages. I am using Hadoop-0.18.0.
/tmp/BinaryFilesToHadoopSequenceFile.java:12: package org.apache.hadoop.mapreduce does not exist
import org.apache.hadoop.mapreduce.Job;
^
/tmp/BinaryFilesToHadoopSequenceFile.java:13: package org.apache.hadoop.mapreduce does not exist
import org.apache.hadoop.mapreduce.Mapper;
^
/tmp/BinaryFilesToHadoopSequenceFile.java:14: package org.apache.hadoop.mapreduce.lib.input does not exist
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
^
/tmp/BinaryFilesToHadoopSequenceFile.java:15: package org.apache.hadoop.mapreduce.lib.input does not exist
import org.apache.hadoop.mapreduce.lib.input.TextInputFormat;
^
/tmp/BinaryFilesToHadoopSequenceFile.java:16: package org.apache.hadoop.mapreduce.lib.output does not exist
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;
^
/tmp/BinaryFilesToHadoopSequenceFile.java:17: package org.apache.hadoop.mapreduce.lib.output does not exist
import org.apache.hadoop.mapreduce.lib.output.SequenceFileOutputFormat;
Whether am i doing anything wrong?? Or is it not available in 0.18.0.
I know this version is very old version. Due to some restrictions i am using an already configured VM to work with ,which is having this version of hadoop.
Any Help would be appreciated!!
I can't easily find a copy of 0.18.0 to download anymore, but it looks like the mapreduce package was not available in this version (or 0.19):
http://www.java2s.com/Code/Jar/h/Downloadhadoop0180corejar.htm
http://www.java2s.com/Code/Jar/h/Downloadhadoop0190corejar.htm
It's definately in 0.20.2 though
try using 0.20.X hadoop core package version to make use of org.apache.hadoop.mapreduce.* classes

Java using classes from jar

This must be a super overasked question. Although here goes:
I have a java file for testing around (hworld.java) and am trying to import conio.jar, a JAR which is a wrapper of Conio. The JAR contains only one class file (conio.class) and META-INF. Trying to do import conio.* or import conio.conio shows me this:
C:\Documents and Settings\Nick\Desktop>javac -cp *.jar; hworld.java
hworld.java:3: error: package conio does not exist
import conio.*;
^
1 error
And compiling it like javac -cp conio.jar hworld.java still errors out while compiling. I even extracted the jar and had conio.class in the same directory as hworld.java but to no avail. The JAR is in the same directory as hworld.java, as well.
Anyone have any idea on how to fix this?
You don't mention whether conio.class is defined in package conio. If it is not, then simply use the class without importing it. Remove the import.
It's actually not possible. You need to put the other class in a package if you want to import it.
What's the syntax to import a class in a default package in Java?
Find out what package Conio is in - an easy way to do this is to open the jar as a zip file, the package will correspond with the folder structure of the archive. For example if Conio is in x/y/z then import x.y.z.Conio and compile/run with conio.jar on the classmate.

Categories