Hot questions for Using Ubuntu in ant

Question:

My system is Linux Mint 18.3 Cinnamon 64-bit.

I've installed IntelliJ-IDEA and Default-jdk (openjdk-8-jdk) using the software manager.

I can see what I believe to be the JDK folder under either /usr/lib/jvm/java-1.8.0-openjdk-amd64 or /etc/java-8-openjdk when browsing with the file manager (Nemo) or the terminal. But it doesn't matter because IntelliJ can't see either folder anyway. In fact, when trying to Select Home Directory for JDK, IntelliJ only seems to have visibility to 14 sub-folders (out of hundreds) under /usr/lib.

Not even sure how to launch IDEA from the command-line using sudo, e.g. to test that the issue is permission-related, since it is apparently being launched vicariously via flatpak.

Seems like this should be simple. I'm not sure what I'm doing wrong.


Answer:

You can try installing IntelliJ IDEA from here and see if it works better. .tar.gz distribution can be launched using ./idea.sh. Note that you can also create a launcher script using Tools>Create Command-line Launcher. This should work with any version.

Question:

I recently installed openJDK 9 under Ubuntu 17.10 and it seems like IntelliJ IDEA has trouble with it.

Whenever I create a new project IntelliJ can find the JDK, but it seems like it's not configuring it the right way. Here is how it looks like

when I create a HelloWorld.java example it looks like this

and it says 'Can't resolve symbol 'String''.

Everything works fine when I compile via terminal and even with Eclipse.

When I type 'java --version' it says

openjdk 9-Ubuntu

OpenJDK Runtime Environment (build 9-Ubuntu+0-9b181-4)

OpenJDK 64-Bit Server VM (build 9-Ubuntu+0-9b181-4, mixed mode)

Is there a way to fix this problem?


Answer:

The problem is related to Debian packaging of openjdk-9 in the lib/jrt-fs.jar file. This file is compiled incorrectly. This bug is reported here and there is a more complete Answer here.

If you insist to make use of openjdk you might wait for the new versions or try to build it from the source using the recommended options on the launchpad.

Question:

I'm new to Ubuntu and I just installed it on a computer. I installed Samba and shared the folders "/samba" and "/hd". I downloaded and installed Firebird and copied my database that I created on Windows and put it in "/samba". This is my Java code:

public static Connection getConnection() throws SQLException {
        Connection connection = null;
        try {
            Class.forName("org.firebirdsql.jdbc.FBDriver");
        } catch (ClassNotFoundException e) {
            throw new RuntimeException(e);
        }
        connection = DriverManager.getConnection("jdbc:firebirdsql://localhost:3050/samba/LNX.FDB", "sysdba",
                "masterkey");
        return connection;
    }

    public static void main(String[] args) throws SQLException {
        getConnection();
    }

I get this error:

Exception in thread "main" org.firebirdsql.jdbc.FBSQLException: GDS Exception. 335544344. I/O error during "open" operation for file "samba/LNX.FDB"
Error while trying to open file
null
    at org.firebirdsql.jdbc.FBDataSource.getConnection(FBDataSource.java:120)
    at org.firebirdsql.jdbc.AbstractDriver.connect(AbstractDriver.java:136)
    at java.sql.DriverManager.getConnection(DriverManager.java:571)
    at java.sql.DriverManager.getConnection(DriverManager.java:215)
    at br.com.ipsnet.jdbc.ConnectionFactory.getConnection(ConnectionFactory.java:16)
    at br.com.ipsnet.jdbc.ConnectionFactory.main(ConnectionFactory.java:22)
Caused by: org.firebirdsql.gds.GDSException: I/O error during "open" operation for file "samba/LNX.FDB"
Error while trying to open file
null
    at org.firebirdsql.gds.impl.wire.AbstractJavaGDSImpl.readStatusVector(AbstractJavaGDSImpl.java:2098)
    at org.firebirdsql.gds.impl.wire.AbstractJavaGDSImpl.receiveResponse(AbstractJavaGDSImpl.java:2048)
    at org.firebirdsql.gds.impl.wire.AbstractJavaGDSImpl.internalAttachDatabase(AbstractJavaGDSImpl.java:463)
    at org.firebirdsql.gds.impl.wire.AbstractJavaGDSImpl.iscAttachDatabase(AbstractJavaGDSImpl.java:411)
    at org.firebirdsql.jca.FBManagedConnection.<init>(FBManagedConnection.java:105)
    at org.firebirdsql.jca.FBManagedConnectionFactory.createManagedConnection(FBManagedConnectionFactory.java:509)
    at org.firebirdsql.jca.FBStandAloneConnectionManager.allocateConnection(FBStandAloneConnectionManager.java:65)
    at org.firebirdsql.jdbc.FBDataSource.getConnection(FBDataSource.java:118)
    ... 5 more

If I go to "/samba" and type:

isql-fb
connect "localhost:/samba/LNX.FDB" user 'SYSDBA' password 'masterkey';

It works perfectly fine, I can select, delete, update, insert,... with no problem at all.

