import java classes into jsp project in eclipse - eclipse

I have a jsp project and I am using eclipse. I want to import a couple of external java source code into Java Resources src. Is there a way to do it rather than create a couple of new classes and then copy and paste the code into it? Thank you.

If they're already in the expected package layout for source files, you can just File|Import from the Filesystem.

Actually nobody is getting what if one havn't define package ???
then define package in ur java code as :-
package MyPackage;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.*;
import java.util.Map.Entry;
public class NavBackend {
static boolean isNumeric(String str)
{
..............
..............
then in your jsp file you can write like :
<%#page import="MyPackage.NavBackend"%>

Related

Cannot find class in package when compiling with javac

I have the following structure in my directory :
PROJECT
- classes
tunnelvisionlabs
postgresql
PostgreSqlLexer.class
PostgreSqlLexerAtnSimulator.class
PostgreSqlLexerUtils.class
- lib
antlr-4-7.jar
- BasicTest.java
In BasicTest.java, i have these imports:
package com.tunnelvisionlabs.postgresql.test;
import com.tunnelvisionlabs.postgresql.PostgreSqlLexer;
import com.tunnelvisionlabs.postgresql.PostgreSqlLexerUtils;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import org.antlr.v4.runtime.ANTLRInputStream;
import org.antlr.v4.runtime.CommonTokenStream;
import org.antlr.v4.runtime.Lexer;
import org.antlr.v4.runtime.Token;
import org.junit.Assert;
import org.junit.Test;
I try to compile with the following command :
javac -cp .:./lib/* BasicTests.java
I get these errors :
BasicTests.java:28: error: cannot find symbol
import com.tunnelvisionlabs.postgresql.PostgreSqlLexer;
^
symbol: class PostgreSqlLexer
location: package com.tunnelvisionlabs.postgresql
BasicTests.java:29: error: cannot find symbol
import com.tunnelvisionlabs.postgresql.PostgreSqlLexerUtils;
^
symbol: class PostgreSqlLexerUtils
location: package com.tunnelvisionlabs.postgresql
In the PostgreSqlLexer and PostgreSqlLexerUtils classes, i have this package declared at the beginning:
package com.tunnelvisionlabs.postgresql;
What do i need to do for my program to find these classes ? I tried adding the classes directory in lib and using the same command as before, so that the classpath also contains the classes directory, but it doesn't change anything.
If I read your project structure correctly, the source folder where BasicTest.java sits is at the same level as the lib folder. If so, then you can using the following javac classpath:
javac -cp .:lib/* BasicTests.java
^^^ lib/ is already where you are calling this
Review the following reference answer for more information:
Including all the jars in a directory within the Java classpath

Determine location of jar file from import

If I have an import statement like:
import com.google.android.gms.maps.model.BitmapDescriptor;
is it possible to determine in Eclipse the jar file where this class is located?
try
ctrl-shift-t
type BitmapDescriptor
then show in Package Explorer

I import another file by `import 'models.dart';`, it can't be compiled

I have defined many dart files in my project, and they imported another file by import:
controller.dart
import 'models.dart';
// dart code
app.dart
import 'models.dart';
import 'controller.dart';
// dart code
server.dart
import "app.dart";
main() {
//
}
more dart files
But when I run server.dart, it reports error:
a library which is imported is missing a library directive: models.dart
What does that mean? Do I have to declare them all as libraries?
From the language specification, it says:
It is a compile-time error if the compilation unit found at the
specified URI is not a library declaration.
It seems we can only import a library, not normal files.
But if I define 2 simple files,
a.dart
import "b.dart";
main() {
hello();
}
b.dart
hello() { print("hello!"); }
Then run a.dart:
dart a.dart
It can print hello!.
I get confused :(
Add library directive in each file that you want to import and all will be works fine.
In your case:
models.dart
library foo.models;
// dart code
controller.dart
library foo.controller;
import 'models.dart';
// dart code
app.dart
library foo.app;
import 'models.dart';
import 'controller.dart';
// dart code
server.dart
// If not planned to be imported then the name may be omitted
library foo.bin.server;
import "app.dart";
main() {
//
}
Remember that each library that will be imported by another library requires unique name.
The best way naming your libraries by prepending package name.
Eg.
The package name is "worker".
lib/worker.dart
library worker.worker
lib/work.dart
library worker.work

The import com.interwoven cannot be resolved

I am new to Teamsite and a not sure which jar file to use for resolving the issue that I get while trying to write a Java Datasource in Eclipse.
The list of imports I am using are:
import com.interwoven.datasource.MapDataSource;
import com.interwoven.datasource.core.DataSourceContext;
import com.interwoven.livesite.dom4j.Dom4jUtils;
import com.interwoven.serverutils100.InstalledLocations;
import com.interwoven.cssdk.filesys.CSVPath;
All these imports show the same error
The import com.interwoven cannot be resolved.
Can anyone please tell me which jar files should I add?

Problem when importing package in scala

Suppose I have such packages:
package test
package test.views
package test.others
package views
Now in a scala file, I want to import test._ and views._(not test.views._), so I write:
import test._
import views._
But when I use some classes under views._, it reports type xxx not found, unless I change views package to another name.
What should I do now?
You can switch package import order (theoretically it should work):
import views._
import test._
Or you can be more precise in views import:
import _root_.views._
Here's yet another way (though using _root_ is the surest way to go):
import test.{views => testviews, _}
import views._