I try to use Geoserver-Manager. I says:
package test;
import java.net.MalformedURLException;
import it.geosolutions.geoserver.rest.GeoServerRESTPublisher;
import it.geosolutions.geoserver.rest.GeoServerRESTReader;
public class RestTester
{
/**
* #param args
* #throws MalformedURLException
*/
public static void main(String[] args) throws MalformedURLException
{
System.out.println("fdfdfd");
// TODO Auto-generated method stub
String RESTURL = "http://localhost:8080/geoserver";
String RESTUSER = "admin";
String RESTPW = "geoserver";
GeoServerRESTReader reader = new GeoServerRESTReader(RESTURL, RESTUSER, RESTPW);
GeoServerRESTPublisher publisher = new GeoServerRESTPublisher(RESTURL, RESTUSER, RESTPW);
System.out.println("fdfdfd");
}
}
And there is something interesting. I start this application and get nothing in console. No any errors or my prints.
What can be wrong? I use Eclipse Galileo.
UPDATE
More info
Geoserver Manager add to application how java classes not *.jar files.
I delete all classes from project but RestTester. But still not get any prints in console.
UPDATE2
I delete RestTester class. And add new class HelloW.
public class HelloW
{
/**
* #param args
*/
public static void main(String[] args)
{
// TODO Auto-generated method stub
System.out.println("HelloW");
}
}
Run it and get error:
java.lang.NoClassDefFoundError: HelloW
Caused by: java.lang.ClassNotFoundException: HelloW
But when i create new project with same class all works fine. In project where i try Geoserver Manager i add some *.jar but its was only apache commons and jdom libraries, half of then i use in my another applications.
Related
First got this error with Eclipse Neon. Installed Oxygen and get the same error. Under Oxygen, I created a new Java project with a one line Main function to write "Hello, World!":
/**
*/
package com.brindlewaye.hello;
/*
* author Dave
*/
public class Hello {
/*
*/
public Hello() {
// TODO Auto-generated constructor stub
}
/*
* #param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
System.out.println("Hello, World!");
}
}
Same error.
I have searched and found nothing that applied, IMHO, to a simple one line, Hello World, Java project.
What might the problem be?
It seems that my Eclipse workspace had gone wonky. Created a new workspace and migrated all of my Java projects to it. Now all of them build and run fine.
package freshjuice;
class FreshJuice {
enum FreshJuiceSize { SMALL, MEDIUM, LARGE }
FreshJuiceSize size;
}
}
public class FreshJuiceTest {
/**
* #param args the command line arguments
*/
public static void main(String[] args) {
FreshJuice juice = new FreshJuice();
juice.size = FreshJuice.FreshJuiceSize.MEDIUM ;
System.out.println("Size: " + juice.size);
// TODO code application logic here
}
}
This is the error message I am getting:
Error: Main method not found in class freshjuice.FreshJuice, please define the main method as:
public static void main(String[] args)
or a JavaFX application class must extend javafx.application.Application
C:\Users\TheGODMasterDu\AppData\Local\NetBeans\Cache\8.2\executor-snippets\run.xml:53: Java returned: 1
BUILD FAILED (total time: 2 seconds)
Your file must be called FreshJuiceTest.java, because that is the class where your main method is located.
Your file name is FreshJuice.java which does not contains main()
In short netbeans looking for main() in your first class
Either change your file name to FreshJuiceTest.java or swap the code of your classes and define FreshJuice.java as public and remove public from second class
Am using Eclipse Neon 3 and was making my usual edits to the formatter when I noticed that everytime I create a new class, it creates two new (or blank) lines between the package declaration and the actual class itself!
package com.myapp;
public class MyClass {
public static void main(String[] args) {
// TODO Auto-generated method stub
}
}
How to setup the Eclipse formatter to only include one blank line (initially), especially if there's no import declarations used yet, like this:
package com.myapp;
public class MyClass {
public static void main(String[] args) {
// TODO Auto-generated method stub
}
}
Been trying to fix this myself and would appreciate if someone could point me in the right direction.
Review the code template that was set up in Eclipse by opening up Window > Preferences > Java > Code Style > Code Templates and configure the generated code for New Java Files under the Code header.
The default template given provided was
${filecomment}
${package_declaration}
${typecomment}
${type_declaration}
and the generated code as follows
package com.personal.test.com.personal.test;
public class AppTest {
}
If the template was modified to this, note the extra blank lines.
${filecomment}
${package_declaration}
${typecomment}
${type_declaration}
The following is generated
package com.personal.test.com.personal.test;
public class AppTestWithSpaces {
}
I've got a java class, calling a native method and trying to load library:
import java.io.UnsupportedEncodingException;
public class Main {
public static native String getMyString(String s);
/**
* #param args
* #throws UnsupportedEncodingException
*/
public static void main(String[] args) throws UnsupportedEncodingException {
// TODO Auto-generated method stub
// System.out.println("here!");
String s2 = getMyString("string text");
for (Byte b : s2.getBytes("UTF-8")) {
System.out.print(b);
System.out.print(",");
}
}
static {
System.loadLibrary("mylib.so");
}
}
The "mylib.so" is in the directory, where Main.class is located.
When I run java Main I get following exception:
Exception in thread "main" java.lang.UnsatisfiedLinkError: no mylib.so in java.library.path
at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1856)
at java.lang.Runtime.loadLibrary0(Runtime.java:845)
at java.lang.System.loadLibrary(System.java:1084)
at Main.<clinit>(Main.java:24)
What should I change for this to wark?
I've tried setting library full path without success
Do the following:
Use System.loadLibrary("mylib");
Copy mylib.so to libmylib.so
Run java -Djava.library.path=/root/ Main
"How to load native library"
public final class NativeLibsLoaderUtil {
private static final String JAVA_LIBRARY_PATH = "java.library.path";
private static final String SYS_PATHS = "sys_paths";
private NativeLibsLoaderUtil() {
}
private static void addLibsToJavaLibraryPath(final String tmpDirName) {
try {
System.setProperty(JAVA_LIBRARY_PATH, tmpDirName);
/* Optionally add these two lines */
System.setProperty("jna.library.path", tmpDirName);
System.setProperty("jni.library.path", tmpDirName);
final Field fieldSysPath = ClassLoader.class.getDeclaredField(SYS_PATHS);
fieldSysPath.setAccessible(true);
fieldSysPath.set(null, null);
} catch (IllegalAccessException | NoSuchFieldException e) {
LOGGER.error(e.getMessage(), e);
}
}
}
Where tmpDirName is a directory where you store your library.
Or you can modify above class and use temp directory from your system property, like this:
/**
* Temporary directory system property name
*/
private static final String JAVA_IO_TMPDIR = "java.io.tmpdir";
/**
*
* #return
*/
private static File getTempDir() {
final String tmpDirName = System.getProperty(JAVA_IO_TMPDIR);
final File tmpDir = new File(tmpDirName);
if (!tmpDir.exists()) {
tmpDir.mkdir();
}
return tmpDir;
}
!But first you have to copy there your native lib :)
Then to load native library call "addLibsToJavaLibraryPath" method in static block in "most root" class before any class constructor was executed.
static {
NativeLibsLoaderUtil.addLibsToJavaLibraryPath("/tmp");
}
You should add the so to library path:
-Djava.libarary.path= (this is in the java command).
if you run from eclipse:
How to add native library to "java.library.path" with Eclipse launch (instead of overriding it)
If you compiled opencv, on installation you should have seen something like:
make install:
-- Up-to-date: /usr/local/share/java/opencv4/libopencv_java460.so
-- Up-to-date: /usr/local/share/java/opencv4/opencv-460.jar
make a hard link to the /usr/lib/ folder:
$ sudo ln /usr/local/share/java/opencv4/libopencv_java460.so /usr/lib/libopencv_java460.so
And then just run:
System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
that he will get the *.so
As Reimeus answered.
Or you can use
System.load("/Library/Path/libsample.so");
For some reason in the testEmployee method I am getting weird error messages saying illegal character.
I've looked at the code but can't find anything syntactically wrong with it.
Any help would be great thanks!
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
import ttp.Cache;
import ttp.DataException;
import ttp.EmployeeDAO;
import ttp.Employee;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import static org.junit.Assert.*;
/**
*
* #author ericrea
*/
public class Tester {
public Tester() {
}
#BeforeClass
public static void setUpClass() throws Exception {
}
#AfterClass
public static void tearDownClass() throws Exception {
}
#Before
public void setUp() {
}
#After
public void tearDown() {
}
// TODO add test methods here.
// The methods must be annotated with annotation #Test. For example:
//
// #Test
// public void hello() {}
// /** Test the Skeleton BO/DAO */
// #Test
// public void TestSkeleton() throws Exception {
// Skeleton s = SkeletonDAO.getInstance().create(“skeleton1”);
// s.save();
//
// // since skeleton1 is in the Cache, this tests reading from the cache
// Skeleton s2 = SkeletonDAO.getInstance().read(“skeleton1”);
// assertSame(s, s2);
//
// // now clear the cache (you’d never do this in the real world)
// // then we can test reading from the database
// Cache.getInstance().clear();
// Skeleton s3 = SkeletonDAO.getInstance().read(“skeleton1”);
// assertEquals(s.getId(), s3.getId());
// //assertEquals(s.getSomething(), s3.getSomething());
//
// // keep testing more methods, BOs, and DAOs
// }//TestSkeleton
// //5. Right-click the file and run the file. You’ll see it test. It will obviously have errors
// //because Skeleton isn’t a real BO/DAO.
// //6. Note in the above code the “assertEquals” methods. That is how you test that two things are equals.
#Test
public void TestEmployee() throws DataException {
Employee e = EmployeeDAO.getInstance().create(“Employee1”);
e.save();
// since skeleton1 is in the Cache, this tests reading from the cache
Employee e2 = EmployeeDAO.getInstance().read(“Employee1”);
assertSame(e, e2);
// now clear the cache (you’d never do this in the real world)
// then we can test reading from the database
Cache.getInstance().clear();
Employee e3 = EmployeeDAO.getInstance().read(“Employee1”);
assertEquals(e.getId(), e3.getId());
assertEquals(e.getName1(), s]e3.getName1());
}
You seem to use 'fancy' quotes (“) instead of normal ones (")
PS If Matt is right, please do not use Word to edit your programs. There're lots of IDEs, but even Notepad would be easier.
The fragment
s]e3.getName1()
(last line) doesn't look right: remove the "s]" fragment.
Edit: You are also missing the closing parenthesis for the class at the end of the code.