If I use IBExpert on my Windows machine to connect to my database in Ubuntu it says:

Unable to complete network request to host "Server-Test".
Failed to estabilish connection.

If I use Flamerobin it says:

An assertion failed!

../src/common/strconv.cpp(3031): assert "Assert failure" failed in wxCSConv(): invalid encoding value in wxCSConv ctor

But it connects. I can select, delete, update,...


Answer:

The problem is that the path you specified in the connection string jdbc:firebirdsql://localhost:3050/samba/LNX.FDB is samba/LNX.FDB, and not /samba/LNX.FDB. Relative paths depend on the platform, user and Firebird configuration.

As documented in the Jaybird release notes you need to use jdbc:firebirdsql://localhost:3050//samba/LNX.FDB:

On Linux the root / should be included in the path. A database located on /opt/firebird/db.fdb should use the URL below (note the double slash after port!).

jdbc:firebirdsql://host:port//opt/firebird/db.fdb

Alternatively, you could define an alias instead and use that.

As to your problems with IB Expert and Flamerobin, they seem to be unrelated and should really be separate questions. The IB Expert problem seems to be that you specified a hostname (Server-Test) that cannot be resolved to an (IPv4) IP address or the server does not accept the connect request. A reason could be that the Firebird service is not listening on that IP address; on Ubuntu by default Firebird only listens on localhost. The flamerobin error sounds like a bug in Flamerobin (or you are specifying an unsupported connection character set(?)).

About your use of samba and using a network share: do not put Firebird databases on a network share. Accessing a Firebird database on a network share (especially from multiple servers), could corrupt the database. If you want to access a Firebird database from multiple hosts, then you need to use a Firebird server and connect through that.

Question:

I've developed a java application that works perfectly on windows when i print a receipt. The issue comes when the same java application is tested it in Ubuntu 14.04, and gives me this:

jpos.JposException: Can't connect printer device=SRP-350II
    at com.bixolon.jpos.services.printers.PrinterBaseService.claim(PrinterBaseService.java:256)
    at jpos.BaseJposControl.claim(BaseJposControl.java:296)
    at PruebaPOSImpresion.main(PruebaPOSImpresion.java:36)

It seems that the app finds the printer declared in jpos.xml since does the "open", but not the "claim". And it's strange that when i execute the "check health" on the printer (with the printer utility) it can print the test page with no problem.

Any help or suggestion is appreciated.


Answer:

Try to refer this solution Java POS printer error

Check your Jpos.xml path directory.. Windows vs Ubuntu File paths in Java (Linux)

Question:

In a swing application I have text fields and password fields. On Windows everything is fine. On Ubuntu (14-16) I can input accentuated characters in the JTextField, but not in the JPasswordField. At least not by typing (I can paste de accentuated char in the JPasswordField).

Here is an example code:

public class Frame extends javax.swing.JFrame {

