Visual Studio Code Java Extension Pack starting template (vscode) - java

I just changed my editor to vscode and loving it since then.
I am using Java extension pack (specifically project manager I guess), and when I create a new project it generates lib, src/App.java. nothing special.
Is there anyway I can change this default files, folders(package)?
Also, is there anyway I can change this default App.java code?
public class App {
public static void main (String[] args) {
System.out.println("Hello World!!");
}
}

When you open Command Palette and choose Java:Create Java Project, click No build tools will generate a template project:
and this function is provided by extension Project Manager for Java:
To customize templates, find the location of Project Manager for Java and change the default ones. On my machine, it's C:\Users\...\.vscode\extensions\vscjava.vscode-java-dependency-0.13.0. There may be many other extensions in your folder extensions and you can search it with keyword java and its version number. For me, the version number is 0.13.0, and you can check it in extension marketplace.
Turn to the directory C:\Users\...\.vscode\extensions\vscjava.vscode-java-dependency-0.13.0, open the folder images to check if you find the correct one. The templates is there and under the directory templates\invisible-project\src, you can see App.java. Customizing templates like adding and editing files is achievable.

Related

Problems running Java from Atom

I currently don't have a working way to edit and run Java on my computer, so I'm trying to get Atom working with Java (I realize it's not a Java IDE and I'm not trying to make it one, I just want to be able to do some light Java work on my laptop). I've installed the script and instant-build packages for Atom and wrote the following test code in a file called "main.java' in my project folder:
class Main{
public static void main(String[] args) {
System.out.println("please");
}
}
When I try to run the code with cmd+i (I'm on a 2012 MacBook Pro) and get the following error message:Error: Could not find or load main class main.
I'd be happy to provide any further information; thanks for helping!
The huge problem of learning Java is that you need to launch the projects in a very strict way, and setting the classpath is always problematic. The solution lays in the following (pretty enigmatic) line of the "Script" documentation:
Project directory should be the source directory; subfolders imply packaging.
So, instead of opening a plain file, open the project (folder) with .java classes or define inside the file, the package to which your .java belong.
It's due to the fact that JDE needs to create a virtual target in form of .classess and single .java file definitely can't be launched as standalone file. I suppose that "Script" is not able to locate the source folder when you try to execute seperate .java file.
Before launching your .java files always "Add Project Folder..."
Please remember that it's not possible to have several folders opened if they don't belong to the same project. Such situation cause problems of locating the right classpath and in the end javac prompts the error.
You have to name your file with the first letter in upper case Main.java, since it must match the name of your class
I replicated the issue quite easily. If I created a new directory in Atom itself and then tried to run the code it didn't work as your error message came up for me as well. Error: Could not find or load main class main.
I used an existing directory and then created a file inside that folder in Atom and ran the same code it worked. I then copied and pasted that same file into the directory of my choice and it worked.

Factual API and coldfusion

I took the java implementation of the Factual API (reference http://developer.factual.com/) and made a JAR file for factual. I did this by opening a new project in eclipse with the factual java files and then exporting to a new jar file.
I put that jar file in my coldfusion installation's /WEB-INF/lib/ folder.
After restarting Coldfusion, I tried to create a new cfobject like so
<cfscript>
// Initialize the Java class.
factualClass=CreateObject("java", "src.main.java.com.factual.driver.Factual");
</cfscript>
I get an error indicating that it cannot find the Factual class.
Can anybody give me some guidance?
(Summary from comments)
It sounds like you may be exporting the source files ie *.java rather than the compiled class files, ie *.class. In the Jar Export wizard, be sure to select the "Export generated class files and resources" option. (To automatically compile the project sources before expi, enable the setting: JAR packaging > Build projects if not build automatically option). If you prefer you can also find pre-compiled jars in the MVN repository.
put that jar file in my coldfusion installation's /WEB-INF/lib/
folder.
CF10+ also supports dynamic class loading via a new application level setting THIS.javaSettings.
// Initialize the Java class.
factualClass=CreateObject("java", "src.main.java.com.factual.driver.Factual");
Just as a point of interest, src/main/java/ is not actually part of the libary class name. It is a standard directory structure used in Maven projects. It is probably included when exporting the sources, but not the compiled classes.
You can always verify the correct path and class name either by examining the API ie javadocs or by viewing one the source files. Package declarations are always at the top of the source file, such as on line 1 of src/main/java/com/factual/driver/Factual.java:
package com.factual.driver; // ie "com.factual.driver"
.. and the class declaration on line 39.
public class Factual { // ie "Factual"
Combined that gives you the exact (case-sensitive) path to use with createObject:
factualClass=CreateObject("java", "com.factual.driver.Factual");

placing and compiling a .java file in working directory

just started learning java, i'm looking to save a .java file (TextIO.java) into my working directory. (which file makes up my working directory exactly?)
and then run it through cmd so that Eclipse can use the class.
I tried doing that by saving (and running thru cmd) the file in the folder containing the programs (yah right) i have written already. But Eclipse still cant find the class.
Can i get some help with this?
thanks
You have to create an Eclipse Java project first. The you can copy the file from file system explorer window and paste it on the Eclipse Package Explorer tree. Eclipse projects compile all files in their source folders automatically by default.
The TextIO.java clas you mentioned has a javadoc saying: ... TextIO provides a set of static methods for reading and writing text... This means you use it as a toolkit rather than executing as an application. Given TextIO.java and you class TextIOUtilizer are both in the root of your classpath (source folder in Eclipse), here is how you call a TextIO method:
public class TextIOUtilizer {
/**
* #param args
*/
public static void main(String[] args) {
// code
TextIO.skipBlanks();
//code
}
}
Now you run TextIOUtilizer as a Java application - it has a main method. Hope this helps.

Custom Jar file on Jasper Server

I wrote some Java class, created jar file. I want to add it to JasperReports Server. When I determine the path to my jar file, using Tools -> Preferences -> Classpath menu in my iReport, it works correctly. But it doesn't work, when I take access to JR Server from another host.
What I must to do, to make this jar file available on this JR Server, from anywhere?
Option 1 - If you want to use your Jar in a several reports.
You should "Add Jar" (as it called in iReport repository manager) to some folder in the Jasper Server folder tree. Then "Add reference" to this resource in Resources section of you specific report.
Option2 - You need a jar in a specifc report.
Use "Add Jar" option in a resources section of specific report.
Worked perfectly on JasperServer 4.7
Add the jar as a resource of the report (if it's one time use) or add it to some path in Jasper Report Server and add a reference to it as Alex suggested.
I'd suggest you to create some folders in Jasper Server (via web interface or iReport) and put all commonly used filed there (be sure to manage correctly the permissions ROLE_USER should have access to the file but you can remove it from the folder so it's not listed).
Then use references on the reports that need those. For example, I use it for the report logo and some helper Java classes.
Edit as #NormTatlock asked more details on how to do it:
Create your Java package my.sample.package for example:
public class MyClass extends JRDefaultScriptlet ...
Compile it and upload the jar as a resource using its full name (e.g. my.sample.package.jar) or upload it to another folder and create a reference to it in the resources folder of the report.
Edit the report and set the Scriptlet Class property to:
my.sample.package.MyClass
Or set the property in the XML tag jasperreports (the root tag) as:
scriptletClass="my.sample.package.MyClass"
Use the scriptlet in your report like this:
$P{REPORT_SCRIPTLET}.myMethod(myParam1, myParam2)
Mind the return type of the methods and so on.
Hope it helps. Have fun!

In Eclipse Plug-in, how to launch a web url using system broswer?

I am working on an eclipse plugin development. It needs to launch system broswer and open a link. In Swing/SWT, I can do it like this:
java.net.URI uri = new java.net.URI("http://www.google.com");
java.awt.Desktop.getDesktop().browse(uri);
And in fact, this code also works in Eclipse plug-in. But I am wondering if eclipse has its own way to do this? Using AWT in eclipse seems some kind of weird...
Equivalent of java.awt.Desktop.getDesktop().browse(uri) is this Program.launch("http://www.google.com");
import org.eclipse.swt.program.Program;
public class del
{
public static void main(String[] args)
{
Program.launch("http://www.google.com");
}
}
The javadoc says:
Launches the operating system
executable associated with the file or
URL (http:// or https://). If the file
is an executable then the executable
is launched. Note that a Display must
already exist to guarantee that this
method returns an appropriate result.

Categories

Resources