how to import jtapi api in netbeans project? - java

i am a novice to java and netbeans both and complete newbie to java telephony.I am trying to import JTAPI (java telephony api) in netbeans project for past few days but i am unable to do so. I tried a lot of things and searched almost everywhere on internet but couldn't find a solution. I am desperate to find a solution so any help would really be appreciated.
coming to point.
i downloaded Jtapi from
http://download.oracle.com/otndocs/jcp/jtapi-1.4-fr3-spec-oth-JSpec/
and saved the jtapi-1_4-fr3-spec.zip file on desktop
then made a new netbeans java project. then i right clicked on libraries tab under the project->click add zip/folder-> entered the location of downloaded api.
then added a java file named "MyOutCallObserver.java" in the project
i opened the Jtapi specification and copied the code for detecting calls and pasted in the project. this code is provided in the following link too.
http://www.brekeke.com/products/jtapi/JTAPIspecdoc/javax/telephony/package-summary.html
import javax.telephony.*;
import javax.telephony.events.*;
/*
* The MyOutCallObserver class implements the CallObserver
* interface and receives all events associated with the Call.
*/
public class MyOutCallObserver1 implements CallObserver {
public void callChangedEvent(CallEv[] evlist) {
for (int i = 0; i < evlist.length; i++) {
if (evlist[i] instanceof ConnEv) {
String name = null;
try {
Connection connection = ((ConnEv)evlist[i]).getConnection();
Address addr = connection.getAddress();
name = addr.getName();
} catch (Exception excp) {
// Handle Exceptions
}
String msg = "Connection to Address: " + name + " is ";
if (evlist[i].getID() == ConnAlertingEv.ID) {
System.out.println(msg + "ALERTING");
}
else if (evlist[i].getID() == ConnInProgressEv.ID) {
System.out.println(msg + "INPROGRESS");
}
else if (evlist[i].getID() == ConnConnectedEv.ID) {
System.out.println(msg + "CONNECTED");
}
else if (evlist[i].getID() == ConnDisconnectedEv.ID) {
System.out.println(msg + "DISCONNECTED");
}
}
}
}
}
but an compile-time error was generated in the project stating the import statement wasn't working. then i tried shifting the zip file to
C:\Program Files\Java\jdk1.7.0_25
C:\Program Files\Java\jdk1.7.0_25\jre\lib\ext
also i created a new library from tools menu and then added it to project
but nothing seemed to work.
after nothing was working i extracted the zip file and copied it where netbeans project was saved. i thought the problem was solved as there was no compile time error but another blood-sucking issue showed up! now the netbeans won't be able to import the CallObserver interface and appeared in dashed line and i had no clue about how to proceed.!
i will be really grateful to anyone who could tell me what am i not doing right and how to get it right.

I use NetBeans 8.0.1 I got the same situation but this is not the problem.I compile the project an there is no errors

I did the same thing like you.I extracted the jtapi zip file and copi and paste javax folder in my Source Packages in my project.When i build the project a got the following error.
Screenshot of error
After that i opened the file that contains error ASRConstants.java and there is on row 204 in comment has some symbol like square in word vendors.After i deleted it the project compiles successfully.
After that i copy and paste your code and compile also successfully.

Related

Getting a specific version of an image with Jib (Maven, Docker, testcontainers)

I'm trying to understand a comment that a colleague made. We're using testcontainers to create a fixture:
import org.testcontainers.containers.GenericContainer;
import org.testcontainers.utility.DockerImageName;
public class SalesforceFixture extends GenericContainer<SalesforceFixture> {
private static final String APPLICATION_NAME = "salesforce-emulator";
public SalesforceFixture() {
// super(ImageResolver.resolve(APPLICATION_NAME));
super(DockerImageName.parse("gcr.io/ad-selfserve/salesforce-emulator:latest"));
...
}
...
The commented code is what it used to be. The next line is my colleague's suggestion. And on that line he commented:
This is the part I don't know. The [ImageResolver] gets the specific version of the emulator, rather than the latest. You need a docker-info file for that though, which jib doesn't automatically generate (but I think it can).
This is what I know or have figured so far:
SalesforceFixture is a class that will be used by other projects to write tests. It spins up a container in Docker, running a service that emulates the real service's API. It's like a local version of the service that behaves enough like the real thing that if one writes code and tests using the fixture, it should work the same in production. (This is where my knowledge ends.)
I looked into ImageResolver—it seems to be a class we wrote that searches a filesystem for something:
public static String resolve(String applicationName, File... roots) {
Stream<File> searchPaths = Arrays.stream(roots).flatMap((value) -> {
return Stream.of(new File(value, "../" + applicationName), new File(value, applicationName));
});
Optional<File> buildFile = searchPaths.flatMap((searchFile) -> {
if (searchFile.exists()) {
File imageFile = new File(searchFile + File.separator + "/target/docker/image-name");
if (imageFile.exists()) {
return Stream.of(imageFile);
}
}
return Stream.empty();
}).findAny();
InputStream build = (InputStream)buildFile.map(ImageResolver::fileStream).orElseGet(() -> {
return searchClasspath(applicationName);
});
if (build != null) {
try {
return IOUtils.toString(build, Charset.defaultCharset()).trim();
} catch (IOException var6) {
throw new RuntimeException("An exception has occurred while reading build file", var6);
}
} else {
throw new RuntimeException("Could not resolve target image for application: " + applicationName);
}
}
But I'm confused. What filesystem? Like, what is the present working directory? My local computer, wherever I ran the Java program from? Or is this from within some container? (I don't think so.) Or maybe the directory structure inside a .jar file? Or somewhere in gcr.io?
What does he mean about a "specific version number" vs. "latest"? I mean, when I build this project, whatever it built is all I have. Isn't that equivalent to "latest"? In what case would an older version of an image be present? (That's what made me think of gcr.io.)
Or, does he mean, that in the project using this project's image, one will not be able to specify a version via Maven/pom.xml—it will always spin up the latest.
Sorry this is long, just trying to "show my work." Any hints welcome. I'll keep looking.
I can't comment on specifics of your own internal implementations, but ImageResolver seems to work on your local filesystem, e.g. it looks into your target/ directory and also touches the classpath. I can imagine this code was just written for resolving an actual image name (not an image), since it also returns a String.
Regarding latest, using a latest tag for a Docker image is generally considered an anti-pattern, so likely your colleague is commenting about this. Here is a random article from the web explaining some of the issues with latest tag:
https://vsupalov.com/docker-latest-tag/
Besides, I don't understand why you ask these questions which are very specific to your project here on SO rather than asking your colleague.

