org.postgresql.*; class not found error - java

I am using Java with eclipse.
I downloaded postgresql-9.1-901.jdbc4.jar and added it. (Properties-> Java Build Path-> Libraries -> Add External JARs...
My Database connection is working just fine I can create tables, execute queries ect.
Now I want to use the CopyManager. And therefore added to my code:
import org.postgresql.copy.CopyManager;
...
CopyManager cManager = new CopyManager(XXX);
unfortunately I get an error Message saying: "The source attachment does not contain the source for the file CopyManager.class"
Exception in thread "main" java.lang.NullPointerException
at org.postgresql.copy.CopyManager.<init>(CopyManager.java:46)
at Table.insert_data_in_tb(Table.java:73)
at DB.main(DB.java:69)
I'd be very thankfull for any help...

This is a message you get while running your code and clicking methods in debug mode. To correct the immediate problem (being able to view the source code) do this:
Download PostgreSQL 9.1 source
code
Copy the file to some appropriate folder and untar it
tar xvf postgresql-jdbc-9.1-901.src.tar.gz
Add the source folder to your debug configuration in Eclipse
(Run->Debug Configurations->select Java Application->Click Source
tab->Add->File System Directory->add ), where directory is
where you expanded the tarball too.
However, you really don't need to view the source code in order to determine whats going wrong in your program. The documentation for CopyManager is available in online Javadocs. The constructor for the object requires a valid connection, which I am guessing is null in your program.

Related

CheckStyle Java Installation | MIT Software Construction

I am following the eclipse set up from MIT's software construction course1. The installation yields an error and I am not sure how to fix this (pictured below)2. The URL yielding an error returns a 404 error, so I don't know if their site is down or an issue with the package I'm using from MIT. Any advice is appreciated!
Error Message From Eclipse
It seems the update site recently moved to a new location.
If you don't want to contact the course staff directly, you could raise an issue against the relevant GitHub project, suggesting they update the setup file.
In the short term, you should be able to download the file to disk, change the URL (look for a line like <repository url="https://checkstyle.github.io/eclipse-cs/update"/> and change the URL to https://checkstyle.org/eclipse-cs-update-site/) and use the "Browse File System" button in the Eclipse installer instead of pasting the remote URL.

Exception in thread "main" Syntax error: This module cannot be found. Java Alloy program not compiling

I have written a Java program that will execute an Alloy (.als) file. When I am using the commandline the program works perfectly but when I try to run it using NetBeans, this error is shown:
Exception in thread "main" Syntax error:
This module cannot be found.
It is not a built-in library module, and it cannot be found at "C:\Users\brinto dibyendu\Documents\NetBeansProjects\Alloy\util\integer.als".
What can I do?
Alloy is built & developed with Bndtools running in Eclipse. Trying to run it in Netbeans is just creating a huge amount of problems that you can avoid by taking the default route.
In Eclipse, all set up to immediately debug the main application is already done. It actually ensures resolves are handled inline instead of in another process so they are easier to debug. Then just debug it. Search for "built-in library module," and see what's happening there.
Even better, in Eclipse even the tiniest change you make to Java source code is immediately reflected in the runtime.
The quickest way I've found to fix this is to duplicate the .als files for the utilities in your file system.
Assuming your model (.als) file is in folder C:\Users\brinto dibyendu\Documents\NetBeansProjects\Alloy\, you'll need to create a util\ subdirectory in that folder and copy the source of the integer utility model (integer.als) into that subdirectory.
You can get the utility model files here.

Sample IBM MFP Java adapter causes an error on import. FWLSE2302E Malformed ziped content

After downloading the sample java adapter from the MobileFirst Operations console I tried to import it and received the following error:
FWLSE3051E: Invalid payload. See additional messages for details.
FWLSE2302E: Can't read the content: failed to extract data from the zip format. Malformed ziped content.
Steps to reproduce:
Navigate to your-mfpserver:9080/mfpconsole/index.html#/downloads#samples and click on the "Hello World" link under "Java Adapter Samples".
Save javaAdapter.zip to disk.
Navigate to your-mfpserver:9080/mfpconsole/index.html#/mfp/browseAdapters
Click "Actions"->"Import Adapter"
Click browse, choose the javaAdapter.zip you saved to your disk.
Click deploy.
We're using IBM MobileFirst Platform Foundation Operations Console
Product version: 8.0.0.00-20170710-1834
I'm just trying to get the simplest adapter to work, so I thought I'd start with "Hello World", then I discovered this doesn't even work. I was developing java adapters 6 months ago just fine and using maven to deploy or create an .adapter file. In the meantime, we upgraded versions of MFP and now it appears only a .zip file is acceptable, but I can't find a working example.
How can I resolve this issue? I wasn't responsible for the configuration or installation of MFP and don't know too much about it.
You can not upload zipped adapter file,you should deploy the .adapter file .
Follow below steps
1.Unzip adapter and open in a terminal
2.run command 'mfpdev adapter build'
3.run 'mfpdev adapter deploy ' or you can deploy it via console Click "Actions"->"Import Adapter choose .adapter file .
Please see here for more details
https://mobilefirstplatform.ibmcloud.com/tutorials/en/foundation/8.0/quick-start/android/
The sample app needs to be built (a detail I overlooked when asking the above question) and a .adapter file needs to be created.
The larger issue is the Malformed ziped content.(sic) error.
Solve this by creating a directory named adapter containing a single directory named adapterPackage that contains only the .adapter file in it. Then zip the contents and you can utilize the MobileFirst Operations Console to import this zip (Actions->Import Adapter).
e.g. myAdapter.zip should contain adapter->adapterPakcage->myAdapter.adapter

Matlab and JDDE

Update: The problem was solved with the help of MathWorks. I've published the answer below.
I need to control a program (Zemax) from Matlab. Unfortunately, Zemax only supports DDE for such control, which Matlab does not support any more. It works, but stops working on 64 bit platform after a few (presumable 63) DDE calls.
I wonder if there are working solutions. I could probably program a DLL with correct DDE support and then use DDE in Matlab via this DLL. This is a major effort for me. A more suitable solution would be to use Java DDE methods. Following another post here, I've discovered the JDDE library. However I cannot make it work: Even if I am in the directory with the DLL and JAR files, executing
import pretty-tools.JDDE-2.0.3.*
works fine but calling
a = com.pretty_tools.dde.client.DDEClientConversation()
afterwards (as done here) results in
Undefined variable "com" or class "com.pretty_tools.dde.client.DDEClientConversation".
I have very limited writing privileges on my PC, so I have added the javaclasspath.txt file with the jar/dll location to the directory indicated by prefdir. The file looks like this:
C:\Users\xxxxxxxx\Documents\matlab toolbox\jdde\pretty-tools-JDDE-2.0.3.jar
Calling javaclasspath shows a long listing with the last lines being:
...
C:\Program Files\MATLAB\R2012b\java\jarext\webservices\ws_client_core\mw-service-client-core.jar
C:\Users\kkarapet\Documents\matlab toolbox\jdde\pretty-tools-JDDE-2.0.3.jar
DYNAMIC JAVA PATH
<empty>
So path seems to be set correctly. What am I doing wrong?
With the help of MathWorks support, I've found the answer. Here is how to make JDDE work with Matlab 2012b, without admin privileges:
Download and unpack JDDE files (DLLs and JAR) into some folder. Let's say it's $path-to-jdde$\.
In Matlab, type prefdir. Open the resulting directory and create two files there, javaclasspath.txt and javalibrarypath.txt.
In javaclasspath.txt, add $path-to-jdde$\pretty-tools-JDDE-2.0.3.jar.
In javalibrarypath.txt, add $path-to-jdde$\.
Restart Matlab.
Now call ddeConv = com.pretty_tools.dde.client.DDEClientConversation; and start using the created object as described in JavaDoc. E.g. to connect to Zemax, run Zemax and then in call ddeConv.connect('Zemax', 'abc').
Step 2 above can only be done starting Matlab version R2012b. With an older version, if you have the write rights on the Matlab installation directory, you should be able to replace step 2 by editing the files librarypath.txt and classpath.txt in $MATLABROOT$\toolbox\local. I could not verify it so if you confirm it please let me know in the comment below.

SIGAR error: Operation not permitted

I need a Java library that can tell me the current load of a server, so after searching I found that SIGAR is currently the most well known and well accepted amongst the community.
I am using Linux Mint 64-bit as operative system (it is a slight modification of Ubuntu) and since it is my first time using such a library I created a new project from zero using Eclipse and decided to install SIGAR on it by doing:
Download and extract the ZIP file
Create a folder called "libs" in my new Java Project
Copy the Sigar.jar and libsigar-amd64-linux.so files into the "libs" folder
Right Click Project -> Properties -> Java Build Path -> Libraries -> Add External JARs -> Add Sigar.jar
Cross fingers and run project
However, when I run the project I get the following error:
/media/data/Users/pedro/SIGAR/libs/libsigar-amd64-linux.so: /media/data/Users/pedro/SIGAR/libs/libsigar-amd64-linux.so: failed to map segment from shared object: Operation not permitted
org.hyperic.sigar.SigarException: /media/data/Users/pedro/SIGAR/libs/libsigar-amd64-linux.so: /media/data/Users/pedro/SIGAR/libs/libsigar-amd64-linux.so: failed to map segment from shared object: Operation not permitted
at org.hyperic.sigar.Sigar.loadLibrary(Sigar.java:172)
at org.hyperic.sigar.Sigar.<clinit>(Sigar.java:100)
at examples.Shell.<init>(Shell.java:50)
at examples.SigarCommandBase.<init>(SigarCommandBase.java:75)
at examples.CpuInfo.<init>(CpuInfo.java:36)
at examples.CpuInfo.main(CpuInfo.java:97)
Exception in thread "main" java.lang.UnsatisfiedLinkError: org.hyperic.sigar.Sigar.getCpuInfoList()[Lorg/hyperic/sigar/CpuInfo;
at org.hyperic.sigar.Sigar.getCpuInfoList(Native Method)
at examples.CpuInfo.output(CpuInfo.java:60)
at examples.SigarCommandBase.processCommand(SigarCommandBase.java:186)
at examples.CpuInfo.main(CpuInfo.java:97)
I checked the Internet and the Operation not permitted error usually occurs when I do not have the write or read permissions, but such is not the case.
Consequently I have some questions:
Have I messed up the installation?
If yes, how should I do it and can someone point me to a beginners tutorial?
If not, how can I fix the error? I already tried running Eclipse as root but it didn't work.
Thank you for your time, Pedro.

Categories