    public Frame() {
        initComponents();
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">                          
    private void initComponents() {

        jLabel1 = new javax.swing.JLabel();
        jTextField1 = new javax.swing.JTextField();
        jLabel2 = new javax.swing.JLabel();
        jPasswordField1 = new javax.swing.JPasswordField();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        jLabel1.setHorizontalAlignment(javax.swing.SwingConstants.TRAILING);
        jLabel1.setText("textField");

        jLabel2.setHorizontalAlignment(javax.swing.SwingConstants.TRAILING);
        jLabel2.setText("passwordField");

        jPasswordField1.setEchoChar('\u0000');

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(jLabel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jLabel2, javax.swing.GroupLayout.DEFAULT_SIZE, 95, Short.MAX_VALUE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(jPasswordField1, javax.swing.GroupLayout.DEFAULT_SIZE, 121, Short.MAX_VALUE)
                    .addComponent(jTextField1))
                .addContainerGap(79, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(28, 28, 28)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel2)
                    .addComponent(jPasswordField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(69, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>                        

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new Frame().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify                     
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JPasswordField jPasswordField1;
    private javax.swing.JTextField jTextField1;
    // End of variables declaration                   
}

The result on Windows:

The result on Ubuntu:


Answer:

Please refer to link: https://bugs.openjdk.java.net/browse/JDK-7052169.

I came across this issue, and fixed by setting :

jPasswordField.enableInputMethod(true)

Question:

I'm learning Nutch through the official guide. So when I run Ant at bin directory, it says:

"Could not load definitions from resource org/sonar/ant/antlib.xml. It could not be found."

I've spent a lot of time in google to solve it, but I failed. My OS is Ubuntu16.04.


Answer:

Try to comment all this part in build.xml:

  <!-- ================================================================== -->
  <!-- SONAR targets                                                      -->
  <!-- ================================================================== -->

  <!-- Define the Sonar task if this hasn't been done in a common script -->
  <taskdef uri="antlib:org.sonar.ant" resource="org/sonar/ant/antlib.xml">
    <classpath path="${ant.library.dir}"/>
    <classpath path="${mysql.library.dir}"/>
  </taskdef>

  <!-- Add the target -->
  <target name="sonar" description="--> run SONAR analysis">

    <!-- list of mandatory source directories (required) -->
    <property name="sonar.sources" value="${src.dir}"/>

    <!-- list of properties (optional) -->
    <property name="sonar.projectName" value="Nutch Trunk 1.4 Sonar Analysis" />
    <property name="sonar.binaries" value="${build.dir}/classes" />
    <property name="sonar.binaries" value="${build.dir}/plugins" />
    <property name="sonar.tests" value="${test.src.dir}" />

    <sonar:sonar workDir="${base.dir}" key="org.apache.nutch:trunk" 
     version="1.4-SNAPSHOT" xmlns:sonar="antlib:org.sonar.ant"/>
  </target>

in this way, it should work.

Question:

I am use Tomcat 8.0.12, Ubuntu 14.04.1, IntelliJ IDEA 13.1.5, I try to run a simple jsp file, then IDE notice:

Error running index.jsp (1): Error copying configuration files from /opt/tomcat8/apache-tomcat-8.0.12/conf to /home/vy/.IntelliJIdea13/system/tomcat/_EE01/conf : /opt/tomcat8/apache-tomcat-8.0.12/conf/catalina.policy (Permission denied)

I also try use Eclipse 4.4 WTP, with Tomcat 8.0.12, there are same problem, although Eclipse don't notice like IntelliJ IDEA:

Server Error The Tomcat server configuration at /Servers/Tomcat v8.0 Server at localhost-config is missing. Check the sever for errors.

Reason: The Tomcat server configuration at /Server/Tomcat v8.0 Server at localhost-config is missing. Check the server for errors.

Help me resove this error.


Answer:

Don't use an installed copy of Tomcat. Use a tarball directly from Apache.

Question:

I have created a web crawler with Selenium (using selenium-server-standalone-2.47.1.jar) and phantomJs (phantomjs -v returns 1.9.0 on Ubuntu 14.04). The code was working fine with both with FirefoxDriver and PhantomJSDriver on Windows 10, but only works with FirefoxDriver under Ubuntu 14.04.

Sample code below:

public static void main(String[] args) {

    DesiredCapabilities DesireCaps = new DesiredCapabilities();
    DesireCaps.setCapability("phantomjs.binary.path", "/usr/lib/phantomjs/phantomjs");

    WebDriver driver=new PhantomJSDriver(DesireCaps);

    String Url = "https://xxx";
    driver.get(Url);

    WebElement rootWebElement = driver.findElement(By.id("main"));
    List<WebElement> parentElements = rootWebElement.findElements(By.tagName("li"));

    //243 , 240 (previous)
    for (int i = 106; i < parentElements.size(); i++) {

        WebElement href =parentElements.get(i).findElement(By.tagName("z"));
        if(href!=null){

            Scanner scanner = new Scanner(href.getAttribute("href"));
            try {
                scanner.parseXML(href.getAttribute("href"));
            } catch (Exception e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }

    }
}

If you open the provided URL's source.... you can easily see that the tag with id="main" exists...

Stack Trace:

PhantomJS is launching GhostDriver...
[INFO  - 2015-08-13T14:15:57.720Z] GhostDriver - Main - running on port 8677
[INFO  - 2015-08-13T14:15:58.361Z] Session [d17a3cc0-41c5-11e5-bedb-6fa39763a2c0] - CONSTRUCTOR - Desired Capabilities: {"phantomjs.binary.path":"/usr/lib/phantomjs/phantomjs"}
[INFO  - 2015-08-13T14:15:58.370Z] Session [d17a3cc0-41c5-11e5-bedb-6fa39763a2c0] - CONSTRUCTOR - Negotiated Capabilities: {"browserName":"phantomjs","version":"1.9.0","driverName":"ghostdriver","driverVersion":"1.0.3","platform":"linux-unknown-32bit","javascriptEnabled":true,"takesScreenshot":true,"handlesAlerts":false,"databaseEnabled":false,"locationContextEnabled":false,"applicationCacheEnabled":false,"browserConnectionEnabled":false,"cssSelectorsEnabled":true,"webStorageEnabled":false,"rotatable":false,"acceptSslCerts":false,"nativeEvents":true,"proxy":{"proxyType":"direct"}}
[INFO  - 2015-08-13T14:15:58.371Z] SessionManagerReqHand - _postNewSessionCommand - New Session Created: d17a3cc0-41c5-11e5-bedb-6fa39763a2c0
Exception in thread "main" org.openqa.selenium.NoSuchElementException: Error Message => 'Unable to find element with id 'main''
 caused by Request => {"headers":{"Accept-Encoding":"gzip,deflate","Connection":"Keep-Alive","Content-Length":"29","Content-Type":"application/json; charset=utf-8","Host":"localhost:8677","User-Agent":"Apache-HttpClient/4.4.1 (Java/1.7.0_79)"},"httpVersion":"1.1","method":"POST","post":"{\"using\":\"id\",\"value\":\"main\"}","url":"/element","urlParsed":{"anchor":"","query":"","file":"element","directory":"/","path":"/element","relative":"/element","port":"","host":"","password":"","user":"","userInfo":"","authority":"","protocol":"","source":"/element","queryKey":{},"chunks":["element"]},"urlOriginal":"/session/d17a3cc0-41c5-11e5-bedb-6fa39763a2c0/element"}
Command duration or timeout: 281 milliseconds
For documentation on this error, please visit: http://seleniumhq.org/exceptions/no_such_element.html
Build info: version: '2.47.1', revision: '411b314', time: '2015-07-30 03:03:16'
System info: host: 'Vmbox', ip: '127.0.1.1', os.name: 'Linux', os.arch: 'i386', os.version: '3.19.0-25-generic', java.version: '1.7.0_79'
*** Element info: {Using=id, value=main}
Session ID: d17a3cc0-41c5-11e5-bedb-6fa39763a2c0
Driver info: org.openqa.selenium.phantomjs.PhantomJSDriver
Capabilities [{platform=LINUX, acceptSslCerts=false, javascriptEnabled=true, browserName=phantomjs, rotatable=false, driverVersion=1.0.3, locationContextEnabled=false, version=1.9.0, cssSelectorsEnabled=true, databaseEnabled=false, handlesAlerts=false, browserConnectionEnabled=false, proxy={proxyType=direct}, nativeEvents=true, webStorageEnabled=false, driverName=ghostdriver, applicationCacheEnabled=false, takesScreenshot=true}]
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:526)
    at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:206)
    at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:158)
    at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:595)
    at org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:348)
    at org.openqa.selenium.remote.RemoteWebDriver.findElementById(RemoteWebDriver.java:389)
    at org.openqa.selenium.By$ById.findElement(By.java:215)
    at org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:340)
    at LinkScanner.main(LinkScanner.java:27)