Intellij: No usages found in Project Files

I'm using IntelliJ 15 and I'm trying to find usages of methods and objects in a .java file packed in a .jar file downloaded through Maven. I now that they're used: I can find them through the simple search (ctrl+f) command, but when I try with the Find Usages command the post-title message is returned.
I've read this post, but it doesn't work.
This an example of a method in a file InstanceManager.class (belonging to .jar file imported with Maven):
private void notifyNewInstance(Instance instance) {
List var2 = this.instanceListeners;
synchronized(this.instanceListeners) {
Iterator var3 = this.instanceListeners.iterator();
while(var3.hasNext()) {
InstanceListener listener = (InstanceListener)var3.next();
try {
listener.newInstanceAvailable(instance);
} catch (Throwable var7) {
LOG.error("Notification of new instance availability failed.", var7);
}
}
}
}
And in the same file is called with this.notifyNewInstance(host); but if I use Find usages on notifyNewInstance I'll receive the error.
UPDATE:
I've tried to Download the source code, but I get the message:
Cannot download sources Sources not found for:
org.apache.flink:flink-runtime_2.10:1.1-20160316.114232-35
Can you help me with that?
You need to get the source code.
Assuming you're attempting to do this on Apache Flink:
Source Code found here
If you only want a particular folder from the source code, you can use the method found here.

Using jna lib to write to registry throws either access is denied or System cannot find the file specified(lib not loaded)

So i have application that needs to use JNA lib to write to registry, when i want to run it from netbeans i get Access is denied i guess i dont have permissions to write with Advapi32Util.registrySetIntValue
So i created batch file that run my application with administrator privileges and did same thing now i got The system cannot find the file specified when i get to Advapi32Util.registrySetIntValue
To see better here is a screen:
On the left you see my netbeans execution and on the right batc hfile execution with admin privileges.I do have lib folder filled with same libraries , When you look at console of command promt you see VALUE READ:-1 , that means i cant even read with the library jna.platform.win32 Why is my library not loaded?
I use jnativehook that is in the folder lib and that one is loaded no problem , netbeans execution also loaded jna.platform.win32 as you can see i coud read value 1 instead of no value has been read -1
I have no idea what is happening there must be something wrong, both libraries are in the same folder, same imports its exactly the same .jar file beign coppied to test folder for jars
So question , why i get this result? Why is my lib not loaded when i can load library jnativehook that is in the same folder and use it normally bud jna throws error?Dont forget that everything loads well in netbeans , i just lack necessery privileges to run writing to registry(i can read from registry with no problem).
Additional not so important code information:
Imports:
import com.sun.jna.platform.win32.Advapi32Util;
import com.sun.jna.platform.win32.WinReg;
import org.jnativehook.GlobalScreen;
import org.jnativehook.NativeHookException;
Reading method:
public static final int readFromLEProperties(String guid) {
System.out.println("GUID IS:" + guid);
try {
int valueInReg = Advapi32Util.registryGetIntValue(
WinReg.HKEY_LOCAL_MACHINE, "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\MMDevices\\"
+ "Audio\\Render\\" + guid + "\\FxProperties", "{E0A941A0-88A2-4df5-8D6B-DD20BB06E8FB},4");
System.out.printf("LE Value: %s\n", valueInReg);
return valueInReg;
} catch (Exception e) {
System.out.println("Coudnt read value from properties path:" + "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\MMDevices\\"
+ "Audio\\Render\\" + guid + "\\FxProperties NAME:" + "{E0A941A0-88A2-4df5-8D6B-DD20BB06E8FB},4");
}
return -1;
}
And writing method:
public static final void writeToLEProperties(String guid, boolean activateLE) {
try{
Advapi32Util.registrySetIntValue(WinReg.HKEY_LOCAL_MACHINE, "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\MMDevices\\"
+ "Audio\\Render\\" + guid + "\\FxProperties", "{E0A941A0-88A2-4df5-8D6B-DD20BB06E8FB},4", (activateLE) ? 1 : 0);
}catch(Exception e){
System.out.println("Error: AD");
}
}