Caused by: org.openqa.selenium.remote.ScreenshotException: Screen shot has been taken
Build info: version: '2.47.1', revision: '411b314', time: '2015-07-30 03:03:16'
System info: host: 'Vmbox', ip: '127.0.1.1', os.name: 'Linux', os.arch: 'i386', os.version: '3.19.0-25-generic', java.version: '1.7.0_79'
Driver info: driver.version: RemoteWebDriver
    at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:138)
    ... 6 more
Caused by: org.openqa.selenium.NoSuchElementException: Error Message => 'Unable to find element with id 'main''
 caused by Request => {"headers":{"Accept-Encoding":"gzip,deflate","Connection":"Keep-Alive","Content-Length":"29","Content-Type":"application/json; charset=utf-8","Host":"localhost:8677","User-Agent":"Apache-HttpClient/4.4.1 (Java/1.7.0_79)"},"httpVersion":"1.1","method":"POST","post":"{\"using\":\"id\",\"value\":\"main\"}","url":"/element","urlParsed":{"anchor":"","query":"","file":"element","directory":"/","path":"/element","relative":"/element","port":"","host":"","password":"","user":"","userInfo":"","authority":"","protocol":"","source":"/element","queryKey":{},"chunks":["element"]},"urlOriginal":"/session/d17a3cc0-41c5-11e5-bedb-6fa39763a2c0/element"}
For documentation on this error, please visit: http://seleniumhq.org/exceptions/no_such_element.html
Build info: version: '2.47.1', revision: '411b314', time: '2015-07-30 03:03:16'
System info: host: 'Vmbox', ip: '127.0.1.1', os.name: 'Linux', os.arch: 'i386', os.version: '3.19.0-25-generic', java.version: '1.7.0_79'
Driver info: driver.version: unknown

Answer:

Post my comment as answer :) You need to install PhantomJS 1.9.8 from https://bitbucket.org/ariya/phantomjs/downloads

Question:

My Android Studio now when opening a project, it does not directly go to the App folder. Also, I can't run my project anymore. I can't add more XML files, Fragments, Activities etc. I can only New -> Source file, html file etc.

When I try to create a new project, it has different types of create (like Java, Gradle, Groovy, etc) to choose. Not like basic to create Activity only. What should I do? Please help me. (In this newly create project I can not even find where to create Activity).

Sorry guys, I forgot to mention I used Android Studio in Ubuntu.


Answer:

This is exactly what IntelliJ looks like which Android Studio is derived from. Probably the problem is the Android Plugins is deactivated. You can activate it from File -> Setting -> Plugins like the following picture:

If the problem still persists, you can try removing .AndroidStudio3.0 (based on your Android Studio version) from your home directory. In Linux, you can get the home directory by using the following command:

echo $HOME

Then you can find the directory by showing all the hidden files from your File Manager after opening your home directory. In my system, the Android Studio folder resides in:

/home/user/.AndroidStudio3.0

That probably different in your system. Unfortunately, I don't use Ubuntu but Slackware. So, I can't make sure where the Android Studio folder is.

Question:

I use evosuite 1.0.1 for automated test case generation for several open source projects. I use java 1.8 on a unix platform (ubuntu 14.04).

Is there a way to use wildcards for dependencies in the -projectCP tag?