Minecraft forge not loading textures

I'm trying to teach myself java syntax and using minecraft as a platform for diving in. I'm having a problem though because none of my textures are being loaded. For that matter neither are my localizations. Here is the code for my block
package net.richbaird.testtutorial.blocks;
import cpw.mods.fml.common.registry.GameRegistry;
//import cpw.mods.fml.common.registry.LanguageRegistry;
import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.creativetab.CreativeTabs;
import net.richbaird.testtutorial.lib.constants;
public class OrangeBlock extends Block {
private String blockName = "orangeBlock";
public OrangeBlock() {
super(Material.rock);
this.setBlockName(constants.MODID + "_" + blockName);
this.setCreativeTab(CreativeTabs.tabBlock);
GameRegistry.registerBlock(this,blockName);
this.setBlockTextureName(constants.MODID + ":" + blockName);
//LanguageRegistry.addName(this,"tutorial block");
}
}
here is my constants class
package net.richbaird.testtutorial.lib;
public class constants {
public static final String MODID = "testtutorial";
public static final String MODNAME = "Test Tutorial";
public static final String VERSION = "1.0";
}
I have my texture saved at
~/IdeaProjects/testmod/src/main/resources/assets/testtutorial/textures/blocks/orangeBlock.png
According to the log it is unable to find my texture. Here's the message I'm getting
[08:08:14] [Client thread/ERROR]:
Using missing texture, unable to load
testtutorial:textures/blocks/orangeBlock.png
java.io.FileNotFoundException: testtutorial:textures/blocks/orangeBlock.png
The client loads and my item shows up but with a default black and purple texture. What have I done wrong? I'm thinking it might have to do with my naming conventions, since the .lang file never gets read either, and the only way I can give my block a friendly name is with the now depreciated LanguageRegistry.addName() method
For those who are curious, it's a bug with intellij 14 looks like. Adding this line to the bottom of the build.gradle that comes with forge
sourceSets {
main { output.resourcesDir = output.classesDir }
}
And running gradle setupDecompWorkspace idea --refresh-dependencies
fixed the problem.
I recently ran into this bug after updating IntelliJ, and while richbai90's solution did fix the immediate issue, it also broke compiling the mod into a jar (the assets folder gets included twice). After some digging around, I eventually found the root of the issue: IntelliJ was delegating the build task to Gradle, which put the assets and classes in separate folders, and Forge didn't know they belong to the same mod. The solution that worked for me was to build and run using the IDE, which is in the Settings dialog under Build, Execution, Deployment | Build Tools | Gradle (the help page has more detailed instructions). On older versions of IntelliJ, this was called "Delegate IDE build/run actions to gradle" (see the help page).

How can I add java client library in java on netbeans?

Hello i read that I have to use the java client library in java to get the revisions list in google drive using google api. I use netbeans. I search for this question and I try to add the bib but i haven't get success. To download the library i visited this link and downloaded the "latest". but after add the jar files I get the message error that the package doesnt exist. Please someone help me!
Yes! I try this but it show the same erros. I add the lib but netbeans (8) show the error in the three lines code: "package [name] doesn't exist".
The three lines are these:
import com.google.api.services.drive.Drive;
import com.google.api.services.drive.model.Revision;
import com.google.api.services.drive.model.RevisionList;
obs: the full code, taken in the google developers site is:
package javaapplication8;
import com.google.api.services.drive.Drive;
import com.google.api.services.drive.model.Revision;
import com.google.api.services.drive.model.RevisionList;
import java.io.IOException;
import java.util.List;
public class MyClass {
private static List<Revision> retrieveRevisions(Drive service,
String fileId) {
fileId = "1XpNdeTFBr2KygyfPtlowBvkpcaJJzjgLckrGjp5oOhg0";
try {
RevisionList revisions = service.revisions().list(fileId).execute();
return revisions.getItems();
} catch (IOException e) {
System.out.println("An error occurred: " + e);
}
return null;
}
}
If it is the error like package is missing, please check whether you have created a folder named com in your project or not. Also, every dot (.) indicates the levels of packages that you use in your project. Please check that com folder followed by the other folder names after every dot are present or not. I think this might help you. I answered your question based on my understanding (i.e, package issue which will be resolved by creating folders in your project. folders means packages). I am sorry if I gave you the wrong answer.

Categories

Resources