Some of my projects depend on a huge number of libraries and this could save me heaps of time. If you have a solution for either terminal or ant build script (no IDE) I would be very thankful!


Answer:

It is (currently) not possible to use wildcards in -projectCP. A workaround is to use first the -setup option to create the classpath (in which using wildcards is possible) on a configuration file on disk, and then run EvoSuite without -projectCP (as the CP will be taken by the previously generated file). For more info, look at the documentation on http://www.evosuite.org/documentation/commandline/

Question:

nI see in build files of different project in Linux frequently use of "out.absolute.dir" and I'm really curious about what does it exactly mean.So I write a short build file which I mentioned in following lines

<project name="Test_Ant_APK" default="print">
  <property name="cal.out.dir" location="${out.absolute.dir}"/> 
  <target name="print">
  <echo>p=${cal.out.dir}</echo>
  </target>
</project>

And when I run this build file from command line I got this output

Buildfile: /home/jody/workspace/Test_Ant_APK/build.xml

print:

 [echo] p=/home/jody/workspace/Test_Ant_APK/${out.absolute.dir}

BUILD SUCCESSFUL

Total time: 0 seconds

I little confused about output.I think we should have p=/home/jody/workspace/Test_Ant_APK as output. Why we have ${out.absolute.dir} at the end of output? what does it mean? Does this build file have problem?


Answer:

Nothing wrong with your buildscript. You adress a propertyvalue with syntax ${...}, but as the property out.absolute.dir is not set within the project scope of your ant file it's getting echoed as is => ${out.absolute.dir} which is normal for properties not set - in your case its added to the dir your ant script resides, because of the use of location attribute in property task. See the difference when using property task with value attribute instead :

<project name="foo">    
  <property name="cal.out.dir" value="${out.absolute.dir}"/> 
  <target name="print">
  <echo>${cal.out.dir}</echo>
  </target>
</project>

output :

[echo] ${out.absolute.dir}

I believe the propertyname $[out.absolute.dir} might be taken in several scripts due to the fact that property task with attribute location means (taken from ant manual) :

Sets the property to the absolute filename of the given file. If the value of this attribute is an absolute path, it is left unchanged (with / and \ characters converted to the current platforms conventions). Otherwise it is taken as a path relative to the project's basedir and expanded.

see ant manual property task for details. If you want the value of project name attribute to be echoed, you must use the builtin property ${ant.project.name}, f.e :

<project name="foo">
 <echo>$${ant.project.name} => ${ant.project.name}</echo>   
</project>

see all builtin properties with :

<project>
 <echo>ant builtin properties:</echo>   
 <echoproperties prefix="ant"/>
 <echo>java builtin properties:</echo>
 <echoproperties prefix="java"/>
</project>

Question:

I have just installed the newest version of eclipse on my ubuntu 16.04. But every time I try to import a maven project I get this kind of errors shown on the picture.

Also, all dependencies and plugins has .lastUpdated sufix, which means I guess that there is some kind of a problem and it wasn't downloaded correctly. I've tried removing everything from .m2 folder and letting eclipse download dependencies again, didn't work. Also tried to add <maven-resources-plugin> explicitly in the .pom and that didn't help also. Tried using both embedded maven from eclipse and installing my own from terminal, and setting eclipse to work with that, but no luck.


Answer:

I faced this problem few month ago, and the only way was to remove Maven Integration Plugin from Eclipse and re-install it from the marketplace.

Question:

I am trying to run a webapp called TestServer2 in the Tomcat 7 running Ubuntu 14.04 but it gave failed as FAIL - Application at context path /TestServer2-0.0.1-SNAPSHOT could not be started. I followed an example online here and I tested it on my local Tomcat server instance running with Eclipse and it works just fine but when I deployed it into the server Ubuntu 14.04 with Tomcat 7 it gave me that error. Below are the codes I used:

web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" id="WebApp_ID" version="3.1">
  <display-name>TestServer2</display-name>


  <context-param>
        <param-name>resteasy.resources</param-name>
        <param-value>com.heyho.rest.JSONService</param-value>
    </context-param>

    <listener>
        <listener-class>
            org.jboss.resteasy.plugins.server.servlet.ResteasyBootstrap</listener-class>
    </listener>
    <servlet>
        <servlet-name>resteasy-servlet</servlet-name>
        <servlet-class>
            org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher</servlet-class>
    </servlet>

    <servlet-mapping>
        <servlet-name>resteasy-servlet</servlet-name>
        <url-pattern>/*</url-pattern>
    </servlet-mapping>



</web-app>

pom.xml

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>TestServer2</groupId>
    <artifactId>TestServer2</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>war</packaging>

    <repositories>
        <repository>
            <id>JBoss repository</id>
            <url>https://repository.jboss.org/nexus/content/groups/public-jboss/</url>
        </repository>
    </repositories>

    <dependencies>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.8.2</version>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>org.jboss.resteasy</groupId>
            <artifactId>resteasy-jaxrs</artifactId>
            <version>2.2.1.GA</version>
        </dependency>

        <!-- <dependency> <groupId>org.jboss.resteasy</groupId> <artifactId>resteasy-jaxb-provider</artifactId> 
            <version>2.2.0.GA</version> </dependency> -->

        <dependency>
            <groupId>org.jboss.resteasy</groupId>
            <artifactId>resteasy-jackson-provider</artifactId>
            <version>2.2.1.GA</version>
        </dependency>
        <dependency>
            <groupId>com.google.code.gson</groupId>
            <artifactId>gson</artifactId>
            <version>2.7</version>
        </dependency>
        <dependency>
            <groupId>org.apache.httpcomponents</groupId>
            <artifactId>httpclient</artifactId>
            <version>4.4</version>
        </dependency>

    </dependencies>

    <build>
        <sourceDirectory>src</sourceDirectory>
        <plugins>
            <plugin>
                <artifactId>maven-war-plugin</artifactId>
                <version>2.6</version>
                <configuration>
                    <warSourceDirectory>WebContent</warSourceDirectory>
                    <failOnMissingWebXml>false</failOnMissingWebXml>
                </configuration>
            </plugin>
            <plugin>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.5.1</version>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>

JSONService.java

package com.heyho.rest;

import javax.ws.rs.Consumes;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.core.Response;

@Path("/service")
public class JSONService {


    @POST
    @Path("/post")
    @Consumes("application/json")
    public Response createProductInJSON(UserInput input) {

        String result = "User input submitted : " + input;
        return Response.status(201).entity(result).build();

    }



}

UserInput.java

package com.heyho.rest;


public class UserInput {

    int counter;
    String attribute;
    String publicKey;

    public int getCounter() {
        return counter;
    }
    public void setCounter(int counter) {
        this.counter = counter;
    }
    public String getAttribute() {
        return attribute;
    }
    public void setAttribute(String attribute) {
        this.attribute = attribute;
    }
    public String getPublicKey() {
        return publicKey;
    }
    public void setPublicKey(String publicKey) {
        this.publicKey = publicKey;
    }

    @Override
    public String toString() {
        return "User Input = counter " + counter + " attribute = " + attribute + " public key = " + publicKey ;

    }
}

ClientPost.java

package com.heyho.client;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.MalformedURLException;
import java.security.KeyManagementException;
import java.security.KeyStoreException;
import java.security.NoSuchAlgorithmException;
import java.util.HashMap;
import java.util.Map;

import javax.net.ssl.SSLContext;
import javax.net.ssl.TrustManager;

import org.apache.commons.httpclient.protocol.Protocol;
import org.apache.http.HttpResponse;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.conn.ssl.NoopHostnameVerifier;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.ssl.SSLContextBuilder;

import com.google.gson.Gson;

public class ClientPost {

    public static void main(String[] args) throws KeyManagementException, NoSuchAlgorithmException, KeyStoreException {

        try {


            SSLContext sslContext = new SSLContextBuilder()
                      .loadTrustMaterial(null, (certificate, authType) -> true).build();

                    CloseableHttpClient client = HttpClients.custom()
                      .setSslcontext(sslContext)
                      .setSSLHostnameVerifier(new NoopHostnameVerifier())
                      .build();
            HttpPost postRequest = new HttpPost(
                "http://somewebsite.de:50064/TestServer2/service/post");

            Gson gson = new Gson();
            Map<String,Object> test = new HashMap<String,Object>();
            test.put("counter", 1000);
            test.put("attribute", "user attribute");
            test.put("publicKey", "user public key");
            String json = gson.toJson(test);
            StringEntity input = new StringEntity(json);
            input.setContentType("application/json");
            postRequest.setEntity(input);

            HttpResponse response = client.execute(postRequest);

            if (response.getStatusLine().getStatusCode() != 201) {
                throw new RuntimeException("Failed : HTTP error code : "
                    + response.getStatusLine().getStatusCode());
            }

            BufferedReader br = new BufferedReader(
                            new InputStreamReader((response.getEntity().getContent())));

            String output;
            System.out.println("Output from Server .... \n");
            while ((output = br.readLine()) != null) {
                System.out.println(output);
            }


          } catch (MalformedURLException e) {

            e.printStackTrace();

          } catch (IOException e) {

            e.printStackTrace();

          }

        }

    }

Is there something wrong with my code? Also how do I debug the Tomcat 7 running on the server so that it could give me some logs or error?

UPDATE

I have found the error in log something like this:

SEVERE: Exception sending context initialized event to listener instance of class org.jboss.resteasy.plugins.server.servlet.ResteasyBootstrap
java.lang.UnsupportedClassVersionError: com/heyho/rest/JSONService : Unsupported major.minor version 52.0 (unable to load class com.heyho.rest.JSONService)

I'm not sure what is the problem here. I have declared JSONService on my web.xml but it still gives me error


Answer:

"Unsupported major.minor version 52.0" means that the class com.heyho.rest.JSONService has been compiled for a newer version of Java as you try to run it with. Upgrade the JVM to 1.8 and it should work. Alternatively, you can make sure to compile the class for the version of the JVM.

Question:

I have an antlr grammar and I have written and listener for it. I am running the latest version of ubuntu.

I run the following commands

#Generate 
java -jar antlr-4.1-complete.jar -package pascal -o pascal pascal.g4
#Compile
javac -cp antlr-4.1-complete.jar pascal/*.java
#Run
java -cp antlr-4.1-complete.jar pascal.pascal sample1.pascal

Everything seems to go fine until the final run command. I get this : https://www.dropbox.com/sh/8majts6voe7c8v9/AADf5GmB3vpbURrp4ONlqSW-a

When I try to do the Run command I get "Error: Could not find or load main class pascal.pascal

I have tried to change pascal.pascal to pascal/pascal.

I have Java "1.7.0_55" installed.

I really do not understand why this does not work as the files with the same commands run on my friends mac.

I do not need help with the actual work, just as to why I keep getting this Error. If you have any ideas it would be appreciated


Answer:

You didn't add the pascal package to the classpath.

From Mac OS X and Linux do:

java -cp .:antlr-4.4-complete.jar pascal.pascal sample1.pascal

and from Windows:

java -cp .;antlr-4.4-complete.jar pascal.pascal sample1.pascal

Also have a look at Java's code conventions: class names should start with an upper case.

Question:

I am trying to setup hive 2.3.0 with mysql on Ubuntu 16.04. I have installed Hadoop and it's running fine. I am able to enter hive console, however no commands are being executed instead it gives me an error:

SemanticException org.apache.hadoop.hive.ql.metadata.HiveException: java.lang.RuntimeException: Unable to instantiate org.apache.hadoop.hive.ql.metadata.SessionHiveMetaStoreClient

Here's my hive-site.xml

<configuration>
<property>
  <name>javax.jdo.option.ConnectionURL</name>
  <value>jdbc:mysql://localhost/metastore?useSSL=true;</value>
  <description>metadata is stored in a MySQL server</description>
</property>
<property>
  <name>javax.jdo.option.ConnectionDriverName</name>
  <value>com.mysql.jdbc.Driver</value>
  <description>MySQL JDBC driver class</description>
</property>
<property>
  <name>javax.jdo.option.ConnectionUserName</name>
  <value>hiveuser</value>
  <description>user name for connecting to mysql server</description>
</property>
<property>
  <name>javax.jdo.option.ConnectionPassword</name>
  <value>hivepassword</value>
  <description>password for connecting to mysql server</description>
</property>
</configuration>

I have also created metastore database in mysql using this link.

Error Image


Answer:

I figured the solution. The issue that Metastore wasn't instantiate is due to duplicated keys in mysql. Instead of Sourcing the the hive schema from mysql. Use this:hive --service metastore

I updated the hive-site.xml too:

<configuration>
 <property>
  <name>javax.jdo.option.ConnectionURL</name>
  <value>jdbc:mysql://localhost/metastore?useSSL=false</value>
  <description>metadata is stored in a MySQL server</description>
</property>
<property>
  <name>javax.jdo.option.ConnectionDriverName</name>
  <value>com.mysql.jdbc.Driver</value>
  <description>MySQL JDBC driver class</description>
</property>
<property>
  <name>javax.jdo.option.ConnectionUserName</name>
  <value>Username</value>
  <description>user name for connecting to mysql server</description>
</property>
<property>
  <name>javax.jdo.option.ConnectionPassword</name>
  <value>Password</value>
  <description>password for connecting to mysql server</description>
</property>
<property>
 <name>datanucleus.autoCreateSchema</name>
 <value>true</value>
</property>
<property>
 <name>datanucleus.fixedDatastore</name>
 <value>true</value>
</property>
<property>
 <name>datanucleus.autoCreateTables</name>
 <value>True</value>
</property>

Also to view the complete stack trace use schematool: schematool -initSchema -dbType mysql --verbose

Question:

I'm running Tomcat 8 and eclipse mars on Ubuntu. When I try to start Tomcat through eclipse, it just hangs. I tried the solutions in Tomcat Not Starting Through Eclipse (Timeout) including:

  1. setting my hosts file has 127.0.0.1 localhost
  2. setting Window -> Preferences -> General -> Network Connections to Direct
  3. adding -Djava.net.preferIPv4Stack=true to eclipse.ini

Console output:

Oct 26, 2015 12:06:56 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: Server version:        Apache Tomcat/8.0.28
Oct 26, 2015 12:06:56 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: Server built:          Oct 7 2015 18:25:21 UTC
Oct 26, 2015 12:06:56 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: Server number:         8.0.28.0
Oct 26, 2015 12:06:56 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: OS Name:               Linux
Oct 26, 2015 12:06:56 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: OS Version:            3.13.0-24-generic
Oct 26, 2015 12:06:56 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: Architecture:          amd64
Oct 26, 2015 12:06:56 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: Java Home:             /opt/java/jdk1.7.0_79/jre
Oct 26, 2015 12:06:56 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: JVM Version:           1.7.0_79-b15
Oct 26, 2015 12:06:56 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: JVM Vendor:            Oracle Corporation
Oct 26, 2015 12:06:56 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: CATALINA_BASE:         /home/weblogic/workspace/.metadata/.plugins/org.eclipse.wst.server.core/tmp0
Oct 26, 2015 12:06:56 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: CATALINA_HOME:         /opt/apache-tomcat-8.0.28
Oct 26, 2015 12:06:56 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: Command line argument: -agentlib:jdwp=transport=dt_socket,suspend=y,address=localhost:43256
Oct 26, 2015 12:06:56 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: Command line argument: -Dcatalina.base=/home/weblogic/workspace/.metadata/.plugins/org.eclipse.wst.server.core/tmp0
Oct 26, 2015 12:06:56 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: Command line argument: -Dcatalina.home=/opt/apache-tomcat-8.0.28
Oct 26, 2015 12:06:56 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: Command line argument: -Dwtp.deploy=/home/weblogic/workspace/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps
Oct 26, 2015 12:06:56 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: Command line argument: -Djava.endorsed.dirs=/opt/apache-tomcat-8.0.28/endorsed
Oct 26, 2015 12:06:56 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: Command line argument: -Dfile.encoding=UTF-8
Oct 26, 2015 12:06:56 PM org.apache.catalina.core.AprLifecycleListener lifecycleEvent
INFO: The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: /usr/lib/oracle/11.2/client/lib:/usr/java/packages/lib/amd64:/usr/lib64:/lib64:/lib:/usr/lib
Oct 26, 2015 12:06:57 PM org.apache.coyote.AbstractProtocol init
INFO: Initializing ProtocolHandler ["http-nio-8080"]
Oct 26, 2015 12:06:57 PM org.apache.tomcat.util.net.NioSelectorPool getSharedSelector
INFO: Using a shared selector for servlet write/read
Oct 26, 2015 12:06:57 PM org.apache.coyote.AbstractProtocol init
INFO: Initializing ProtocolHandler ["ajp-nio-8009"]
Oct 26, 2015 12:06:57 PM org.apache.tomcat.util.net.NioSelectorPool getSharedSelector
INFO: Using a shared selector for servlet write/read
Oct 26, 2015 12:06:57 PM org.apache.catalina.startup.Catalina load
INFO: Initialization processed in 3816 ms
Oct 26, 2015 12:06:57 PM org.apache.catalina.core.StandardService startInternal
INFO: Starting service Catalina
Oct 26, 2015 12:06:57 PM org.apache.catalina.core.StandardEngine startInternal
INFO: Starting Servlet Engine: Apache Tomcat/8.0.28
Oct 26, 2015 12:06:59 PM org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["http-nio-8080"]
Oct 26, 2015 12:06:59 PM org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["ajp-nio-8009"]
Oct 26, 2015 12:06:59 PM org.apache.catalina.startup.Catalina start
INFO: Server startup in 2091 ms

Answer:

I double clicked on the server, went down to "Server Location" and switched from "Use workspace metadata" to "Use Tomcat installation".

Question:

I was trying to install Xuggle on Ubuntu with this tutorial

But when I used ant stage it doesn`t work. I see these commands on the terminal

> root@test1:~# ant stage Unable to locate tools.jar. Expected to find
> it in /usr/lib/jvm/java-7-openjdk-amd64/lib/tools.jar Buildfile:
> build.xml does not exist! Build failed

Do you have any idea how I can fix it?


Answer:

The tools.jar error will be because ant can't find your JDK, it appears to be looking in the open JDK location. You might need to install oracle-java7-set-default so it points your system java to the oracle java you just installed.

Question:

I start javaEE with tomcat and linux ubuntu.

i installed tomcat on linux successfully and see its first page in 127.0.0.1:8080

that was : "it works..."

By the first example in my book, i create a directory called jspbook in webapps and a sub directory WEB-INFin jspbook that contains this web.xml:

<web-app xmlns="http://java.sun.com/xml/ns/j2ee" version="2.4">

And another xml file called jspbook.xml in webapps directory:

<Context path="/jspbook" docBase="jspbook" debug="0"/>

Now after restarting tomcat, it doesn't display a blank directory in browser by 127.0.0.1:8080/jspbook/ in linux

But i try it in windows and it displayed a blank directory correctly!


Answer:

I must tell you, 1st create a simple html file and check your browser can acces that directory or not In jspbook create a html file called test.html

<html>
<head><title> Its Test<title></head>
<body> Its Working Fine</body>
</html>

Now open: http://127.0.0.1:8080/jspbook/test.html If that works then there is some problem in your java code, if it dosen't work check you have given read permission for groups and other or not

Question:


Answer:

You are trying to use a downloaded version of Java, not a system wide install. This means you need to prefix the command with a path:

$ ./java # when you're in the bin directory
$ ~/Desktop/jdk1.8.0_51/bin/java # from anywhere else

I would recommend just installing OpenJDK with apt-get though.

Question:


Answer:

You've got Oracle Java installed, not OpenJDK. If you want to uninstall it, you can do this:

sudo apt-get remove oracle-java7-*

In effect, you were telling apt to install something that was never installed on your machine.